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

Unique lock for writing. More...

#include <UniqueWriteLock.hpp>

Collaboration diagram for samchon::library::UniqueWriteLock:

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

RWMutexrw_mutex
 Managed mutex. More...
 
bool locked
 Whether the mutex was locked by UniqueLock. More...
 

Detailed Description

Unique lock for writing.

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

  • acquired
  • released

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

Class Diagram
Note
Though, that the UniqueWriteLock 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 UniqueWriteLock that manages it.

Library - Critical Section

Author
Jeongho Nam http://samchon.org

Definition at line 39 of file UniqueWriteLock.hpp.

Constructor & Destructor Documentation

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

Construct from mutex.

Parameters
rw_mutexMutex to manage
lockWhether to lock directly or not

Definition at line 62 of file UniqueWriteLock.hpp.

References lock(), and rw_mutex.

Here is the call graph for this function:

samchon::library::UniqueWriteLock::UniqueWriteLock ( const UniqueWriteLock )
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::UniqueWriteLock::UniqueWriteLock ( UniqueWriteLock &&  obj)
inline

Move Constructor.

Parameters
objAn object to move

Definition at line 88 of file UniqueWriteLock.hpp.

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

Here is the call graph for this function:

Member Function Documentation

void samchon::library::UniqueWriteLock::lock ( )
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.

  • Writing can be done by only a section at once.
  • Writing can't be done when reading.
Note
You've to call write_unlock when writing work was terminated.

Definition at line 117 of file UniqueWriteLock.hpp.

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

Referenced by UniqueWriteLock().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

RWMutex* samchon::library::UniqueWriteLock::rw_mutex
private

Managed mutex.

Definition at line 45 of file UniqueWriteLock.hpp.

Referenced by UniqueWriteLock().

bool samchon::library::UniqueWriteLock::locked
private

Whether the mutex was locked by UniqueLock.

Definition at line 50 of file UniqueWriteLock.hpp.


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