Samchon Framework for CPP
1.0.0
|
Shared acquire from a Semaphore. More...
#include <SharedAcquire.hpp>
Public Member Functions | |
SharedAcquire (Semaphore &semaphore, bool lock=true) | |
Construct from Semaphore. More... | |
SharedAcquire (const SharedAcquire &obj) | |
Copy Constructor. More... | |
SharedAcquire (SharedAcquire &&obj) | |
Move Constructor. More... | |
~SharedAcquire () | |
Default Destructor. More... | |
void | acquire () |
Acquire admission. More... | |
void | release () |
Release an admission. More... | |
Private Attributes | |
Semaphore * | semaphore |
Managed Semaphore. More... | |
std::atomic< size_t > * | reference |
Referencing count sharing same Semaphore. More... | |
std::atomic< bool > * | locked |
Whether the mutex was locked by SharedAcquire. More... | |
Shared acquire from a Semaphore.
A SharedAcquire is an object manages a Semaphore with shared ownership in both states.
On default construction, the object acquires a Semaphore object, for whose acquiring and releasing operations becomes responsible. When copy constructions, responsibilities of acquiring and releasing Semaphore are shared with copied with those SharedAcquire objects.
The class shared_lock is a general-purpose shared mutex ownership wrapper allowing deferred locking, timed locking and transfer of lock ownership. Locking a shared_lock locks the associated shared mutex in shared mode (to lock it in exclusive mode, std::unique_lock can be used)
This class guarantees a released status on destruction of all shared objects (even if not called explicitly). Therefore it is especially useful as an object with automatic duration, as it guarantees the Semaphore object is properly released in case an exception is thrown.
Referenced comments of std::unique_lock
Though, that the SharedAcquire object does not manage the lifetime of the Semaphore object in any way: the duration of the Semaphore object shall extend at least until the destruction of the SharedAcquire that manages it.
Definition at line 43 of file SharedAcquire.hpp.
|
inline |
|
inline |
Copy Constructor.
Definition at line 84 of file SharedAcquire.hpp.
|
inline |
Move Constructor.
Definition at line 96 of file SharedAcquire.hpp.
|
inline |
Default Destructor.
Definition at line 112 of file SharedAcquire.hpp.
References locked, reference, and samchon::library::Semaphore::release().
|
inline |
Acquire admission.
Acquires an admission and increases count of admission by 1.
If the count is over permitted size, wait until other admissions to be released.
Definition at line 130 of file SharedAcquire.hpp.
References samchon::library::Semaphore::acquire().
Referenced by SharedAcquire().
|
inline |
Release an admission.
Releases an admission what you've acquired. If the admission count was over the limited size, unlock the mutex.
Definition at line 142 of file SharedAcquire.hpp.
References samchon::library::Semaphore::release().
|
private |
|
private |
Referencing count sharing same Semaphore.
Definition at line 54 of file SharedAcquire.hpp.
Referenced by SharedAcquire(), and ~SharedAcquire().
|
private |
Whether the mutex was locked by SharedAcquire.
Definition at line 59 of file SharedAcquire.hpp.
Referenced by SharedAcquire(), and ~SharedAcquire().