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