ONPOSIX  2.0
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
PosixMutex Class Reference

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 Member Functions

 PosixMutex (const PosixMutex &)
PosixMutexoperator= (const PosixMutex &)

Private Attributes

pthread_mutex_t mutex_

Friends

class PosixCondition

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

PosixMutex ( const PosixMutex )
private

Constructor. Initialize the mutex.

Exceptions
runtime_errorif 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));
}
~PosixMutex ( )

Destructor. Destroys the mutex.

Definition at line 43 of file PosixMutex.cpp.

{
VERIFY_ASSERTION(!pthread_mutex_destroy(&mutex_));
}

Member Function Documentation

void lock ( )
inline

Acquires the lock.

If the mutex is busy the calling thread is blocked.

Definition at line 51 of file PosixMutex.hpp.

{
pthread_mutex_lock(&mutex_);
}

Here is the caller graph for this function:

PosixMutex& operator= ( const PosixMutex )
private
bool tryLock ( )

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;
}
void unlock ( )
inline

Releases the lock.

Definition at line 58 of file PosixMutex.hpp.

{
pthread_mutex_unlock(&mutex_);
}

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class PosixCondition
friend

Definition at line 40 of file PosixMutex.hpp.

Member Data Documentation

pthread_mutex_t mutex_
private

Definition at line 38 of file PosixMutex.hpp.


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