dxd - dynax driver framework 3.0.2
cross platform open source driver development framework
Loading...
Searching...
No Matches
dx::shared::reference Class Reference

cross-process, crash-safe named reference count More...

#include <dx_shared_reference.h>

Inheritance diagram for dx::shared::reference:
Collaboration diagram for dx::shared::reference:

Public Member Functions

reference& initialize(const std::string& name)
reference& initialize(const std::string& name)
 operator const os_event() const noexcept
 operator os_event() noexcept
 operator ::HANDLE() const noexcept
 reference()= default
 reference()= default
 reference(const std::string& name)
 reference(const std::string& name)
template<typename last_t>
void release(last_t&& last) noexcept
 releases this hold - last run where it was the last one
template<typename last_t>
void release(last_t&& last) noexcept
 releases this hold - last run where it was the last one
 ~reference()

Protected Attributes

::HANDLE process

Detailed Description

cross-process, crash-safe named reference count

Holding an instance signals "I am interested in the named resource" to every other process doing the same under the same name. Each holder keeps a shared (LOCK_SH) advisory lock open on a small marker file; the kernel releases a process' flock()s when its last file descriptor to the file closes, a crash included, so the count never desyncs. The marker file is never unlinked - same as the named semaphores in shared::event - a later reference under the same name reopens it; flock()s are per open file description, not per path.

release() runs its last where this was the last holder, under the exclusive lock that proved it: a holder registering meanwhile waits for it, so last (dx::shared::memory's shm_unlink()) never removes what a newcomer created - and waits on nothing itself.

Holding an instance signals "I am interested in the named resource" to every other process doing the same under the same name. The underlying named mutex is kept alive by Windows for as long as any process holds an open handle to it, and Windows closes all of a process' handles on termination, a crash included, so the count never desyncs. dx::shared::memory (Windows) does not use this class: the file mapping object is itself kept alive exactly as long as any process holds a handle to it, so nothing is left to remove after the last one.

release() runs its last where this was the last holder (e.g. dx::service::client::_device erasing an application's non-persistent settings).

Constructor & Destructor Documentation

◆ reference() [1/4]

dx::shared::reference::reference()
default
Here is the caller graph for this function:

◆ reference() [2/4]

dx::shared::reference::reference(const std::string& name)
inline
Here is the call graph for this function:

◆ ~reference()

dx::shared::reference::~reference()
inline

◆ reference() [3/4]

dx::shared::reference::reference()
default

◆ reference() [4/4]

dx::shared::reference::reference(const std::string& name)
inline
Here is the call graph for this function:

Member Function Documentation

◆ initialize() [1/2]

reference& dx::shared::reference::initialize(const std::string& name)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize() [2/2]

reference& dx::shared::reference::initialize(const std::string& name)
inline
Here is the call graph for this function:

◆ operator const os_event()

dx::resource<invalid_t>::operator const os_event() const
inlinenoexceptinherited

◆ operator os_event()

dx::resource<invalid_t>::operator os_event()
inlinenoexceptinherited

◆ operator ::HANDLE()

dx::resource<invalid_t>::operator ::HANDLE() const
inlinenoexceptinherited
Here is the caller graph for this function:

◆ release() [1/2]

template<typename last_t>
void dx::shared::reference::release(last_t&& last)
inlinenoexcept

releases this hold - last run where it was the last one

Here is the call graph for this function:
Here is the caller graph for this function:

◆ release() [2/2]

template<typename last_t>
void dx::shared::reference::release(last_t&& last)
inlinenoexcept

releases this hold - last run where it was the last one

Here is the call graph for this function:

Member Data Documentation

◆ process

::HANDLE dx::resource<invalid_t>::process
protectedinherited

The documentation for this class was generated from the following files: