|
|
@@ -18,7 +18,7 @@
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * @file platform/platfrom_interface.h
|
|
|
+ * @file include/platfrom_interface.h
|
|
|
* @brief internal platform abstraction functions
|
|
|
* @author Karlson2k (Evgeny Grin)
|
|
|
*/
|
|
|
@@ -139,4 +139,114 @@
|
|
|
#define MHD_random_() MHD_W32_random_()
|
|
|
#endif
|
|
|
|
|
|
+#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_;
|
|
|
+#elif defined(HAVE_PTHREAD_H)
|
|
|
+#define MHD_PTHREAD_MUTEX_ 1
|
|
|
+typedef pthread_mutex_t MHD_mutex_;
|
|
|
+#else
|
|
|
+#error "No base mutex API is available."
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(MHD_PTHREAD_MUTEX_)
|
|
|
+/**
|
|
|
+ * Create new mutex.
|
|
|
+ * @param mutex pointer to the mutex
|
|
|
+ * @return #MHD_YES on success, #MHD_NO on failure
|
|
|
+ */
|
|
|
+#define MHD_mutex_create_(mutex) \
|
|
|
+ ((0 == pthread_mutex_init ((mutex), NULL)) ? MHD_YES : MHD_NO)
|
|
|
+#elif defined(MHD_W32_MUTEX_)
|
|
|
+/**
|
|
|
+ * Create new mutex.
|
|
|
+ * @param mutex pointer to 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)
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(MHD_PTHREAD_MUTEX_)
|
|
|
+/**
|
|
|
+ * Destroy previously created mutex.
|
|
|
+ * @param mutex pointer to mutex
|
|
|
+ * @return #MHD_YES on success, #MHD_NO on failure
|
|
|
+ */
|
|
|
+#define MHD_mutex_destroy_(mutex) \
|
|
|
+ ((0 == pthread_mutex_destroy ((mutex), NULL)) ? MHD_YES : MHD_NO)
|
|
|
+#elif defined(MHD_W32_MUTEX_)
|
|
|
+/**
|
|
|
+ * Destroy previously created mutex.
|
|
|
+ * @param mutex pointer to 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)
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(MHD_PTHREAD_MUTEX_)
|
|
|
+/**
|
|
|
+ * Acquire lock on previously created mutex.
|
|
|
+ * If mutex was already locked by other thread, function
|
|
|
+ * blocks until mutex becomes available.
|
|
|
+ * @param mutex pointer to mutex
|
|
|
+ * @return #MHD_YES on success, #MHD_NO on failure
|
|
|
+ */
|
|
|
+#define MHD_mutex_lock_(mutex) \
|
|
|
+ ((0 == pthread_mutex_lock((mutex), NULL)) ? MHD_YES : MHD_NO)
|
|
|
+#elif defined(MHD_W32_MUTEX_)
|
|
|
+/**
|
|
|
+ * Acquire lock on previously created mutex.
|
|
|
+ * If mutex was already locked by other thread, function
|
|
|
+ * blocks until mutex becomes available.
|
|
|
+ * @param mutex pointer to 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)
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(MHD_PTHREAD_MUTEX_)
|
|
|
+/**
|
|
|
+ * Try to acquire lock on previously created mutex.
|
|
|
+ * Function returns immediately.
|
|
|
+ * @param mutex pointer to mutex
|
|
|
+ * @return #MHD_YES if mutex is locked, #MHD_NO if
|
|
|
+ * mutex was not locked.
|
|
|
+ */
|
|
|
+#define MHD_mutex_trylock_(mutex) \
|
|
|
+ ((0 == pthread_mutex_trylock((mutex), NULL)) ? MHD_YES : MHD_NO)
|
|
|
+#elif defined(MHD_W32_MUTEX_)
|
|
|
+/**
|
|
|
+ * Try to acquire lock on previously created mutex.
|
|
|
+ * Function returns immediately.
|
|
|
+ * @param mutex pointer to mutex
|
|
|
+ * @return #MHD_YES if mutex is locked, #MHD_NO if
|
|
|
+ * mutex was not locked.
|
|
|
+ */
|
|
|
+#define MHD_mutex_trylock_(mutex) \
|
|
|
+ ((NULL != (mutex) && WAIT_OBJECT_0 == WaitForSingleObject(*(mutex), 0)) ? MHD_YES : MHD_NO)
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(MHD_PTHREAD_MUTEX_)
|
|
|
+/**
|
|
|
+ * Unlock previously created and locked mutex.
|
|
|
+ * @param mutex pointer to mutex
|
|
|
+ * @return #MHD_YES on success, #MHD_NO on failure
|
|
|
+ */
|
|
|
+#define MHD_mutex_unlock_(mutex) \
|
|
|
+ ((0 == pthread_mutex_unlock((mutex), NULL)) ? MHD_YES : MHD_NO)
|
|
|
+#elif defined(MHD_W32_MUTEX_)
|
|
|
+/**
|
|
|
+ * Unlock previously created and locked mutex.
|
|
|
+ * @param mutex pointer to mutex
|
|
|
+ * @return #MHD_YES on success, #MHD_NO on failure
|
|
|
+ */
|
|
|
+#define MHD_mutex_unlock_(mutex) \
|
|
|
+ ((NULL != (mutex) && 0 != ReleaseMutex(*(mutex))) ? MHD_YES : MHD_NO)
|
|
|
+#endif
|
|
|
+
|
|
|
#endif // MHD_PLATFORM_INTERFACE_H
|