OverSim
XmlRpcMutex.cc
Go to the documentation of this file.
1 
7 #if defined(XMLRPC_THREADS)
8 
9 #include "XmlRpcMutex.h"
10 
11 #if defined(_WINDOWS)
12 # define WIN32_LEAN_AND_MEAN
13 # include <windows.h>
14 #else
15 # include <pthread.h>
16 #endif
17 
18 using namespace XmlRpc;
19 
20 
23 {
24  if (_pMutex)
25  {
26 #if defined(_WINDOWS)
27  ::CloseHandle((HANDLE)_pMutex);
28 #else
29  ::pthread_mutex_destroy((pthread_mutex_t*)_pMutex);
30  delete _pMutex;
31 #endif
32  _pMutex = 0;
33  }
34 }
35 
38 {
39 #if defined(_WINDOWS)
40  if ( ! _pMutex)
41  _pMutex = ::CreateMutex(0, TRUE, 0);
42  else
43  ::WaitForSingleObject(_pMutex, INFINITE);
44 #else
45  if ( ! _pMutex)
46  {
47  _pMutex = new pthread_mutex_t;
48  ::pthread_mutex_init((pthread_mutex_t*)_pMutex, 0);
49  }
50  ::pthread_mutex_lock((pthread_mutex_t*)_pMutex);
51 #endif
52 }
53 
56 {
57  if (_pMutex)
58 #if defined(_WINDOWS)
59  ::ReleaseMutex(_pMutex);
60 #else
61  ::pthread_mutex_unlock((pthread_mutex_t*)_pMutex);
62 #endif
63 }
64 
65 #endif // XMLRPC_THREADS
66