~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to src/xmlrpcpp/XmlRpcMutex.cpp

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-06-07 11:28:52 UTC
  • Revision ID: package-import@ubuntu.com-20140607112852-v4d5tb1m3h3vi0dl
Tags: upstream-1.3.15
ImportĀ upstreamĀ versionĀ 1.3.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if defined(XMLRPC_THREADS)
 
2
 
 
3
#include "XmlRpcMutex.h"
 
4
 
 
5
#if defined(_WINDOWS)
 
6
# define WIN32_LEAN_AND_MEAN
 
7
# include <windows.h>
 
8
#else
 
9
# include <pthread.h>
 
10
#endif
 
11
 
 
12
using namespace XmlRpc;
 
13
 
 
14
 
 
15
//! Destructor.
 
16
XmlRpcMutex::~XmlRpcMutex()
 
17
{
 
18
  if (_pMutex)
 
19
  {
 
20
#if defined(_WINDOWS)
 
21
    ::CloseHandle((HANDLE)_pMutex);
 
22
#else
 
23
    ::pthread_mutex_destroy((pthread_mutex_t*)_pMutex);
 
24
    delete _pMutex;
 
25
#endif
 
26
    _pMutex = 0;
 
27
  }
 
28
}
 
29
 
 
30
//! Wait for the mutex to be available and then acquire the lock.
 
31
void XmlRpcMutex::acquire()
 
32
{
 
33
#if defined(_WINDOWS)
 
34
  if ( ! _pMutex)
 
35
    _pMutex = ::CreateMutex(0, TRUE, 0);
 
36
  else
 
37
    ::WaitForSingleObject(_pMutex, INFINITE);
 
38
#else
 
39
  if ( ! _pMutex)
 
40
  {
 
41
    _pMutex = new pthread_mutex_t;
 
42
    ::pthread_mutex_init((pthread_mutex_t*)_pMutex, 0);
 
43
  }
 
44
  ::pthread_mutex_lock((pthread_mutex_t*)_pMutex);
 
45
#endif
 
46
}
 
47
 
 
48
//! Release the mutex.
 
49
void XmlRpcMutex::release()
 
50
{
 
51
  if (_pMutex)
 
52
#if defined(_WINDOWS)
 
53
    ::ReleaseMutex(_pMutex);
 
54
#else
 
55
    ::pthread_mutex_unlock((pthread_mutex_t*)_pMutex);
 
56
#endif
 
57
}
 
58
 
 
59
#endif // XMLRPC_THREADS
 
60