diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-08-10 13:52:51 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-08-10 13:52:51 +0000 |
commit | 40b07cc6451ce9b0c36f353385b777c4ebfcb138 (patch) | |
tree | 1c2262c387dd01c6672f51628b8a0c74cae18199 /src/include/platform_interface.h | |
parent | a7029c10cccdf2b0d4597eb79fb58d2f11d167f1 (diff) | |
download | libmicrohttpd-40b07cc6451ce9b0c36f353385b777c4ebfcb138.tar.gz libmicrohttpd-40b07cc6451ce9b0c36f353385b777c4ebfcb138.zip |
Moved locks and mutex abstraction to mhd_locks.h
Minor refactoring to allow better code optimization.
Diffstat (limited to 'src/include/platform_interface.h')
-rw-r--r-- | src/include/platform_interface.h | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/src/include/platform_interface.h b/src/include/platform_interface.h index 13f54530..c2aee64b 100644 --- a/src/include/platform_interface.h +++ b/src/include/platform_interface.h | |||
@@ -189,113 +189,5 @@ typedef int _MHD_socket_funcs_size; | |||
189 | #else | 189 | #else |
190 | #define MHD_random_() MHD_W32_random_() | 190 | #define MHD_random_() MHD_W32_random_() |
191 | #endif | 191 | #endif |
192 | #if defined(MHD_USE_W32_THREADS) | ||
193 | #define MHD_W32_MUTEX_ 1 | ||
194 | #include <windows.h> | ||
195 | typedef CRITICAL_SECTION MHD_mutex_; | ||
196 | #elif defined(HAVE_PTHREAD_H) && defined(MHD_USE_POSIX_THREADS) | ||
197 | #define MHD_PTHREAD_MUTEX_ 1 | ||
198 | typedef pthread_mutex_t MHD_mutex_; | ||
199 | #else | ||
200 | #error "No base mutex API is available." | ||
201 | #endif | ||
202 | |||
203 | #if defined(MHD_PTHREAD_MUTEX_) | ||
204 | /** | ||
205 | * Create new mutex. | ||
206 | * @param mutex pointer to the mutex | ||
207 | * @return #MHD_YES on success, #MHD_NO on failure | ||
208 | */ | ||
209 | #define MHD_mutex_create_(mutex) \ | ||
210 | ((0 == pthread_mutex_init ((mutex), NULL)) ? MHD_YES : MHD_NO) | ||
211 | #elif defined(MHD_W32_MUTEX_) | ||
212 | /** | ||
213 | * Create new mutex. | ||
214 | * @param mutex pointer to mutex | ||
215 | * @return #MHD_YES on success, #MHD_NO on failure | ||
216 | */ | ||
217 | #define MHD_mutex_create_(mutex) \ | ||
218 | ((NULL != (mutex) && 0 != InitializeCriticalSectionAndSpinCount((mutex),2000)) ? MHD_YES : MHD_NO) | ||
219 | #endif | ||
220 | |||
221 | #if defined(MHD_PTHREAD_MUTEX_) | ||
222 | /** | ||
223 | * Destroy previously created mutex. | ||
224 | * @param mutex pointer to mutex | ||
225 | * @return #MHD_YES on success, #MHD_NO on failure | ||
226 | */ | ||
227 | #define MHD_mutex_destroy_(mutex) \ | ||
228 | ((0 == pthread_mutex_destroy ((mutex))) ? MHD_YES : MHD_NO) | ||
229 | #elif defined(MHD_W32_MUTEX_) | ||
230 | /** | ||
231 | * Destroy previously created mutex. | ||
232 | * @param mutex pointer to mutex | ||
233 | * @return #MHD_YES on success, #MHD_NO on failure | ||
234 | */ | ||
235 | #define MHD_mutex_destroy_(mutex) \ | ||
236 | ((NULL != (mutex)) ? (DeleteCriticalSection(mutex), MHD_YES) : MHD_NO) | ||
237 | #endif | ||
238 | |||
239 | #if defined(MHD_PTHREAD_MUTEX_) | ||
240 | /** | ||
241 | * Acquire lock on previously created mutex. | ||
242 | * If mutex was already locked by other thread, function | ||
243 | * blocks until mutex becomes available. | ||
244 | * @param mutex pointer to mutex | ||
245 | * @return #MHD_YES on success, #MHD_NO on failure | ||
246 | */ | ||
247 | #define MHD_mutex_lock_(mutex) \ | ||
248 | ((0 == pthread_mutex_lock((mutex))) ? MHD_YES : MHD_NO) | ||
249 | #elif defined(MHD_W32_MUTEX_) | ||
250 | /** | ||
251 | * Acquire lock on previously created mutex. | ||
252 | * If mutex was already locked by other thread, function | ||
253 | * blocks until mutex becomes available. | ||
254 | * @param mutex pointer to mutex | ||
255 | * @return #MHD_YES on success, #MHD_NO on failure | ||
256 | */ | ||
257 | #define MHD_mutex_lock_(mutex) \ | ||
258 | ((NULL != (mutex)) ? (EnterCriticalSection((mutex)), MHD_YES) : MHD_NO) | ||
259 | #endif | ||
260 | |||
261 | #if defined(MHD_PTHREAD_MUTEX_) | ||
262 | /** | ||
263 | * Try to acquire lock on previously created mutex. | ||
264 | * Function returns immediately. | ||
265 | * @param mutex pointer to mutex | ||
266 | * @return #MHD_YES if mutex is locked, #MHD_NO if | ||
267 | * mutex was not locked. | ||
268 | */ | ||
269 | #define MHD_mutex_trylock_(mutex) \ | ||
270 | ((0 == pthread_mutex_trylock((mutex))) ? MHD_YES : MHD_NO) | ||
271 | #elif defined(MHD_W32_MUTEX_) | ||
272 | /** | ||
273 | * Try to acquire lock on previously created mutex. | ||
274 | * Function returns immediately. | ||
275 | * @param mutex pointer to mutex | ||
276 | * @return #MHD_YES if mutex is locked, #MHD_NO if | ||
277 | * mutex was not locked. | ||
278 | */ | ||
279 | #define MHD_mutex_trylock_(mutex) \ | ||
280 | ((NULL != (mutex) && 0 != TryEnterCriticalSection ((mutex))) ? MHD_YES : MHD_NO) | ||
281 | #endif | ||
282 | |||
283 | #if defined(MHD_PTHREAD_MUTEX_) | ||
284 | /** | ||
285 | * Unlock previously created and locked mutex. | ||
286 | * @param mutex pointer to mutex | ||
287 | * @return #MHD_YES on success, #MHD_NO on failure | ||
288 | */ | ||
289 | #define MHD_mutex_unlock_(mutex) \ | ||
290 | ((0 == pthread_mutex_unlock((mutex))) ? MHD_YES : MHD_NO) | ||
291 | #elif defined(MHD_W32_MUTEX_) | ||
292 | /** | ||
293 | * Unlock previously created and locked mutex. | ||
294 | * @param mutex pointer to mutex | ||
295 | * @return #MHD_YES on success, #MHD_NO on failure | ||
296 | */ | ||
297 | #define MHD_mutex_unlock_(mutex) \ | ||
298 | ((NULL != (mutex)) ? (LeaveCriticalSection((mutex)), MHD_YES) : MHD_NO) | ||
299 | #endif | ||
300 | 192 | ||
301 | #endif /* MHD_PLATFORM_INTERFACE_H */ | 193 | #endif /* MHD_PLATFORM_INTERFACE_H */ |