RTP Audio System
2.0.0
|
#include <synchronizable.h>
Public Member Functions | |
Synchronizable (const char *name="Synchronizable", const bool recursive=true) | |
~Synchronizable () | |
void | synchronized () |
bool | synchronizedTry () |
void | unsynchronized () |
void | resynchronize () |
const char * | getName () const |
void | setName (const char *name) |
Static Public Member Functions | |
static bool | setCancelState (const bool enabled) |
Protected Attributes | |
pthread_mutex_t | Mutex |
bool | Recursive |
char | MutexName [64] |
This class realizes synchronized access to a thread's data by other threads. Synchronization is done by using a global pthread mutex and obtaining access to this mutex by synchronized() for synchronized access and releasing this mutex for unsynchronized access. IMPORTANT: Do *not* use synchronized()/unsynchronized() within async signal handlers. This may cause deadlocks. See PThread's pthread_mutex_lock man-page, section "Async Signal Safety" for more information!
Synchronizable::Synchronizable | ( | const char * | name = "Synchronizable" , |
const bool | recursive = true |
||
) |
Constructor.
name | Name. |
recursive | true to make mutex recursive (default); false otherwise. |
Destructor.
const char* Synchronizable::getName | ( | ) | const [inline] |
Get name of synchronizable object.
void Synchronizable::resynchronize | ( | ) |
Do reinitialization of Synchronizable.
static bool Synchronizable::setCancelState | ( | const bool | enabled | ) | [inline, static] |
Enable or disable cancelability of calling thread.
enabled | true to enable cancellation; false otherwise. |
void Synchronizable::setName | ( | const char * | name | ) | [inline] |
Set name of synchronizable object.
name | Name. |
void Synchronizable::synchronized | ( | ) | [inline] |
synchronized() begins a synchronized block. The block has to be finished by unsynchronized(). synchronized() will wait until the mutex is available.
bool Synchronizable::synchronizedTry | ( | ) | [inline] |
synchronizedTry() tries to begins a synchronized block. It does the same as synchronized(), but returns immediately, if the mutex is obtained by another thread.
void Synchronizable::unsynchronized | ( | ) | [inline] |
unsynchronized() ends a synchronized block, which has begun by synchronized().
pthread_mutex_t Synchronizable::Mutex [protected] |
char Synchronizable::MutexName[64] [protected] |
bool Synchronizable::Recursive [protected] |