XmlRpcMutex.cc
Go to the documentation of this file.00001
00007 #if defined(XMLRPC_THREADS)
00008
00009 #include "XmlRpcMutex.h"
00010
00011 #if defined(_WINDOWS)
00012 # define WIN32_LEAN_AND_MEAN
00013 # include <windows.h>
00014 #else
00015 # include <pthread.h>
00016 #endif
00017
00018 using namespace XmlRpc;
00019
00020
00022 XmlRpcMutex::~XmlRpcMutex()
00023 {
00024 if (_pMutex)
00025 {
00026 #if defined(_WINDOWS)
00027 ::CloseHandle((HANDLE)_pMutex);
00028 #else
00029 ::pthread_mutex_destroy((pthread_mutex_t*)_pMutex);
00030 delete _pMutex;
00031 #endif
00032 _pMutex = 0;
00033 }
00034 }
00035
00037 void XmlRpcMutex::acquire()
00038 {
00039 #if defined(_WINDOWS)
00040 if ( ! _pMutex)
00041 _pMutex = ::CreateMutex(0, TRUE, 0);
00042 else
00043 ::WaitForSingleObject(_pMutex, INFINITE);
00044 #else
00045 if ( ! _pMutex)
00046 {
00047 _pMutex = new pthread_mutex_t;
00048 ::pthread_mutex_init((pthread_mutex_t*)_pMutex, 0);
00049 }
00050 ::pthread_mutex_lock((pthread_mutex_t*)_pMutex);
00051 #endif
00052 }
00053
00055 void XmlRpcMutex::release()
00056 {
00057 if (_pMutex)
00058 #if defined(_WINDOWS)
00059 ::ReleaseMutex(_pMutex);
00060 #else
00061 ::pthread_mutex_unlock((pthread_mutex_t*)_pMutex);
00062 #endif
00063 }
00064
00065 #endif // XMLRPC_THREADS
00066