00001 #ifndef IBRCOMMON_MUTEX_H_ 00002 #define IBRCOMMON_MUTEX_H_ 00003 00004 #include <pthread.h> 00005 #include "ibrcommon/Exceptions.h" 00006 00007 namespace ibrcommon 00008 { 00009 class MutexException : public ibrcommon::Exception 00010 { 00011 public: 00012 MutexException(string what = "An error occured during mutex operation.") throw() : ibrcommon::Exception(what) 00013 { 00014 }; 00015 }; 00016 00017 class Mutex 00018 { 00019 public: 00020 enum MUTEX_TYPE 00021 { 00022 MUTEX_NORMAL = PTHREAD_MUTEX_NORMAL, 00023 MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE, 00024 MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK 00025 }; 00026 00027 Mutex(MUTEX_TYPE type = MUTEX_ERRORCHECK); 00028 virtual ~Mutex(); 00029 00030 virtual void trylock() throw (MutexException); 00031 virtual void enter() throw (MutexException); 00032 virtual void leave() throw (MutexException); 00033 00034 protected: 00035 pthread_mutex_t m_mutex; 00036 }; 00037 } 00038 00039 #endif /*MUTEX_H_*/
1.7.1