UNCLASSIFIED

GeographicTranslator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
CCSThreadMutex.cpp
Go to the documentation of this file.
1 // CLASSIFICATION: UNCLASSIFIED
2 
3 #ifdef WIN32
4 # include <windows.h>
5 #endif
6 
7 #include "CCSThreadMutex.h"
8 
10 
11 CCSThreadMutex::CCSThreadMutex()
12 {
13 #ifdef WIN32
14  mutex = (void*)CreateMutex(NULL,FALSE,NULL);
15 #elif NDK_BUILD
16  // do nothing for Android
17 #else
18  // force a recursive mutex to match windows implementation.
19  pthread_mutexattr_t attr;
20  pthread_mutexattr_init(&attr);
21  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
22  pthread_mutex_init(&mutex, &attr);
23  pthread_mutexattr_destroy(&attr);
24 #endif
25 }
26 
28 {
29 #ifdef WIN32
30  CloseHandle((HANDLE)mutex);
31 #elif NDK_BUILD
32  // do nothing for Android
33 #else
34  // force a recursive mutex to match windows implementation.
35  pthread_mutex_destroy(&mutex);
36 #endif
37 }
38 void
40 {
41 #ifdef WIN32
42  WaitForSingleObject((HANDLE)mutex, INFINITE);
43 #elif NDK_BUILD
44  // do nothing for Android
45 #else
46  // force a recursive mutex to match windows implementation.
47  pthread_mutex_lock(&mutex);
48 #endif
49 }
50 
51 
52 void
54 {
55 #ifdef WIN32
56  ReleaseMutex((HANDLE)mutex);
57 #elif NDK_BUILD
58  // do nothing for Android
59 #else
60  // force a recursive mutex to match windows implementation.
61  pthread_mutex_unlock(&mutex);
62 #endif
63 }
64 
65 // CLASSIFICATION: UNCLASSIFIED