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

Private Attributes

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

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

Definition at line 41 of file UniqueWriteLock.hpp.

Constructor & Destructor Documentation

UniqueWriteLock::UniqueWriteLock ( RWMutex mtx,
bool  doLock = true 
)

Construct from mutex.

Parameters
mtxMutex to manage
doLockWhether to lock directly or not

Definition at line 7 of file UniqueWriteLock.cpp.

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

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

Move Constructor.

Parameters
Anobject to move

Definition at line 15 of file UniqueWriteLock.cpp.

References isLocked, and mtx.

UniqueWriteLock::~UniqueWriteLock ( )

Destructor.

If write lock has done by the UniqueLock, unlock it

Definition at line 25 of file UniqueWriteLock.cpp.

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

Here is the call graph for this function:

Member Function Documentation

void UniqueWriteLock::lock ( )

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

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

Here is the call graph for this function:

void UniqueWriteLock::unlock ( )

Unlock on writing.

Definition at line 42 of file UniqueWriteLock.cpp.

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

Referenced by samchon::protocol::service::User::addClient(), samchon::protocol::service::User::eraseClient(), and samchon::library::EventDispatcher::EventDispatcher().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

RWMutex* samchon::library::UniqueWriteLock::mtx
private

Managed mutex.

Definition at line 47 of file UniqueWriteLock.hpp.

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

bool samchon::library::UniqueWriteLock::isLocked
private

Whether the mutex was locked by UniqueLock.

Definition at line 52 of file UniqueWriteLock.hpp.

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


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