source: cheroxy/trunk/src/CRXMutex.cpp@ 48

Last change on this file since 48 was 48, checked in by cheese, 11 years ago

#1 fix compilation error in linux on mutex constructor for windows

File size: 2.0 KB
Line 
1
2#include "CRXMutex.h"
3
4CRXMutex::CRXMutex (void)
5 : mIsCreated (false)
6{
7 /*----------------------------------------------------------------*/
8#ifdef _WIN32
9 mMutex = NULL;
10#endif
11 /*----------------------------------------------------------------*/
12}
13
14CRXMutex::~CRXMutex (void)
15{
16 /*----------------------------------------------------------------*/
17 this->Unlock ();
18 this->Destroy ();
19 /*----------------------------------------------------------------*/
20}
21
22bool
23CRXMutex::IsCreated (void) const
24{
25 /*----------------------------------------------------------------*/
26 /*----------------------------------------------------------------*/
27
28 return mIsCreated;
29}
30
31int
32CRXMutex::Create (void)
33{
34 int aResult = 0;
35
36 /*----------------------------------------------------------------*/
37#ifdef _WIN32
38 if ((mMutex = ::CreateMutexA (NULL, FALSE, NULL)) == NULL)
39 aResult = GetLastError ();
40#else
41 aResult = pthread_mutex_init (&mMutex, NULL);
42#endif
43
44 mIsCreated = true;
45 /*----------------------------------------------------------------*/
46
47 return aResult;
48}
49
50int
51CRXMutex::Destroy (void)
52{
53 int aResult = 0;
54
55 /*----------------------------------------------------------------*/
56#ifdef _WIN32
57 if (::CloseHandle (mMutex))
58 aResult = GetLastError ();
59#else
60 aResult = pthread_mutex_destroy (&mMutex);
61#endif
62
63 mIsCreated = false;
64 /*----------------------------------------------------------------*/
65
66 return aResult;
67}
68
69void
70CRXMutex::Lock (void)
71{
72 /*----------------------------------------------------------------*/
73#ifdef _WIN32
74 ::WaitForSingleObject (mMutex, INFINITE);
75#else
76 pthread_mutex_lock (&mMutex);
77#endif
78 /*----------------------------------------------------------------*/
79}
80
81void
82CRXMutex::Unlock (void)
83{
84 /*----------------------------------------------------------------*/
85#ifdef _WIN32
86 if (mMutex != NULL)
87 ::ReleaseMutex(mMutex);
88#else
89 pthread_mutex_unlock (&mMutex);
90#endif
91 /*----------------------------------------------------------------*/
92}
Note: See TracBrowser for help on using the repository browser.