#include <Locker.hxx>
Public Member Functions | |
Locker (L &lock) | |
Constructs a locker class. | |
~Locker () | |
Handles the locker instance destruction. |
This class will call method lock() on a specified resource in the constructor and unlock() in the destructor of the last instance in a copy chain. Creating instances of this class on the stack (e.g. automatic variables or temporaries) will guarantee unlocking even in presense of exceptions due to C++ stack unwinding feature.
Usage:
_mutex for
the duration of an expression: ... ( sk::rt::Locker<sk::rt::Mutex>(_mutex), _a.calc() + _b.calc() ); ...
_mutex for
the duration of a method: void someMethod() { sk::rt::Locker<sk::rt::Mutex> locker(_mutex); if(process() != 0) { throw sk::util::IllegalStateException("processing failed"); } }
sk::rt::Locker< L >::Locker | ( | L & | lock | ) | [inline] |
Constructs a locker class.
The constructor will lock a specified resource by calling its lock() method.
sk::rt::Locker< L >::~Locker | ( | ) | [inline] |
Handles the locker instance destruction.
When this locker goes out of scope, it will call unlock() on the resource it has been costructed with, when it is the last instance in a copy chain.