Samchon Framework for CPP  1.0.0
samchon::library::UniqueReadLock Class Reference

Unique lock for reading. More...

#include <UniqueReadLock.hpp>

Collaboration diagram for samchon::library::UniqueReadLock:

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 RWMutexrw_mutex
 Managed mutex. More...
 
bool locked
 Whether the mutex was locked by UniqueLock. More...
 

Detailed Description

Unique lock for reading.

A UniqueAcquire is an object manages a RWMutex with unique ownership in both states.

  • locked
  • unlocked

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

Class Diagram
Note
Though, that the UniqueReadLock object does not manage the lifetime of the RWMutex object in any way: the duration of the RWMutex object shall extend at least until the destruction of the UniqueReadLock that manages it.

Library - Critical Section

Author
Jeongho Nam http://samchon.org

Definition at line 37 of file UniqueReadLock.hpp.

Constructor & Destructor Documentation

samchon::library::UniqueReadLock::UniqueReadLock ( const RWMutex rw_mutex,
bool  lock = true 
)
inline

Construct from mutex.

Parameters
rw_mutexMutex to manage
lockWhether to lock directly or not

Definition at line 60 of file UniqueReadLock.hpp.

References lock(), and rw_mutex.

Here is the call graph for this function:

samchon::library::UniqueReadLock::UniqueReadLock ( const UniqueReadLock )
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.

Parameters
objTried object to copy.
samchon::library::UniqueReadLock::UniqueReadLock ( UniqueReadLock &&  obj)
inline

Move Constructor.

Parameters
objAn object to move

Definition at line 86 of file UniqueReadLock.hpp.

samchon::library::UniqueReadLock::~UniqueReadLock ( )
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().

Here is the call graph for this function:

Member Function Documentation

void samchon::library::UniqueReadLock::lock ( ) const
inline

Lock on read.

Increases a reading count.

When write_lock is on a progress, wait until write_unlock to be called.

  • Reading can be done by multiple sections.
  • Reading can't be done when writing.
Warning
You've to call read_unlock when the reading work is terminated.

Definition at line 113 of file UniqueReadLock.hpp.

References samchon::library::RWMutex::readLock().

Referenced by UniqueReadLock().

Here is the call graph for this function:

Here is the caller graph for this function:

void samchon::library::UniqueReadLock::unlock ( ) const
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().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

const RWMutex* samchon::library::UniqueReadLock::rw_mutex
private

Managed mutex.

Definition at line 43 of file UniqueReadLock.hpp.

Referenced by UniqueReadLock().

bool samchon::library::UniqueReadLock::locked
private

Whether the mutex was locked by UniqueLock.

Definition at line 48 of file UniqueReadLock.hpp.


The documentation for this class was generated from the following file: