Class implementing scope locking synchronization pattern. More...
#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 | |
Class implementing scope locking synchronization pattern.
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
}
| ACS::ThreadSyncGuard::ThreadSyncGuard | ( | ACE_Recursive_Thread_Mutex * | mutex, | |
| bool | block = true | |||
| ) |
Constructor. Creates a guard and acquires mutex if <block> is true.
| mutex | mutex to be used by guard | |
| block | if true, lock is acuired, otherwise not |
| ACS::ThreadSyncGuard::~ThreadSyncGuard | ( | ) |
Destructor. Relases mutex if necessary.
| void ACS::ThreadSyncGuard::acquire | ( | ) |
Blocks the thread until the lock is acquired.
| void ACS::ThreadSyncGuard::release | ( | ) |
Releases the lock.
state of mutex
| ACE_Recursive_Thread_Mutex* ACS::ThreadSyncGuard::mutex_mp |
mutex used by guard
1.7.0