Main Page Class Hierarchy Compound List File List Compound Members File Members
Guard< Lock > Class Template Reference
List of all members.
Detailed Description
template<class Lock = Mutex>
class Guard< Lock >
A class which acquires a lock on creating and destroys it on destruction.
It is typically used like so:
Mutex my_mutex;
int my_function()
{
Guard g(my_mutex);
do_some_exclusive_stuff();
if (some_condition())
return 1;
do_other_stuff();
return 0;
}
The Mutex is automatically released whenever the Guard goes out of scope, so you don't need to worry about releasing the Mutex in case of exception (e.g., in do_some_exclusive_stuff) or if a code block ends early (e.g., returns 1 in that if clause).
The above function is actually better written using the locking(x) macro.
Constructor & Destructor Documentation
template<class Lock = Mutex> |
Guard< Lock >::Guard |
( |
const Guard< Lock > & |
g |
) |
|
|
template<class Lock = Mutex> |
Guard< Lock >::Guard |
( |
Lock & |
m |
) |
|
|
template<class Lock = Mutex> |
Guard< Lock >::Guard |
( |
Lock * |
m |
) |
|
|
template<class Lock = Mutex> |
Guard< Lock >::~Guard |
( |
|
) |
|
|
Member Function Documentation
template<class Lock = Mutex> |
Guard< Lock >::operator bool |
( |
|
) |
const |
|
template<class Lock = Mutex> |
Guard& Guard< Lock >::operator= |
( |
const Guard< Lock > & |
g |
) |
|
|
The documentation for this class was generated from the following file:
Generated on Fri Dec 20 13:35:11 2002 for NMSTL