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

Unique acquire from a Semaphore. More...

#include <UniqueAcquire.hpp>

Collaboration diagram for samchon::library::UniqueAcquire:

Public Member Functions

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

Private Attributes

Semaphoresemaphore
 Managed semaphore. More...
 
bool locked
 Whether the semaphore was acquired by the UniqueLock. More...
 

Detailed Description

Unique acquire from a Semaphore.

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

  • acquired
  • released

On construction (or by move-assigning to it), the object acquires a semaphore object, for whose acquiring and releasing operations becomes responsible.

This class guarantees a released status on destruction (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 UniqueAcquire 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 UniqueAcquire that manages it.

The UniqueAcquire is movable, but not copyable.

Library - Critical Section

Author
Jeongho Nam http://samchon.org

Definition at line 39 of file UniqueAcquire.hpp.

Constructor & Destructor Documentation

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

Construct from semaphore.

Parameters
semaphoreSemaphore to manage
lockWhether to lock directly or not

Definition at line 62 of file UniqueAcquire.hpp.

References acquire(), and semaphore.

Here is the call graph for this function:

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

Move Constructor.

Parameters
objAn object to move

Definition at line 88 of file UniqueAcquire.hpp.

References locked, and semaphore.

samchon::library::UniqueAcquire::~UniqueAcquire ( )
inline

Default Destructor.

If read lock has done by the UniqueLock, unlock it

Definition at line 103 of file UniqueAcquire.hpp.

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

Here is the call graph for this function:

Member Function Documentation

void samchon::library::UniqueAcquire::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 115 of file UniqueAcquire.hpp.

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

Referenced by UniqueAcquire().

Here is the call graph for this function:

Here is the caller graph for this function:

void samchon::library::UniqueAcquire::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 127 of file UniqueAcquire.hpp.

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

Here is the call graph for this function:

Member Data Documentation

Semaphore* samchon::library::UniqueAcquire::semaphore
private

Managed semaphore.

Definition at line 45 of file UniqueAcquire.hpp.

Referenced by UniqueAcquire().

bool samchon::library::UniqueAcquire::locked
private

Whether the semaphore was acquired by the UniqueLock.

Definition at line 50 of file UniqueAcquire.hpp.

Referenced by UniqueAcquire().


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