Samchon Framework for CPP
1.0.0
|
Unique acquire from a Semaphore. More...
#include <UniqueAcquire.hpp>
Public Member Functions | |
UniqueAcquire (Semaphore &semaphore, bool lock=true) | |
Construct from semaphore. More... | |
UniqueAcquire (const UniqueAcquire &obj)=delete | |
Prohibited Copy Constructor. More... | |
UniqueAcquire (UniqueAcquire &&obj) | |
Move Constructor. More... | |
~UniqueAcquire () | |
Default Destructor. More... | |
void | acquire () |
Acquire admission. More... | |
void | release () |
Release an admission. More... | |
Private Attributes | |
Semaphore * | semaphore |
Managed semaphore. More... | |
bool | locked |
Whether the semaphore was acquired by the UniqueLock. More... | |
Unique acquire from a Semaphore.
A UniqueAcquire is an object manages a Semaphore with unique ownership in both states.
On construction (or by move-assigning to it), the object acquires a semaphore object, for whose acquiring and releasing operations becomes responsible.
This class guarantees a released status on destruction (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 UniqueAcquire 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 UniqueAcquire that manages it.
The UniqueAcquire is movable, but not copyable.
Definition at line 39 of file UniqueAcquire.hpp.
|
inline |
Construct from semaphore.
semaphore | Semaphore to manage |
lock | Whether to lock directly or not |
Definition at line 62 of file UniqueAcquire.hpp.
References acquire(), and semaphore.
|
delete |
Prohibited Copy Constructor.
UniqueAcquire can't be copied. Use pointer, reference instead.
If what you want is UniqueAcquire(s) references each other and unlock when all related UniqueAcquire objects are destructed, SharedAcquire is the best way.
obj | Tried object to copy. |
|
inline |
|
inline |
Default Destructor.
If read lock has done by the UniqueLock, unlock it
Definition at line 103 of file UniqueAcquire.hpp.
References 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 115 of file UniqueAcquire.hpp.
References samchon::library::Semaphore::acquire().
Referenced by UniqueAcquire().
|
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 127 of file UniqueAcquire.hpp.
References samchon::library::Semaphore::release().
|
private |
|
private |
Whether the semaphore was acquired by the UniqueLock.
Definition at line 50 of file UniqueAcquire.hpp.
Referenced by UniqueAcquire().