commit 30da663666aa92463665967c21b80f85521a05d2
parent 96a5541b5f603db3554a8b0dc86cf7ce1e4a4027
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Fri, 4 Apr 2014 11:19:41 +0000
W32: use critical section instead of waitable object as MHD require synchronization only within one process
Diffstat:
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/include/platform.h b/src/include/platform.h
@@ -59,6 +59,9 @@
#error "Headers for Windows XP or later are required"
#endif // _WIN32_WINNT < 0x0501
#endif // _WIN32_WINNT
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif /* !WIN32_LEAN_AND_MEAN */
#endif // _WIN32
#include <stdio.h>
diff --git a/src/include/platform_interface.h b/src/include/platform_interface.h
@@ -141,9 +141,8 @@
#if defined(_WIN32) && !defined(__CYGWIN__)
#define MHD_W32_MUTEX_ 1
-/* 'void*' is the same as 'HANDLE'
- * this way allow typedef without including "windows.h" */
-typedef void* MHD_mutex_;
+#include <windows.h>
+typedef CRITICAL_SECTION MHD_mutex_;
#elif defined(HAVE_PTHREAD_H)
#define MHD_PTHREAD_MUTEX_ 1
typedef pthread_mutex_t MHD_mutex_;
@@ -166,7 +165,7 @@ typedef pthread_mutex_t MHD_mutex_;
* @return #MHD_YES on success, #MHD_NO on failure
*/
#define MHD_mutex_create_(mutex) \
- ((NULL != (mutex) && NULL != (*(mutex) = CreateMutex(NULL, FALSE, NULL))) ? MHD_YES : MHD_NO)
+ ((NULL != (mutex) && 0 != InitializeCriticalSectionAndSpinCount((mutex),2000)) ? MHD_YES : MHD_NO)
#endif
#if defined(MHD_PTHREAD_MUTEX_)
@@ -184,7 +183,7 @@ typedef pthread_mutex_t MHD_mutex_;
* @return #MHD_YES on success, #MHD_NO on failure
*/
#define MHD_mutex_destroy_(mutex) \
- ((NULL != (mutex) && 0 != CloseHandle(*(mutex)) && NULL == (*(mutex) = NULL)) ? MHD_YES : MHD_NO)
+ ((NULL != (mutex)) ? (DeleteCriticalSection(mutex), MHD_YES) : MHD_NO)
#endif
#if defined(MHD_PTHREAD_MUTEX_)
@@ -206,7 +205,7 @@ typedef pthread_mutex_t MHD_mutex_;
* @return #MHD_YES on success, #MHD_NO on failure
*/
#define MHD_mutex_lock_(mutex) \
- ((NULL != (mutex) && WAIT_OBJECT_0 == WaitForSingleObject(*(mutex), INFINITE)) ? MHD_YES : MHD_NO)
+ ((NULL != (mutex)) ? (EnterCriticalSection((mutex)), MHD_YES) : MHD_NO)
#endif
#if defined(MHD_PTHREAD_MUTEX_)
@@ -228,7 +227,7 @@ typedef pthread_mutex_t MHD_mutex_;
* mutex was not locked.
*/
#define MHD_mutex_trylock_(mutex) \
- ((NULL != (mutex) && WAIT_OBJECT_0 == WaitForSingleObject(*(mutex), 0)) ? MHD_YES : MHD_NO)
+ ((NULL != (mutex) && 0 != TryEnterCriticalSection ((mutex))) ? MHD_YES : MHD_NO)
#endif
#if defined(MHD_PTHREAD_MUTEX_)
@@ -246,7 +245,7 @@ typedef pthread_mutex_t MHD_mutex_;
* @return #MHD_YES on success, #MHD_NO on failure
*/
#define MHD_mutex_unlock_(mutex) \
- ((NULL != (mutex) && 0 != ReleaseMutex(*(mutex))) ? MHD_YES : MHD_NO)
+ ((NULL != (mutex)) ? (LeaveCriticalSection((mutex)), MHD_YES) : MHD_NO)
#endif
#endif // MHD_PLATFORM_INTERFACE_H