4 # include <autosprintf.h>
10 extern void init_mutex(pthread_mutex_t *);
12 extern void init_mutex(pthread_mutex_t &);
14 extern void destroy_mutex(pthread_mutex_t *);
16 extern void destroy_mutex(pthread_mutex_t &);
18 using namespace Aleph;
22 pthread_mutex_t * mutex;
23 bool unlock_when_destroy;
30 throw std::domain_error(
"unlock: NULL pointer to mutex");
32 pthread_mutex_unlock(mutex);
38 throw std::domain_error(
"lock: NULL pointer to mutex");
40 pthread_mutex_lock(mutex);
43 UseMutex(pthread_mutex_t *m) : mutex(m), unlock_when_destroy(
true)
48 UseMutex(pthread_mutex_t & m): mutex(&m), unlock_when_destroy(
true)
53 void enter() { lock(); }
55 void leave() { unlock(); }
59 if (unlock_when_destroy)
63 void disallow_unlock() { unlock_when_destroy =
false; }
65 void allow_unlock() { unlock_when_destroy =
true; }
69 # define CTOR_USE_MUTEX(name, mutex) name(mutex)
71 # define CTOR_INH_USE_MUTEX(mutex) UseMutex(mutex)
73 # define USE_MUTEX(name, mutex) UseMutex name(mutex)
75 # define CRITICAL_SECTION(mutex) UseMutex critical_section(mutex)
Definition: useMutex.H:20