Commit 93d83286a4e801ad30132972cfe183a9eabf2c9c

Authored by Perry Werneck
1 parent e4ef72e3

Ajustes para eliminar problemas que apareceram na atualização do gcc para windows.

Showing 1 changed file with 48 additions and 55 deletions   Show diff stats
src/classlib/private.h
@@ -34,79 +34,72 @@ @@ -34,79 +34,72 @@
34 #include <cstring> 34 #include <cstring>
35 #include <pw3270/class.h> 35 #include <pw3270/class.h>
36 36
37 - #if __cplusplus < 201103L 37 + #if defined(_WIN32)
38 38
39 - #define nullptr NULL  
40 -  
41 -  
42 - #ifdef _WIN32  
43 -  
44 - class recursive_mutex {  
45 - private:  
46 - HANDLE hMutex; 39 + class recursive_mutex {
  40 + private:
  41 + HANDLE hMutex;
47 42
48 - public:  
49 - recursive_mutex() {  
50 - hMutex = CreateMutex(NULL,FALSE,NULL);  
51 - };  
52 -  
53 - ~recursive_mutex() {  
54 - CloseHandle(hMutex);  
55 - };  
56 -  
57 - void lock(void) {  
58 - WaitForSingleObject(hMutex,INFINITE);  
59 - }; 43 + public:
  44 + recursive_mutex() {
  45 + hMutex = CreateMutex(NULL,FALSE,NULL);
  46 + };
60 47
61 - void unlock(void) {  
62 - ReleaseMutex(hMutex);  
63 - }; 48 + ~recursive_mutex() {
  49 + CloseHandle(hMutex);
  50 + };
64 51
65 - bool try_lock(void) {  
66 - if(WaitForSingleObject(hMutex,1) == WAIT_OBJECT_0)  
67 - return true;  
68 - return false;  
69 - }; 52 + void lock(void) {
  53 + WaitForSingleObject(hMutex,INFINITE);
70 }; 54 };
71 55
72 - #else 56 + void unlock(void) {
  57 + ReleaseMutex(hMutex);
  58 + };
73 59
74 - class recursive_mutex {  
75 - private:  
76 - pthread_mutex_t mtx;  
77 - pthread_mutexattr_t mtxAttr; 60 + bool try_lock(void) {
  61 + if(WaitForSingleObject(hMutex,1) == WAIT_OBJECT_0)
  62 + return true;
  63 + return false;
  64 + };
  65 + };
78 66
79 - public:  
80 - recursive_mutex() { 67 + #elif __cplusplus < 201103L
81 68
82 - memset(&mtx,0,sizeof(mtx));  
83 - memset(&mtxAttr,0,sizeof(mtxAttr)); 69 + #define nullptr NULL
84 70
85 - pthread_mutexattr_init(&mtxAttr);  
86 - pthread_mutexattr_settype(&mtxAttr, PTHREAD_MUTEX_RECURSIVE);  
87 - pthread_mutex_init(&mtx, &mtxAttr);  
88 - }; 71 + class recursive_mutex {
  72 + private:
  73 + pthread_mutex_t mtx;
  74 + pthread_mutexattr_t mtxAttr;
89 75
90 - ~recursive_mutex() {  
91 - pthread_mutex_destroy(&mtx);  
92 - }; 76 + public:
  77 + recursive_mutex() {
93 78
94 - void lock(void) {  
95 - pthread_mutex_lock(&mtx);  
96 - }; 79 + memset(&mtx,0,sizeof(mtx));
  80 + memset(&mtxAttr,0,sizeof(mtxAttr));
97 81
98 - void unlock(void) {  
99 - pthread_mutex_unlock(&mtx);  
100 - }; 82 + pthread_mutexattr_init(&mtxAttr);
  83 + pthread_mutexattr_settype(&mtxAttr, PTHREAD_MUTEX_RECURSIVE);
  84 + pthread_mutex_init(&mtx, &mtxAttr);
  85 + };
101 86
102 - bool try_lock(void) {  
103 - return pthread_mutex_trylock(&mtx) == 0;  
104 - }; 87 + ~recursive_mutex() {
  88 + pthread_mutex_destroy(&mtx);
105 }; 89 };
106 90
  91 + void lock(void) {
  92 + pthread_mutex_lock(&mtx);
  93 + };
107 94
  95 + void unlock(void) {
  96 + pthread_mutex_unlock(&mtx);
  97 + };
108 98
109 - #endif // _WIN32 99 + bool try_lock(void) {
  100 + return pthread_mutex_trylock(&mtx) == 0;
  101 + };
  102 + };
110 103
111 #else 104 #else
112 105