Guard Class Reference

Utility class to guard a section of code to guarantee exclusive execution in a single thread, using a mutex. More...

#include <guard.h>

Collaboration diagram for Guard:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Guard (const pthread_mutex_t *mutex)
 ~Guard ()

Static Public Member Functions

static void initialize_mutex (pthread_mutex_t &mutex)
static void destroy_mutex (pthread_mutex_t &mutex)

Protected Attributes

const pthread_mutex_t * mutex
 The mutex we're using to protect the critical section of code.


Detailed Description

Utility class to guard a section of code to guarantee exclusive execution in a single thread, using a mutex.

I'm sure this class can become much more robust and useful. At the moment, all it's really good for is instantiating one, which locks the given mutex, and deleting one, which releases the mutex. The easiest way to use it is to create one on the stack: { Guard g(mutex); ... do some stuff ... } This way, even if the stuff in that scope throws an exception, the mutex will always be unlocked properly.

Definition at line 22 of file guard.h.


Constructor & Destructor Documentation

Guard::Guard ( const pthread_mutex_t *  mutex  ) 

Definition at line 8 of file guard.cc.

References mutex, MUTEX_LOG, and PTHREAD_CHECK_AND_THROW.

Guard::~Guard (  ) 

Definition at line 28 of file guard.cc.

References mutex, MUTEX_LOG, and PTHREAD_CHECK_AND_THROW.


Member Function Documentation

void Guard::initialize_mutex ( pthread_mutex_t &  mutex  )  [static]

Definition at line 37 of file guard.cc.

References PTHREAD_CHECK_AND_THROW.

Referenced by History::History(), Message::Message(), and SocketListener::SocketListener().

Here is the caller graph for this function:

void Guard::destroy_mutex ( pthread_mutex_t &  mutex  )  [static]

Definition at line 45 of file guard.cc.

Referenced by History::~History(), and SocketListener::~SocketListener().

Here is the caller graph for this function:


Member Data Documentation

const pthread_mutex_t* Guard::mutex [protected]

The mutex we're using to protect the critical section of code.

Definition at line 35 of file guard.h.

Referenced by Guard(), and ~Guard().


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

Generated on Tue May 13 11:32:46 2008 for consmgr by  doxygen 1.5.5