Samchon Framework for CPP
1.0.0
|
Unique lock for writing. More...
#include <UniqueWriteLock.hpp>
Public Member Functions | |
UniqueWriteLock (RWMutex &, bool=true) | |
Construct from mutex. More... | |
UniqueWriteLock (const UniqueWriteLock &)=delete | |
Prohibited Copy Constructor. More... | |
UniqueWriteLock (UniqueWriteLock &&) | |
Move Constructor. More... | |
~UniqueWriteLock () | |
Destructor. More... | |
void | lock () |
Lock on writing. More... | |
void | unlock () |
Unlock on writing. More... | |
Private Attributes | |
RWMutex * | mtx |
Managed mutex. More... | |
bool | isLocked |
Whether the mutex was locked by UniqueLock. More... | |
Unique lock for writing.
A UniqueWriteLock is an object manages a RWMutex with unique ownership in both states.
On construction (or by move-assigning to it), the object locks a RWMutex object on writing side, for whose locking and unlocking operations becomes responsible.
The object supports both states: locked and unlocked.
This class guarantees a unlocked status on destruction (even if not called explicitly). Therefore it is especially useful as an object with automatic duration, as it guarantees the RWMutex object is properly unlocked in case an exception is thrown.
Referenced comments of std::unique_lock
Definition at line 41 of file UniqueWriteLock.hpp.
UniqueWriteLock::UniqueWriteLock | ( | RWMutex & | mtx, |
bool | doLock = true |
||
) |
Construct from mutex.
mtx | Mutex to manage |
doLock | Whether to lock directly or not |
Definition at line 7 of file UniqueWriteLock.cpp.
References isLocked, mtx, and samchon::library::RWMutex::writeLock().
|
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. |
UniqueWriteLock::UniqueWriteLock | ( | UniqueWriteLock && | obj | ) |
UniqueWriteLock::~UniqueWriteLock | ( | ) |
Destructor.
If write lock has done by the UniqueLock, unlock it
Definition at line 25 of file UniqueWriteLock.cpp.
References isLocked, mtx, and samchon::library::RWMutex::writeUnlock().
void UniqueWriteLock::lock | ( | ) |
Lock on writing.
Changes writing flag to true.
If another write_lock or read_lock is on a progress, wait until them to be unlocked.
Definition at line 34 of file UniqueWriteLock.cpp.
References isLocked, mtx, and samchon::library::RWMutex::writeLock().
void UniqueWriteLock::unlock | ( | ) |
Unlock on writing.
Definition at line 42 of file UniqueWriteLock.cpp.
References isLocked, mtx, and samchon::library::RWMutex::writeUnlock().
Referenced by samchon::protocol::service::User::addClient(), samchon::protocol::service::User::eraseClient(), and samchon::library::EventDispatcher::EventDispatcher().
|
private |
Managed mutex.
Definition at line 47 of file UniqueWriteLock.hpp.
Referenced by lock(), UniqueWriteLock(), unlock(), and ~UniqueWriteLock().
|
private |
Whether the mutex was locked by UniqueLock.
Definition at line 52 of file UniqueWriteLock.hpp.
Referenced by lock(), UniqueWriteLock(), unlock(), and ~UniqueWriteLock().