Samchon Framework for CPP
1.0.0
|
Unique lock for reading. More...
#include <UniqueReadLock.hpp>
Public Member Functions | |
UniqueReadLock (const RWMutex &rw_mutex, bool lock=true) | |
Construct from mutex. More... | |
UniqueReadLock (const UniqueReadLock &)=delete | |
Prohibited Copy Constructor. More... | |
UniqueReadLock (UniqueReadLock &&obj) | |
Move Constructor. More... | |
~UniqueReadLock () | |
Default Destructor. More... | |
void | lock () const |
Lock on read. More... | |
void | unlock () const |
Unlock of read. More... | |
Private Attributes | |
const RWMutex * | rw_mutex |
Managed mutex. More... | |
bool | locked |
Whether the mutex was locked by UniqueLock. More... | |
Unique lock for reading.
A UniqueAcquire 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 reading side, for whose locking and unlocking operations becomes responsible.
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 37 of file UniqueReadLock.hpp.
|
inline |
Construct from mutex.
rw_mutex | Mutex to manage |
lock | Whether to lock directly or not |
Definition at line 60 of file UniqueReadLock.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 |
|
inline |
Default Destructor.
If read lock has done by the UniqueLock, unlock it
Definition at line 101 of file UniqueReadLock.hpp.
References samchon::library::RWMutex::readUnlock().
|
inline |
Lock on read.
Increases a reading count.
When write_lock is on a progress, wait until write_unlock to be called.
Definition at line 113 of file UniqueReadLock.hpp.
References samchon::library::RWMutex::readLock().
Referenced by UniqueReadLock().
|
inline |
Unlock of read.
Decreases a reading count.
When write_lock had done after read_lock, it continues by read_unlock if the reading count was 1 (read_unlock makes the count to be zero).
Definition at line 125 of file UniqueReadLock.hpp.
References samchon::library::RWMutex::readUnlock().
Referenced by samchon::library::EventDispatcher::dispatch(), samchon::templates::service::Server::sendData(), samchon::templates::external::ExternalSystemArray< Viewer >::sendData(), samchon::templates::service::User::sendData(), and samchon::templates::distributed::DistributedProcess::sendData().
|
private |
|
private |
Whether the mutex was locked by UniqueLock.
Definition at line 48 of file UniqueReadLock.hpp.