mutex.h
Go to the documentation of this file.
00001 #ifndef MT_MUTEX_H
00002 #define MT_MUTEX_H
00003 
00004 #include "base.h"
00005 
00006 #include <pthread.h>
00007 
00008 namespace mt
00009 {
00010 
00011 class condition;
00012 
00013 class mutex
00014 {
00015     MT_PREVENT_COPY(mutex)
00016 
00017     public:
00018 
00019         typedef mutex this_type;
00020         typedef void  base_type;
00021 
00022         mutex(void)
00023         {
00024             pthread_mutex_init(&(this->m), 0);
00025         }
00026 
00027         ~mutex(void)
00028         {
00029             pthread_mutex_destroy(&(this->m));
00030         }
00031 
00032         void lock(void)
00033         {
00034             pthread_mutex_lock(&(this->m));
00035         }
00036 
00037         void unlock(void)
00038         {
00039             pthread_mutex_unlock(&(this->m));
00040         }
00041         bool tryLock(void)
00042         {
00043             int a = pthread_mutex_trylock(&(this->m));
00044             return a == 0;
00045         }
00046 
00047     private:
00048 
00049         friend class condition;
00050 
00051         pthread_mutex_t m;
00052 };
00053 
00054 }
00055 
00056 #endif // MT_MUTEX_H


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:33:22