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 &, bool=true)
 Construct from mutex. More...
 
 UniqueReadLock (const UniqueReadLock &)=delete
 Prohibited Copy Constructor. More...
 
 UniqueReadLock (UniqueReadLock &&)
 Move Constructor. More...
 
 ~UniqueReadLock ()
 Default Destructor. More...
 
void lock () const
 Lock on read. More...
 
void unlock () const
 Unlock of read. More...
 

Private Attributes

const RWMutexmtx
 Managed mutex. More...
 
bool isLocked
 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

library_critical_section.png
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.
See also
samchon::library
Author
Jeongho Nam http://samchon.org

Definition at line 39 of file UniqueReadLock.hpp.

Constructor & Destructor Documentation

UniqueReadLock::UniqueReadLock ( const RWMutex mtx,
bool  doLock = true 
)

Construct from mutex.

Parameters
mtxMutex to manage
doLockWhether to lock directly or not

Definition at line 7 of file UniqueReadLock.cpp.

References isLocked, mtx, and samchon::library::RWMutex::readLock().

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.
UniqueReadLock::UniqueReadLock ( UniqueReadLock &&  obj)

Move Constructor.

Parameters
Anobject to move

Definition at line 15 of file UniqueReadLock.cpp.

References isLocked, and mtx.

UniqueReadLock::~UniqueReadLock ( )

Default Destructor.

If read lock has done by the UniqueLock, unlock it

Definition at line 25 of file UniqueReadLock.cpp.

References isLocked, mtx, and samchon::library::RWMutex::readUnlock().

Here is the call graph for this function:

Member Function Documentation

void UniqueReadLock::lock ( ) const

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 34 of file UniqueReadLock.cpp.

References isLocked, mtx, and samchon::library::RWMutex::readLock().

Here is the call graph for this function:

void UniqueReadLock::unlock ( ) const

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 44 of file UniqueReadLock.cpp.

References isLocked, mtx, and samchon::library::RWMutex::readUnlock().

Referenced by samchon::library::EventDispatcher::dispatch().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

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

Managed mutex.

Definition at line 45 of file UniqueReadLock.hpp.

Referenced by lock(), UniqueReadLock(), unlock(), and ~UniqueReadLock().

bool samchon::library::UniqueReadLock::isLocked
private

Whether the mutex was locked by UniqueLock.

Definition at line 50 of file UniqueReadLock.hpp.

Referenced by lock(), UniqueReadLock(), unlock(), and ~UniqueReadLock().


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