Commit ee824e2a78753de9df4d715e2e014412cba5c3ff
1 parent
0133e202
Exists in
master
and in
5 other branches
Incluindo arquivo que faltava.
Showing
1 changed file
with
120 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,120 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como private.h e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | +#ifndef PRIVATE_H_INCLUDED | |
31 | + | |
32 | + #define PRIVATE_H_INCLUDED | |
33 | + | |
34 | + #include <cstring> | |
35 | + #include <pw3270/class.h> | |
36 | + | |
37 | + #if __cplusplus < 201103L | |
38 | + | |
39 | + #define nullptr NULL | |
40 | + | |
41 | + | |
42 | + #ifdef _WIN32 | |
43 | + | |
44 | + class recursive_mutex { | |
45 | + private: | |
46 | + HANDLE hMutex; | |
47 | + | |
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 | + }; | |
60 | + | |
61 | + void unlock(void) { | |
62 | + ReleaseMutex(hMutex); | |
63 | + }; | |
64 | + | |
65 | + bool try_lock(void) { | |
66 | + if(WaitForSingleObject(hMutex,1) == WAIT_OBJECT_0) | |
67 | + return true; | |
68 | + return false; | |
69 | + }; | |
70 | + }; | |
71 | + | |
72 | + #else | |
73 | + | |
74 | + class recursive_mutex { | |
75 | + private: | |
76 | + pthread_mutex_t mtx; | |
77 | + pthread_mutexattr_t mtxAttr; | |
78 | + | |
79 | + public: | |
80 | + recursive_mutex() { | |
81 | + | |
82 | + memset(&mtx,0,sizeof(mtx)); | |
83 | + memset(&mtxAttr,0,sizeof(mtxAttr)); | |
84 | + | |
85 | + pthread_mutexattr_init(&mtxAttr); | |
86 | + pthread_mutexattr_settype(&mtxAttr, PTHREAD_MUTEX_RECURSIVE); | |
87 | + pthread_mutex_init(&mtx, &mtxAttr); | |
88 | + }; | |
89 | + | |
90 | + ~recursive_mutex() { | |
91 | + pthread_mutex_destroy(&mtx); | |
92 | + }; | |
93 | + | |
94 | + void lock(void) { | |
95 | + pthread_mutex_lock(&mtx); | |
96 | + }; | |
97 | + | |
98 | + void unlock(void) { | |
99 | + pthread_mutex_unlock(&mtx); | |
100 | + }; | |
101 | + | |
102 | + bool try_lock(void) { | |
103 | + return pthread_mutex_trylock(&mtx) == 0; | |
104 | + }; | |
105 | + }; | |
106 | + | |
107 | + | |
108 | + | |
109 | + #endif // _WIN32 | |
110 | + | |
111 | + #else | |
112 | + | |
113 | + #include <recursive_mutex> | |
114 | + | |
115 | + #endif // !c11 | |
116 | + | |
117 | + | |
118 | + | |
119 | + | |
120 | +#endif // PRIVATE_H_INCLUDED | ... | ... |