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

dynamically allocated mutex: unlock before you destroy it! More...

#include <l_mt_mutexlock.h>

Inheritance diagram for kjb::Pthread_mutex:
kjb::Pthread_locked_mutex

Public Member Functions

 Pthread_mutex (void(Pthread_mutex::*pmf)()=0)
 dynamic mutex: unlock before you destroy it! More...
 
virtual ~Pthread_mutex ()
 dtor cleans up the mutex, which MUST be unlocked beforehand. More...
 
void lock ()
 lock this mutex More...
 
void unlock ()
 unlock this mutex More...
 
int try_lock ()
 try to lock; return WOULD_BLOCK if locked, else NO_ERROR. More...
 

Friends

class Mutex_lock
 

Detailed Description

dynamically allocated mutex: unlock before you destroy it!

This object is not copyable or assignable, but it does let you dynamically create a mutex.

You cannot store these objects in a container, because they are uncopyable. However, you can store shared pointers to them easily, e.g.:

#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
std::vector<boost::shared_ptr<kjb::Pthread_mutex> > foo_lock;
while (foo_lock.size() < PROPER_SIZE)
{
foo_lock.push_back(boost::make_shared<kjb::Pthread_mutex>());
}
Warning
You are obliged to make sure the mutex is unlocked before you destroy it!
See Also
Pthread_locked_mutex

Constructor & Destructor Documentation

kjb::Pthread_mutex::Pthread_mutex ( void(Pthread_mutex::*)()  pmf = 0)
inline

dynamic mutex: unlock before you destroy it!

virtual kjb::Pthread_mutex::~Pthread_mutex ( )
inlinevirtual

dtor cleans up the mutex, which MUST be unlocked beforehand.

Member Function Documentation

void kjb::Pthread_mutex::lock ( )
inline

lock this mutex

int kjb::Pthread_mutex::try_lock ( )
inline

try to lock; return WOULD_BLOCK if locked, else NO_ERROR.

void kjb::Pthread_mutex::unlock ( )
inline

unlock this mutex

Friends And Related Function Documentation

friend class Mutex_lock
friend

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