gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r32865 - libmicrohttpd/src/include


From: gnunet
Subject: [GNUnet-SVN] r32865 - libmicrohttpd/src/include
Date: Tue, 1 Apr 2014 08:16:04 +0200

Author: Karlson2k
Date: 2014-04-01 08:16:04 +0200 (Tue, 01 Apr 2014)
New Revision: 32865

Modified:
   libmicrohttpd/src/include/platform.h
   libmicrohttpd/src/include/platform_interface.h
Log:
Implement wrapper macros for mutex manipulations, support W32 native mutex, 
require at least WinXP headers on W32

Modified: libmicrohttpd/src/include/platform.h
===================================================================
--- libmicrohttpd/src/include/platform.h        2014-04-01 00:16:59 UTC (rev 
32864)
+++ libmicrohttpd/src/include/platform.h        2014-04-01 06:16:04 UTC (rev 
32865)
@@ -51,6 +51,16 @@
 #define _LP64
 #endif
 
+#if defined(_WIN32)
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#else // _WIN32_WINNT
+#if _WIN32_WINNT < 0x0501
+#error "Headers for Windows XP or later are required"
+#endif // _WIN32_WINNT < 0x0501
+#endif // _WIN32_WINNT
+#endif // _WIN32
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>

Modified: libmicrohttpd/src/include/platform_interface.h
===================================================================
--- libmicrohttpd/src/include/platform_interface.h      2014-04-01 00:16:59 UTC 
(rev 32864)
+++ libmicrohttpd/src/include/platform_interface.h      2014-04-01 06:16:04 UTC 
(rev 32865)
@@ -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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]