00001
00002
00003 #ifndef _WINLOCK_H_
00004 #define _WINLOCK_H_
00005
00006 #if defined(_WIN32)
00007
00008 #include <windows.h>
00009
00018 #if 1
00019
00020 namespace HL {
00021
00022 class WinLockType {
00023 public:
00024
00025 WinLockType (void)
00026 : mutex (0)
00027 {}
00028
00029 ~WinLockType (void)
00030 {
00031 mutex = 0;
00032 }
00033
00034 inline void lock (void) {
00035 #if 1
00036
00037 while (InterlockedExchange ((long *) &mutex, 1) != 0)
00038 Sleep (0);
00039 #endif
00040 }
00041
00042 inline void unlock (void) {
00043 mutex = 0;
00044
00045 }
00046
00047 private:
00048 unsigned int mutex;
00049 bool onMultiprocessor (void) {
00050 SYSTEM_INFO infoReturn[1];
00051 GetSystemInfo (infoReturn);
00052 if (infoReturn->dwNumberOfProcessors == 1) {
00053 return FALSE;
00054 } else {
00055 return TRUE;
00056 }
00057 }
00058 };
00059
00060 };
00061
00062 #else
00063
00064 #include <windows.h>
00065
00066 class WinLockType {
00067 public:
00068
00069 WinLockType (void)
00070 {
00071 InitializeCriticalSection(&mutex);
00072 }
00073
00074 ~WinLockType (void)
00075 {
00076 DeleteCriticalSection(&mutex);
00077 }
00078
00079 inline void lock (void) {
00080 EnterCriticalSection(&mutex);
00081 }
00082
00083 inline void unlock (void) {
00084 LeaveCriticalSection(&mutex);
00085 }
00086
00087 private:
00088 CRITICAL_SECTION mutex;
00089 };
00090
00091 #endif
00092
00093 #endif
00094
00095 #endif