00001
00020 #ifndef COIL_MUTEX_H
00021 #define COIL_MUTEX_H
00022
00023 #include <pthread.h>
00024
00025 namespace coil
00026 {
00027 class Mutex
00028 {
00029 public:
00030 Mutex(const char * const name = 0)
00031 {
00032 ::pthread_mutex_init(&mutex_, 0);
00033 }
00034
00035 ~Mutex()
00036 {
00037 ::pthread_mutex_destroy(&mutex_);
00038 }
00039
00040 inline void lock()
00041 {
00042 ::pthread_mutex_lock(&mutex_);
00043 }
00044
00045 inline bool trylock()
00046 {
00047 return ::pthread_mutex_trylock(&mutex_);
00048 }
00049
00050 inline void unlock()
00051 {
00052 ::pthread_mutex_unlock(&mutex_);
00053 }
00054 pthread_mutex_t mutex_;
00055
00056 private:
00057 Mutex(const Mutex&);
00058 Mutex& operator=(const Mutex &);
00059 };
00060 };
00061 #endif // COIL_MUTEX_H