Samchon Framework for CPP
1.0.0
|
Unique lock for writing. More...
#include <UniqueWriteLock.hpp>
Public Member Functions | |
UniqueWriteLock (RWMutex &rw_mutex, bool lock=true) | |
Construct from mutex. More... | |
UniqueWriteLock (const UniqueWriteLock &)=delete | |
Prohibited Copy Constructor. More... | |
UniqueWriteLock (UniqueWriteLock &&obj) | |
Move Constructor. More... | |
~UniqueWriteLock () | |
Destructor. More... | |
void | lock () |
Lock on writing. More... | |
void | unlock () |
Unlock on writing. More... | |
Private Attributes | |
RWMutex * | rw_mutex |
Managed mutex. More... | |
bool | locked |
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 39 of file UniqueWriteLock.hpp.
|
inline |
Construct from mutex.
rw_mutex | Mutex to manage |
lock | Whether to lock directly or not |
Definition at line 62 of file UniqueWriteLock.hpp.
References lock(), and rw_mutex.
|
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 |
Move Constructor.
obj | An object to move |
Definition at line 88 of file UniqueWriteLock.hpp.
|
inline |
Destructor.
If write lock has done by the UniqueLock, unlock it
Definition at line 105 of file UniqueWriteLock.hpp.
References samchon::library::RWMutex::writeUnlock().
|
inline |
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 117 of file UniqueWriteLock.hpp.
References samchon::library::RWMutex::writeLock().
Referenced by UniqueWriteLock().
|
inline |
Unlock on writing.
Definition at line 129 of file UniqueWriteLock.hpp.
References samchon::library::RWMutex::writeUnlock().
Referenced by samchon::library::EventDispatcher::EventDispatcher(), and samchon::templates::parallel::ParallelSystemArray< SlaveDriver >::sendPieceData().
|
private |
|
private |
Whether the mutex was locked by UniqueLock.
Definition at line 50 of file UniqueWriteLock.hpp.