Utility class to acquire a lock that is released by the destructor. More...
Public Member Functions | |
Block (Recursive_lock *lock=0) | |
Constructor. More... |
|
~Block () | |
Destructor. More... |
|
void | set (Recursive_lock *lock) |
Acquires a lock. More... |
|
bool | try_set (Recursive_lock *lock) |
Tries to acquire a lock. More... |
|
void | release () |
Releases the lock. More... |
|
Utility class to acquire a lock that is released by the destructor.
|
explicit |
Constructor.
lock | If not NULL , this lock is acquired. If NULL , set() can be used to explicitly acquire a lock later. |
mi::base::Recursive_lock::Block::~Block | ( | ) |
Destructor.
Releases the lock (if it is acquired).
void mi::base::Recursive_lock::Block::release | ( | ) |
Releases the lock.
Useful to release the lock before the destructor is called.
void mi::base::Recursive_lock::Block::set | ( | Recursive_lock * | lock) |
Acquires a lock.
Releases the current lock (if it is set) and acquires the given lock. Useful to acquire a different lock, or to acquire a lock if no lock was acquired in the constructor.
This method does nothing if the passed lock is already acquired by this class.
lock | The new lock to acquire. |
bool mi::base::Recursive_lock::Block::try_set | ( | Recursive_lock * | lock) |
Tries to acquire a lock.
Releases the current lock (if it is set) and tries to acquire the given lock. Useful to acquire a different lock without blocking, or to acquire a lock without blocking if no lock was acquired in the constructor.
This method does nothing if the passed lock is already acquired by this class.
lock | The new lock to acquire. |
true
if the lock was acquired, false
otherwise.