Changeset 38 in cheroxy for trunk/src/CRXMutex.cpp
- Timestamp:
- 11/21/12 09:23:50 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/CRXMutex.cpp
r12 r38 3 3 4 4 CRXMutex::CRXMutex (void) 5 : mIsCreated (false), 6 #ifdef _WIN32 7 mMutex (NULL) 8 #endif 5 9 { 6 #ifdef _WIN32 7 mMutex = NULL; 8 #endif 10 /*----------------------------------------------------------------*/ 11 /*----------------------------------------------------------------*/ 9 12 } 10 13 11 14 CRXMutex::~CRXMutex (void) 12 15 { 16 /*----------------------------------------------------------------*/ 13 17 this->Unlock (); 14 18 this->Destroy (); 15 #ifdef _WIN32 16 #else 17 #endif 19 /*----------------------------------------------------------------*/ 18 20 } 19 21 20 int CRXMutex::Create (void) 22 bool 23 CRXMutex::IsCreated (void) const 21 24 { 25 /*----------------------------------------------------------------*/ 26 /*----------------------------------------------------------------*/ 27 28 return mIsCreated; 29 } 30 31 int 32 CRXMutex::Create (void) 33 { 34 int aResult = 0; 35 36 /*----------------------------------------------------------------*/ 22 37 #ifdef _WIN32 23 38 if ((mMutex = ::CreateMutexA (NULL, FALSE, NULL)) == NULL) 24 return GetLastError (); 25 else 26 return 0; 39 aResult = GetLastError (); 27 40 #else 28 returnpthread_mutex_init (&mMutex, NULL);41 aResult = pthread_mutex_init (&mMutex, NULL); 29 42 #endif 43 44 mIsCreated = true; 45 /*----------------------------------------------------------------*/ 46 47 return aResult; 30 48 } 31 49 32 int CRXMutex::Destroy (void) 50 int 51 CRXMutex::Destroy (void) 33 52 { 53 int aResult = 0; 54 55 /*----------------------------------------------------------------*/ 34 56 #ifdef _WIN32 35 57 if (::CloseHandle (mMutex)) 36 return GetLastError (); 37 else 38 return 0; 58 aResult = GetLastError (); 39 59 #else 40 returnpthread_mutex_destroy (&mMutex);60 aResult = pthread_mutex_destroy (&mMutex); 41 61 #endif 62 63 mIsCreated = false; 64 /*----------------------------------------------------------------*/ 65 66 return aResult; 42 67 } 43 68 44 void CRXMutex::Lock (void) 69 void 70 CRXMutex::Lock (void) 45 71 { 72 /*----------------------------------------------------------------*/ 46 73 #ifdef _WIN32 47 74 ::WaitForSingleObject (mMutex, INFINITE); … … 49 76 pthread_mutex_lock (&mMutex); 50 77 #endif 78 /*----------------------------------------------------------------*/ 51 79 } 52 80 53 void CRXMutex::Unlock (void) 81 void 82 CRXMutex::Unlock (void) 54 83 { 84 /*----------------------------------------------------------------*/ 55 85 #ifdef _WIN32 56 86 if (mMutex != NULL) … … 59 89 pthread_mutex_unlock (&mMutex); 60 90 #endif 91 /*----------------------------------------------------------------*/ 61 92 }
Note:
See TracChangeset
for help on using the changeset viewer.