#include <acsThreadBase.h>
Public Member Functions | |
ThreadSyncGuard (ACE_Recursive_Thread_Mutex *mutex, bool block=true) | |
~ThreadSyncGuard () | |
void | acquire () |
void | release () |
Public Attributes | |
ACE_Recursive_Thread_Mutex * | mutex_mp |
mutex used by guard | |
bool | acquired_m |
state of mutex |
ThreadSyncGuard implements scope locking synchronization pattern, which is very usefull not to forget to release (or relase can be by-passed by an exception) and so avoiding deadlocks. Mutex is automatically released when out of scope.
ThreadSyncGuard uses recursive thread mutex. An example of usage:
void PowerSupplyImpl::shutdown() { //ThreadSyncGuard guard("gizmo0::propertyVector"); ThreadSyncGuard guard(mutex_m);
// do something
// optional lock release guard.release();
// do something
// optional locking guard.acquire();
// do something
// lock is automatically released when out of scope
}
|
Constructor. Creates a guard and acquires mutex if <block> is true.
|
|
Destructor. Relases mutex if necessary. |
|
Blocks the thread until the lock is acquired. |
|
Releases the lock. |
|
state of mutex
|
|
mutex used by guard
|