|
|
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!
See also: Thread
Synchronizable (const char* name = "Synchronizable",
const bool recursive = true)
| Synchronizable |
Constructor.
Parameters:
name | Name. |
recursive | true to make mutex recursive (default); false otherwise. |
~Synchronizable ()
| ~Synchronizable |
Destructor.
inline void synchronized ()
| synchronized |
synchronized() begins a synchronized block. The block has to be finished by unsynchronized(). synchronized() will wait until the mutex is available.
See also: unsynchronized, synchronizedTry
inline bool synchronizedTry ()
| synchronizedTry |
synchronizedTry() tries to begins a synchronized block. It does the same as synchronized(), but returns immediately, if the mutex is obtained by another thread.
See also: synchronized, unsynchronized
inline void unsynchronized ()
| unsynchronized |
unsynchronized() ends a synchronized block, which has begun by synchronized().
See also: synchronized
void resynchronize ()
| resynchronize |
Do reinitialization of Synchronizable.
inline bool setCancelState (const bool enabled)
| setCancelState |
[static]
Enable or disable cancelability of calling thread.
Parameters:
enabled | true to enable cancellation; false otherwise. |
void synchronized_debug (const char* file, const cardinal line)
| synchronized_debug |
Debug version of synchronized. This will print PID, file name and line number, followed by debug information.
Parameters:
file | File name. |
line | Line number. |
See also: synchronized
void unsynchronized_debug (const char* file, const cardinal line)
| unsynchronized_debug |
Debug version of unsynchronized. This will print PID, file name and line number, followed by debug information.
Parameters:
file | File name. |
line | Line number. |
See also: unsynchronized
bool synchronizedTry_debug (const char* file, const cardinal line)
| synchronizedTry_debug |
Debug version of synchronizedTry. This will print PID, file name and line number, followed by debug information.
Parameters:
file | File name. |
line | Line number. |
See also: synchronizedTry
void resynchronize_debug (const char* file, const cardinal line)
| resynchronize_debug |
Debug version of resynchronize. This will print PID, file name and line number, followed by debug information.
Parameters:
file | File name. |
line | Line number. |
See also: resynchronize
inline const char* getName ()
| getName |
[const]
Get name of synchronizable object (SYNCDEBUGGER mode only, see synchronizable.h).
Returns: Name.
inline void setName (const char* name)
| setName |
Set name of synchronizable object (SYNCDEBUGGER mode only, see synchronizable.h).
Parameters:
name | Name. |
pthread_mutex_t Mutex | Mutex |
[protected]
cardinal RecursionLevel | RecursionLevel |
[protected]
pthread_t Owner | Owner |
[protected]
bool Recursive | Recursive |
[protected]
char MutexName[256] | MutexName[256] |
[protected]
friend class Thread | Thread |
[protected]
static set<Synchronizable*> MutexSet | MutexSet |
[protected]