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 | #ifdef _WIN32
|
---|
15 | #else
|
---|
16 | #endif
|
---|
17 | }
|
---|
18 |
|
---|
19 | int CRXMutex::Create ()
|
---|
20 | {
|
---|
21 | #ifdef _WIN32
|
---|
22 | if ((mMutex = ::CreateMutexA(NULL, FALSE, NULL)) == NULL)
|
---|
23 | return -1;
|
---|
24 | #else
|
---|
25 | pthread_mutex_init (&mMutex, NULL);
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | return 0;
|
---|
29 | }
|
---|
30 |
|
---|
31 | void CRXMutex::Lock (void)
|
---|
32 | {
|
---|
33 | #ifdef _WIN32
|
---|
34 | ::WaitForSingleObject (mMutex, INFINITE);
|
---|
35 | #else
|
---|
36 | pthread_mutex_lock (&mMutex);
|
---|
37 | #endif
|
---|
38 | }
|
---|
39 |
|
---|
40 | void CRXMutex::Unlock (void)
|
---|
41 | {
|
---|
42 | #ifdef _WIN32
|
---|
43 | if (mMutex != NULL)
|
---|
44 | ::ReleaseMutex(mMutex);
|
---|
45 | #else
|
---|
46 | pthread_mutex_unlock (&mMutex);
|
---|
47 | #endif
|
---|
48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.