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

Shared acquire from a Semaphore. More...

#include <SharedAcquire.hpp>

Collaboration diagram for samchon::library::SharedAcquire:

Public Member Functions

 SharedAcquire (Semaphore &semaphore, bool lock=true)
 Construct from Semaphore. More...
 
 SharedAcquire (const SharedAcquire &obj)
 Copy Constructor. More...
 
 SharedAcquire (SharedAcquire &&obj)
 Move Constructor. More...
 
 ~SharedAcquire ()
 Default Destructor. More...
 
void acquire ()
 Acquire admission. More...
 
void release ()
 Release an admission. More...
 

Private Attributes

Semaphoresemaphore
 Managed Semaphore. More...
 
std::atomic< size_t > * reference
 Referencing count sharing same Semaphore. More...
 
std::atomic< bool > * locked
 Whether the mutex was locked by SharedAcquire. More...
 

Detailed Description

Shared acquire from a Semaphore.

A SharedAcquire is an object manages a Semaphore with shared ownership in both states.

  • acquired
  • released

On default construction, the object acquires a Semaphore object, for whose acquiring and releasing operations becomes responsible. When copy constructions, responsibilities of acquiring and releasing Semaphore are shared with copied with those SharedAcquire objects.

The class shared_lock is a general-purpose shared mutex ownership wrapper allowing deferred locking, timed locking and transfer of lock ownership. Locking a shared_lock locks the associated shared mutex in shared mode (to lock it in exclusive mode, std::unique_lock can be used)

This class guarantees a released status on destruction of all shared objects (even if not called explicitly). Therefore it is especially useful as an object with automatic duration, as it guarantees the Semaphore object is properly released in case an exception is thrown.

Referenced comments of std::unique_lock

Class Diagram
Note

Though, that the SharedAcquire object does not manage the lifetime of the Semaphore object in any way: the duration of the Semaphore object shall extend at least until the destruction of the SharedAcquire that manages it.

Library - Critical Section

Author
Jeongho Nam http://samchon.org

Definition at line 43 of file SharedAcquire.hpp.

Constructor & Destructor Documentation

samchon::library::SharedAcquire::SharedAcquire ( Semaphore semaphore,
bool  lock = true 
)
inline

Construct from Semaphore.

Parameters
semaphoreSemaphore to manage
lockWhether to lock directly or not

Definition at line 71 of file SharedAcquire.hpp.

References acquire(), and semaphore.

Here is the call graph for this function:

samchon::library::SharedAcquire::SharedAcquire ( const SharedAcquire obj)
inline

Copy Constructor.

Definition at line 84 of file SharedAcquire.hpp.

References locked, reference, and semaphore.

samchon::library::SharedAcquire::SharedAcquire ( SharedAcquire &&  obj)
inline

Move Constructor.

Definition at line 96 of file SharedAcquire.hpp.

samchon::library::SharedAcquire::~SharedAcquire ( )
inline

Default Destructor.

Definition at line 112 of file SharedAcquire.hpp.

References locked, reference, and samchon::library::Semaphore::release().

Here is the call graph for this function:

Member Function Documentation

void samchon::library::SharedAcquire::acquire ( )
inline

Acquire admission.

Acquires an admission and increases count of admission by 1.

If the count is over permitted size, wait until other admissions to be released.

  • Lock on mutex

Definition at line 130 of file SharedAcquire.hpp.

References samchon::library::Semaphore::acquire().

Referenced by SharedAcquire().

Here is the call graph for this function:

Here is the caller graph for this function:

void samchon::library::SharedAcquire::release ( )
inline

Release an admission.

Releases an admission what you've acquired. If the admission count was over the limited size, unlock the mutex.

Definition at line 142 of file SharedAcquire.hpp.

References samchon::library::Semaphore::release().

Here is the call graph for this function:

Member Data Documentation

Semaphore* samchon::library::SharedAcquire::semaphore
private

Managed Semaphore.

Definition at line 49 of file SharedAcquire.hpp.

Referenced by SharedAcquire().

std::atomic<size_t>* samchon::library::SharedAcquire::reference
private

Referencing count sharing same Semaphore.

Definition at line 54 of file SharedAcquire.hpp.

Referenced by SharedAcquire(), and ~SharedAcquire().

std::atomic<bool>* samchon::library::SharedAcquire::locked
private

Whether the mutex was locked by SharedAcquire.

Definition at line 59 of file SharedAcquire.hpp.

Referenced by SharedAcquire(), and ~SharedAcquire().


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