00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #ifndef _Mutex_incl_
00020 #define _Mutex_incl_
00021 
00022 #include <rlog/common.h>
00023 
00024 #ifdef _WIN32
00025     #include <windows.h>
00026     
00027     #undef ERROR
00028 
00029     typedef CRITICAL_SECTION rlog_mutex_t;
00030     #define rlog_mutex_init InitializeCriticalSection
00031     #define rlog_mutex_destroy DeleteCriticalSection
00032     #define rlog_mutex_lock EnterCriticalSection
00033     #define rlog_mutex_unlock LeaveCriticalSection
00034 #else
00035     #include <pthread.h>
00036 
00037     typedef pthread_mutex_t rlog_mutex_t;
00038     #define rlog_mutex_init(m) pthread_mutex_init((m), 0)
00039     #define rlog_mutex_destroy pthread_mutex_destroy
00040     #define rlog_mutex_lock pthread_mutex_lock
00041     #define rlog_mutex_unlock pthread_mutex_unlock
00042 #endif
00043 
00044 namespace rlog
00045 {
00053     class RLOG_DECL Mutex
00054     {
00055     public:
00056         Mutex() { rlog_mutex_init(&m_mutex); }
00057         ~Mutex() { rlog_mutex_destroy(&m_mutex); }
00058 
00059         void Lock() { rlog_mutex_lock(&m_mutex); }
00060         void Unlock() { rlog_mutex_unlock(&m_mutex); }
00061 
00062     private:
00063         rlog_mutex_t m_mutex;
00064 
00065         Mutex( const Mutex & );
00066         Mutex & operator = ( const Mutex & );
00067     };
00068 } 
00069 
00070 #endif // _Mutex_incl_
00071