00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __JackWinMutex__
00022 #define __JackWinMutex__
00023
00024 #include "JackCompilerDeps.h"
00025 #include "JackException.h"
00026 #include <windows.h>
00027 #include <stdio.h>
00028
00029 namespace Jack
00030 {
00031
00035 class SERVER_EXPORT JackBaseWinMutex
00036 {
00037
00038 protected:
00039
00040 HANDLE fMutex;
00041 DWORD fOwner;
00042
00043 public:
00044
00045 JackBaseWinMutex():fOwner(0)
00046 {
00047
00048 fMutex = CreateMutex(NULL, FALSE, NULL);
00049 ThrowIf((fMutex == 0), JackException("JackBaseWinMutex: could not init the mutex"));
00050 }
00051
00052 virtual ~JackBaseWinMutex()
00053 {
00054 CloseHandle(fMutex);
00055 }
00056
00057 bool Lock();
00058 bool Trylock();
00059 bool Unlock();
00060
00061 };
00062
00063 class SERVER_EXPORT JackWinMutex
00064 {
00065
00066 protected:
00067
00068 HANDLE fMutex;
00069
00070 public:
00071
00072 JackWinMutex(const char* name = NULL)
00073 {
00074
00075 if (name) {
00076 char buffer[MAX_PATH];
00077 snprintf(buffer, sizeof(buffer), "%s_%s", "JackWinMutex", name);
00078 fMutex = CreateMutex(NULL, FALSE, buffer);
00079 } else {
00080 fMutex = CreateMutex(NULL, FALSE, NULL);
00081 }
00082
00083 ThrowIf((fMutex == 0), JackException("JackWinMutex: could not init the mutex"));
00084 }
00085
00086 virtual ~JackWinMutex()
00087 {
00088 CloseHandle(fMutex);
00089 }
00090
00091 bool Lock();
00092 bool Trylock();
00093 bool Unlock();
00094
00095 };
00096
00097 class SERVER_EXPORT JackWinCriticalSection
00098 {
00099
00100 protected:
00101
00102 CRITICAL_SECTION fSection;
00103
00104 public:
00105
00106 JackWinCriticalSection(const char* name = NULL)
00107 {
00108 InitializeCriticalSection(&fSection);
00109 }
00110
00111 virtual ~JackWinCriticalSection()
00112 {
00113 DeleteCriticalSection(&fSection);
00114 }
00115
00116 bool Lock();
00117 bool Trylock();
00118 bool Unlock();
00119
00120 };
00121
00122
00123 }
00124
00125 #endif
00126