#include <guard.h>
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. |
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.
Guard::Guard | ( | const pthread_mutex_t * | mutex | ) |
Guard::~Guard | ( | ) |
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().
void Guard::destroy_mutex | ( | pthread_mutex_t & | mutex | ) | [static] |
Definition at line 45 of file guard.cc.
Referenced by History::~History(), and SocketListener::~SocketListener().
const pthread_mutex_t* Guard::mutex [protected] |