Last change
on this file since 10 was 10, checked in by cheese, 12 years ago |
#1 add mutex class to trunk. threading module in branch will not be used.
|
File size:
906 bytes
|
Line | |
---|
1 |
|
---|
2 | #include "CRXMutex.h"
|
---|
3 |
|
---|
4 | CRXMutex::CRXMutex (void)
|
---|
5 | {
|
---|
6 | #ifdef _WIN32
|
---|
7 | mMutex = NULL;
|
---|
8 | #endif
|
---|
9 | }
|
---|
10 |
|
---|
11 | CRXMutex::~CRXMutex (void)
|
---|
12 | {
|
---|
13 | this->Unlock ();
|
---|
14 | this->Destroy ();
|
---|
15 | #ifdef _WIN32
|
---|
16 | #else
|
---|
17 | #endif
|
---|
18 | }
|
---|
19 |
|
---|
20 | int CRXMutex::Create (void)
|
---|
21 | {
|
---|
22 | #ifdef _WIN32
|
---|
23 | if ((mMutex = ::CreateMutexA (NULL, FALSE, NULL)) == NULL)
|
---|
24 | return GetLastError ();;
|
---|
25 | else
|
---|
26 | return 0;
|
---|
27 | #else
|
---|
28 | return pthread_mutex_init (&mMutex, NULL);
|
---|
29 | #endif
|
---|
30 | }
|
---|
31 |
|
---|
32 | int 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
|
---|
42 | }
|
---|
43 |
|
---|
44 | void CRXMutex::Lock (void)
|
---|
45 | {
|
---|
46 | #ifdef _WIN32
|
---|
47 | ::WaitForSingleObject (mMutex, INFINITE);
|
---|
48 | #else
|
---|
49 | pthread_mutex_lock (&mMutex);
|
---|
50 | #endif
|
---|
51 | }
|
---|
52 |
|
---|
53 | void 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.