nidas v1.2.3
Public Member Functions | Private Member Functions | Private Attributes | List of all members
nidas::util::Synchronized Class Reference

Synchronized is used a simple guard object for critical sections. More...

#include <ThreadSupport.h>

Public Member Functions

 Synchronized (Cond &cond_)
 Construct the guard object and lock() the lock.
 
 Synchronized (Mutex &mutex_)
 
 ~Synchronized ()
 On destruction, unlock the lock.
 

Private Member Functions

 Synchronized (const Synchronized &)
 
Synchronizedoperator= (const Synchronized &)
 

Private Attributes

Mutexmutexp
 
Condcondp
 

Detailed Description

Synchronized is used a simple guard object for critical sections.

Upon construction it lock()s the given Lock, and then when it goes out of scope, either through a normal exit or an exception, it will be destroyed and the Lock will be unlock()ed. Inside the critical section the thread can call wait() on the Synchronized object to wait on the Lock condition.

Constructor & Destructor Documentation

◆ Synchronized() [1/3]

nidas::util::Synchronized::Synchronized ( Cond & cond_)
inline

Construct the guard object and lock() the lock.

As for Lock, be wary of recursively entering sections Synchronized on the same lock within the same thread. The default, posix mutexes are not recursive and so the thread will deadlock.

Exceptions
Exception

References condp, and nidas::util::Cond::lock().

◆ Synchronized() [2/3]

nidas::util::Synchronized::Synchronized ( Mutex & mutex_)
inline
Exceptions
Exception

References nidas::util::Mutex::lock(), and mutexp.

◆ ~Synchronized()

nidas::util::Synchronized::~Synchronized ( )
inline

On destruction, unlock the lock.

References condp, mutexp, nidas::util::Mutex::unlock(), and nidas::util::Cond::unlock().

◆ Synchronized() [3/3]

nidas::util::Synchronized::Synchronized ( const Synchronized & )
private

Member Function Documentation

◆ operator=()

Synchronized & nidas::util::Synchronized::operator= ( const Synchronized & )
private

Member Data Documentation

◆ condp

Cond* nidas::util::Synchronized::condp
private

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

◆ mutexp

Mutex* nidas::util::Synchronized::mutexp
private

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


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