00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __NEMUTEX_H
00028 #define __NEMUTEX_H
00029
00030
00031 #include "base.h"
00032
00033 #ifdef WIN32
00034 # ifndef WIN32_LEAN_AND_MEAN
00035 # define WIN32_LEAN_AND_MEAN
00036 # endif
00037 # ifndef NOGDI
00038 # define NOGDI
00039 # endif
00040 # include <windows.h>
00041 #elif defined(POSIX) || defined(__APPLE__)
00042 # include <pthread.h>
00043 #endif
00044
00045 #include <string>
00046
00047
00048 namespace NeoEngine
00049 {
00050
00051
00056 class NEOENGINE_API MutexObject
00057 {
00058 private:
00059
00060 #ifdef WIN32
00061
00063 HANDLE m_kMutex;
00064
00066 HANDLE m_kEvent;
00067
00068 #elif defined(POSIX) || defined(__APPLE__)
00069
00071 pthread_mutex_t m_kMutex;
00072
00074 pthread_cond_t m_kCond;
00075
00076 #endif
00077
00079 std::string m_strMutexName;
00080
00081
00082 public:
00083
00088 MutexObject( const std::string &rstrMutexName = "_noname" );
00089
00093 virtual ~MutexObject();
00094
00098 void Lock();
00099
00103 void Unlock();
00104
00108 void WaitForEvent();
00109
00113 void BroadcastEvent();
00114
00119 void SetName( const std::string &rstrName ) { Lock(); m_strMutexName = rstrName; Unlock(); }
00120 };
00121
00122
00123
00124
00145 class NEOENGINE_API MutexLock
00146 {
00147 private:
00148
00150 MutexObject *m_pkMutexObject;
00151
00152
00153 public:
00154
00159 MutexLock( MutexObject *pkMutexObject );
00160
00164 virtual ~MutexLock();
00165 };
00166
00167
00168 };
00169
00170
00171 #endif // __NEMUTEX_H