KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
kjb::Mutex_lock Class Reference

simple RAII class to grab and release a mutex More...

#include <l_mt_mutexlock.h>

Public Member Functions

 Mutex_lock (kjb_c::kjb_pthread_mutex_t *m)
 establish a lock on the mutex (as a C-style struct) More...
 
 Mutex_lock (Pthread_mutex &m)
 establish a lock on the mutex object (as a reference) More...
 
 Mutex_lock (Pthread_mutex *m)
 establish a lock on the mutex object pointer More...
 
void release ()
 release the mutex for others (safe to call twice) More...
 
 ~Mutex_lock ()
 dtor releases the mutex More...
 

Detailed Description

simple RAII class to grab and release a mutex

All this does is lock a mutex at creation time, and guarantee that it gets unlocked, unless an abort occurs. The ctor accepts either a pointer to a kjb_c::kjb_pthread_t object (the C-language style struct used by the multithread wrapper), or a C++ object, either a Pthread_mutex reference or pointer (it does not matter which).

If you wish to unlock the mutex prior to the destruction of this object, just call the release() method. It is safe to call release() multiple times on the same object – only the first one has effect, the rest are benign NOPs. However, if for some reason the mutex cannot be unlocked, the object's destructor will abort the program.

Constructor & Destructor Documentation

kjb::Mutex_lock::Mutex_lock ( kjb_c::kjb_pthread_mutex_t *  m)
inline

establish a lock on the mutex (as a C-style struct)

kjb::Mutex_lock::Mutex_lock ( Pthread_mutex m)
inline

establish a lock on the mutex object (as a reference)

kjb::Mutex_lock::Mutex_lock ( Pthread_mutex m)
inline

establish a lock on the mutex object pointer

kjb::Mutex_lock::~Mutex_lock ( )
inline

dtor releases the mutex

Member Function Documentation

void kjb::Mutex_lock::release ( )
inline

release the mutex for others (safe to call twice)


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