C12Adapter Opensource C++ Interface
|
Scope based locker that acquires the lock at construction, and releases it at destruction. More...
Public Member Functions | |
Locker (const MSynchronizer &s) | |
Lock the given object at construction. More... | |
Locker (const MSynchronizer &s, long timeout) | |
Lock the given object with timeout at construction. More... | |
~Locker () | |
If the lock was acquired at construction, unlock the client synchronizer at destruction. More... | |
bool | IsLocked () const |
Whether the object has been locked in the constructor. More... | |
Scope based locker that acquires the lock at construction, and releases it at destruction.
Typical usage of this convenience class is
MSynchronizer::Locker::Locker | ( | const MSynchronizer & | s | ) |
Lock the given object at construction.
If the object is already locked within a different thread, the constructor call will wait until the lock is released.
Lock timeout is set to infinity so that if the constructor succeeds, IsLocked() will always return true.
The constructor can fail with a system error exception.
MSynchronizer::Locker::Locker | ( | const MSynchronizer & | s, |
long | timeout | ||
) |
Lock the given object with timeout at construction.
If the object is already locked within a different thread, the constructor will wait for the given number of milliseconds until the lock is released.
If the given timeout expires the constructor exits successfully, but IsLocked() will return false.
The constructor can fail with a system error exception.
MSynchronizer::Locker::~Locker | ( | ) |
If the lock was acquired at construction, unlock the client synchronizer at destruction.
Typically, the destructor is called implicitly when the locker object goes out of scope.
|
inline |
Whether the object has been locked in the constructor.
This is useful to determine if the timeout has occurred, in which case the return value will be false.