Fawkes API
Fawkes Development Version
|
#include <>>
Public Member Functions | |
MutexLocker (RefPtr< Mutex > mutex, bool initially_lock=true) | |
Constructor. More... | |
MutexLocker (Mutex *mutex, bool initially_lock=true) | |
Constructor. More... | |
MutexLocker (Mutex &mutex, bool initially_lock=true) | |
Constructor. More... | |
~MutexLocker () | |
Destructor. More... | |
void | relock () |
Lock this mutex, again. More... | |
void | unlock () |
Unlock the mutex. More... | |
Mutex locking helper. This class is a convenience function which can help you prevent a quite a few headaches. Consider the following code.
This is not a complete list of examples but as you see if you have many exit points in a function it becomes more and more work to have correct locking behavior.
This is a lot simpler with the MutexLocker. The MutexLocker locks the given mutex on creation, and unlocks it in the destructor. If you now have a mutex locker on the stack as integral type the destructor is called automagically on function exit and thus the mutex is appropriately unlocked. The code would look like this:
Definition at line 39 of file mutex_locker.h.
Constructor.
mutex | Mutex to lock/unlock appropriately. |
initially_lock | true to lock the mutex in the constructor, false to not lock |
Definition at line 95 of file mutex_locker.cpp.
fawkes::MutexLocker::MutexLocker | ( | Mutex * | mutex, |
bool | initially_lock = true |
||
) |
Constructor.
mutex | Mutex to lock/unlock appropriately. |
initially_lock | true to lock the mutex in the constructor, false to not lock |
Definition at line 109 of file mutex_locker.cpp.
fawkes::MutexLocker::MutexLocker | ( | Mutex & | mutex, |
bool | initially_lock = true |
||
) |
Constructor.
mutex | Mutex to lock/unlock appropriately. |
initially_lock | true to lock the mutex in the constructor, false to not lock |
Definition at line 122 of file mutex_locker.cpp.
fawkes::MutexLocker::~MutexLocker | ( | ) |
Destructor.
Definition at line 132 of file mutex_locker.cpp.
void fawkes::MutexLocker::relock | ( | ) |
Lock this mutex, again.
Use this if you unlocked the mutex from the outside.
Definition at line 147 of file mutex_locker.cpp.
Referenced by fawkes::SyncPoint::unregister_emitter(), and fawkes::SyncPoint::wait().
void fawkes::MutexLocker::unlock | ( | ) |
Unlock the mutex.
Definition at line 159 of file mutex_locker.cpp.
Referenced by fawkes::BlackBoardInterfaceListMaintainer::BlackBoardInterfaceListMaintainer(), MetricsThread::init(), PlexilTimerThread::loop(), SickTiM55xUSBAcquisitionThread::loop(), OpenNiImageThread::loop(), OpenNiDepthThread::loop(), OpenNiPointCloudThread::loop(), fawkes::SyncPoint::unregister_emitter(), and fawkes::SyncPoint::wait().