Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes
MutexLock Class Reference

The MutexLock class is used to protect a section of code so that at any given time only a single thread can perform the protected operation. More...

#include <thread.h>

Collaboration diagram for MutexLock:
Collaboration graph
[legend]

Public Member Functions

 MutexLock (Mutex &_mutex)
 Acquire the mutex. More...
 
 ~MutexLock ()
 Release the mutex automatically. More...
 

Private Attributes

Mutexmutex
 

Detailed Description

The MutexLock class is used to protect a section of code so that at any given time only a single thread can perform the protected operation.

It use Mutex to protect operation. Using this class is usefull and exception safe. The mutex that has been locked is automatically released when the function call stack falls out of scope, so one doesnt have to remember to unlock the mutex at each function return.

A common use is

void func_to_protect() { MutexLock lock(mutex); ... operation ... }

NOTE: do not declare variable as "MutexLock (mutex)", the mutex will be released at statement end.

Author
Frediano Ziglio fredd.nosp@m.y77@.nosp@m.angel.nosp@m.fire.nosp@m..com Mutex automatic locker for protected access.

Definition at line 328 of file thread.h.

Constructor & Destructor Documentation

MutexLock::MutexLock ( Mutex _mutex)
inline

Acquire the mutex.

Parameters
_mutexreference to mutex to aquire.

Definition at line 338 of file thread.h.

MutexLock::~MutexLock ( )
inline

Release the mutex automatically.

Definition at line 345 of file thread.h.

Field Documentation

Mutex& MutexLock::mutex
private

Definition at line 331 of file thread.h.


The documentation for this class was generated from the following file: