Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_mutex-win32.h
Go to the documentation of this file.
1
33#ifdef __MINGW32__
34# define _RWSTD_CRITICAL_SECTION _CRITICAL_SECTION
35#else
36# define _RWSTD_CRITICAL_SECTION _RTL_CRITICAL_SECTION
37#endif
38
39#ifdef _RWSTD_NO_FWD_DECLARATIONS
40
41 // #including <windows.h> without WIN32_LEAN_AND_MEAN macro defined
42 // may cause an errors "WinSock.h has already been included"
43 // when <winsock2.h> has been included after this header
44# include <windows.h>
45# define _RWSTD_MUTEX_T _RWSTD_CRITICAL_SECTION
46
47#else // if !defined (_RWSTD_NO_FWD_DECLARATIONS)
48
49 // avoid #including this header (MFC doesn't like it)
50 // # include <windows.h>
51
52extern "C" {
53
54// but rather declare these globals here
56
57__declspec (dllimport) void __stdcall
58InitializeCriticalSection (_RWSTD_CRITICAL_SECTION*);
59
60__declspec (dllimport) void __stdcall
61EnterCriticalSection (_RWSTD_CRITICAL_SECTION*);
62
63__declspec (dllimport) void __stdcall
64LeaveCriticalSection (_RWSTD_CRITICAL_SECTION*);
65
66__declspec (dllimport) void __stdcall
67DeleteCriticalSection (_RWSTD_CRITICAL_SECTION*);
68
69} // extern "C"
70
72
73// fake critical section type
74union __rw_critical_section {
75 long _C_pad; // force alignment
76
77# ifndef _WIN64
78 char _C_buf [24 /* == sizeof (_RTL_CRITICAL_SECTION) */];
79# else // #ifdef _WIN64
80 char _C_buf [40 /* == sizeof (_RTL_CRITICAL_SECTION) */];
81# endif // _WIN64
82};
83
84# define _RWSTD_MUTEX_T _RW::__rw_critical_section
85
86} // namespace __rw
87
88#endif // _RWSTD_NO_FWD_DECLARATIONS
89
90
92
93#ifndef _MSC_VER
94# define __try if (1)
95# define __except(ignore) else if (0)
96#endif // _MSC_VER
97
98// Win32/64 throws non-C++ exceptions rather than returning error status
99// from some system calls like most other operating systems do
100
101inline int __rw_mutex_init (_RWSTD_CRITICAL_SECTION *__mutex)
102{
103 __try {
104 InitializeCriticalSection (__mutex);
105 }
106 __except (1) {
107 return -1;
108 }
109 return 0;
110}
111
112inline int __rw_mutex_destroy (_RWSTD_CRITICAL_SECTION *__mutex)
113{
114 __try {
115 DeleteCriticalSection (__mutex);
116 }
117 __except (1) {
118 return -1;
119 }
120 return 0;
121}
122
123inline int __rw_mutex_lock (_RWSTD_CRITICAL_SECTION *__mutex)
124{
125 __try {
126 EnterCriticalSection (__mutex);
127 }
128 __except (1) {
129 return -1;
130 }
131 return 0;
132}
133
134inline int __rw_mutex_unlock (_RWSTD_CRITICAL_SECTION *__mutex)
135{
136 __try {
137 LeaveCriticalSection (__mutex);
138 }
139 __except (1) {
140 return -1;
141 }
142 return 0;
143}
144
145#define _RWSTD_MUTEX_INIT(mutex) \
146 __rw_mutex_init (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
147#define _RWSTD_MUTEX_DESTROY(mutex) \
148 __rw_mutex_destroy (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
149#define _RWSTD_MUTEX_LOCK(mutex) \
150 __rw_mutex_lock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
151#define _RWSTD_MUTEX_UNLOCK(mutex) \
152 __rw_mutex_unlock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
153
154#ifndef _MSC_VER
155# undef __try
156# undef __except
157#endif // _MSC_VER
158
159} // namespace __rw
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define __try
__declspec(dllimport) void __stdcall InitializeCriticalSection(_RWSTD_CRITICAL_SECTION *)
#define __except(ignore)
#define _RWSTD_CRITICAL_SECTION