source: cheroxy/branches/b0_1_threading/src/CRXMutex.cpp@ 13

Last change on this file since 13 was 13, checked in by cheese, 12 years ago

#1 fix branch code typos

File size: 905 bytes
RevLine 
[7]1
2#include "CRXMutex.h"
3
4CRXMutex::CRXMutex (void)
5{
6#ifdef _WIN32
7 mMutex = NULL;
8#endif
9}
10
11CRXMutex::~CRXMutex (void)
12{
13 this->Unlock ();
[8]14 this->Destroy ();
[7]15#ifdef _WIN32
16#else
17#endif
18}
19
[8]20int CRXMutex::Create (void)
[7]21{
22#ifdef _WIN32
[8]23 if ((mMutex = ::CreateMutexA (NULL, FALSE, NULL)) == NULL)
[13]24 return GetLastError ();
[8]25 else
26 return 0;
[7]27#else
[8]28 return pthread_mutex_init (&mMutex, NULL);
[7]29#endif
[8]30}
[7]31
[8]32int CRXMutex::Destroy (void)
33{
34#ifdef _WIN32
35 if (::CloseHandle (mMutex))
36 return GetLastError ();
37 else
38 return 0;
39#else
40 return pthread_mutex_destroy (&mMutex);
41#endif
[7]42}
43
44void CRXMutex::Lock (void)
45{
46#ifdef _WIN32
47 ::WaitForSingleObject (mMutex, INFINITE);
48#else
49 pthread_mutex_lock (&mMutex);
50#endif
51}
52
53void CRXMutex::Unlock (void)
54{
55#ifdef _WIN32
56 if (mMutex != NULL)
57 ::ReleaseMutex(mMutex);
58#else
59 pthread_mutex_unlock (&mMutex);
60#endif
61}
Note: See TracBrowser for help on using the repository browser.