Implementation of a mutex class.
More...
#include <PosixMutex.hpp>
Public Member Functions |
| PosixMutex () |
| Constructor. Initialize the mutex.
|
| ~PosixMutex () |
| Destructor. Destroys the mutex.
|
void | lock () |
| Acquires the lock.
|
void | unlock () |
| Releases the lock.
|
bool | tryLock () |
| Tries to acquire the lock.
|
Private Attributes |
pthread_mutex_t | mutex_ |
Detailed Description
Implementation of a mutex class.
The class is non copyable and makes use of the pthread library.
Definition at line 33 of file PosixMutex.hpp.
Constructor & Destructor Documentation
Constructor. Initialize the mutex.
- Exceptions
-
runtime_error | if the mutex initialization fails. |
Definition at line 34 of file PosixMutex.cpp.
{
if (pthread_mutex_init(&
mutex_, NULL) != 0)
throw std::runtime_error(std::string("Error: ") + strerror(errno));
}
Member Function Documentation
Acquires the lock.
If the mutex is busy the calling thread is blocked.
Definition at line 51 of file PosixMutex.hpp.
Tries to acquire the lock.
If the mutex is busy the calling thread continues its executions
- Returns
- True if the lock is acquired, false otherwise.
Definition at line 55 of file PosixMutex.cpp.
{
if (pthread_mutex_trylock(&
mutex_) == EBUSY)
return false;
else
return true;
}
Friends And Related Function Documentation
Member Data Documentation
The documentation for this class was generated from the following files: