gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37688 - in libmicrohttpd: src/include src/microhttpd w32/c


From: gnunet
Subject: [GNUnet-SVN] r37688 - in libmicrohttpd: src/include src/microhttpd w32/common
Date: Wed, 10 Aug 2016 15:52:51 +0200

Author: Karlson2k
Date: 2016-08-10 15:52:51 +0200 (Wed, 10 Aug 2016)
New Revision: 37688

Added:
   libmicrohttpd/src/microhttpd/mhd_locks.h
Modified:
   libmicrohttpd/src/include/platform_interface.h
   libmicrohttpd/src/microhttpd/Makefile.am
   libmicrohttpd/src/microhttpd/connection.c
   libmicrohttpd/src/microhttpd/daemon.c
   libmicrohttpd/src/microhttpd/internal.h
   libmicrohttpd/src/microhttpd/response.c
   libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj
   libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj
Log:
Moved locks and mutex abstraction to mhd_locks.h
Minor refactoring to allow better code optimization.

Modified: libmicrohttpd/src/include/platform_interface.h
===================================================================
--- libmicrohttpd/src/include/platform_interface.h      2016-08-10 13:52:47 UTC 
(rev 37687)
+++ libmicrohttpd/src/include/platform_interface.h      2016-08-10 13:52:51 UTC 
(rev 37688)
@@ -189,113 +189,5 @@
 #else
 #define MHD_random_() MHD_W32_random_()
 #endif
-#if defined(MHD_USE_W32_THREADS)
-#define MHD_W32_MUTEX_ 1
-#include <windows.h>
-typedef CRITICAL_SECTION MHD_mutex_;
-#elif defined(HAVE_PTHREAD_H) && defined(MHD_USE_POSIX_THREADS)
-#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) && 0 != 
InitializeCriticalSectionAndSpinCount((mutex),2000)) ? 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))) ? 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)) ? (DeleteCriticalSection(mutex), 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))) ? 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)) ? (EnterCriticalSection((mutex)), 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))) ? 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) && 0 != TryEnterCriticalSection ((mutex))) ? 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))) ? 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)) ? (LeaveCriticalSection((mutex)), MHD_YES) : MHD_NO)
-#endif
-
 #endif /* MHD_PLATFORM_INTERFACE_H */

Modified: libmicrohttpd/src/microhttpd/Makefile.am
===================================================================
--- libmicrohttpd/src/microhttpd/Makefile.am    2016-08-10 13:52:47 UTC (rev 
37687)
+++ libmicrohttpd/src/microhttpd/Makefile.am    2016-08-10 13:52:51 UTC (rev 
37688)
@@ -68,6 +68,7 @@
   sysfdsetsize.c sysfdsetsize.h \
   mhd_str.c mhd_str.h \
   mhd_threads.c mhd_threads.h \
+  mhd_locks.h \
   response.c response.h
 libmicrohttpd_la_CPPFLAGS = \
   $(AM_CPPFLAGS) $(MHD_LIB_CPPFLAGS) \

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2016-08-10 13:52:47 UTC (rev 
37687)
+++ libmicrohttpd/src/microhttpd/connection.c   2016-08-10 13:52:51 UTC (rev 
37688)
@@ -31,6 +31,7 @@
 #include "response.h"
 #include "mhd_mono_clock.h"
 #include "mhd_str.h"
+#include "mhd_locks.h"
 
 #if HAVE_NETINET_TCP_H
 /* for TCP_CORK */
@@ -37,14 +38,7 @@
 #include <netinet/tcp.h>
 #endif
 
-#if defined(_WIN32) && defined(MHD_W32_MUTEX_)
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN 1
-#endif /* !WIN32_LEAN_AND_MEAN */
-#include <windows.h>
-#endif /* _WIN32 && MHD_W32_MUTEX_ */
 
-
 /**
  * Message to transmit when http 1.1 request is received
  */
@@ -2412,7 +2406,7 @@
     }
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     {
-      if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+      if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
         MHD_PANIC ("Failed to acquire cleanup mutex\n");
     }
   else
@@ -2441,7 +2435,7 @@
   connection->resuming = MHD_NO;
   connection->in_idle = MHD_NO;
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_(&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_(&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
 }
 

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2016-08-10 13:52:47 UTC (rev 
37687)
+++ libmicrohttpd/src/microhttpd/daemon.c       2016-08-10 13:52:51 UTC (rev 
37688)
@@ -33,6 +33,7 @@
 #include "mhd_limits.h"
 #include "autoinit_funcs.h"
 #include "mhd_mono_clock.h"
+#include "mhd_locks.h"
 
 #if HAVE_SEARCH_H
 #include <search.h>
@@ -267,7 +268,7 @@
 static void
 MHD_ip_count_lock (struct MHD_Daemon *daemon)
 {
-  if (MHD_YES != MHD_mutex_lock_(&daemon->per_ip_connection_mutex))
+  if (!MHD_mutex_lock_(&daemon->per_ip_connection_mutex))
     {
       MHD_PANIC ("Failed to acquire IP connection limit mutex\n");
     }
@@ -282,7 +283,7 @@
 static void
 MHD_ip_count_unlock (struct MHD_Daemon *daemon)
 {
-  if (MHD_YES != MHD_mutex_unlock_(&daemon->per_ip_connection_mutex))
+  if (!MHD_mutex_unlock_(&daemon->per_ip_connection_mutex))
     {
       MHD_PANIC ("Failed to release IP connection limit mutex\n");
     }
@@ -1536,7 +1537,7 @@
 
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
   {
-    if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+    if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
       MHD_PANIC ("Failed to acquire cleanup mutex\n");
   }
   else
@@ -1547,7 +1548,7 @@
              daemon->connections_tail,
              connection);
   if  ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
 
   if (NULL != daemon->notify_connection)
@@ -1631,7 +1632,7 @@
   MHD_ip_limit_del (daemon, addr, addrlen);
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
   {
-    if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+    if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
       MHD_PANIC ("Failed to acquire cleanup mutex\n");
   }
   else
@@ -1642,7 +1643,7 @@
              daemon->connections_tail,
              connection);
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
   MHD_pool_destroy (connection->pool);
   free (connection->addr);
@@ -1689,7 +1690,7 @@
     MHD_PANIC ("Cannot suspend connections without enabling 
MHD_USE_SUSPEND_RESUME!\n");
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     {
-      if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+      if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
         MHD_PANIC ("Failed to acquire cleanup mutex\n");
     }
   else
@@ -1733,7 +1734,7 @@
 #endif
   connection->suspended = MHD_YES;
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
 }
 
@@ -1755,7 +1756,7 @@
   if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
     MHD_PANIC ("Cannot resume connections without enabling 
MHD_USE_SUSPEND_RESUME!\n");
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to acquire cleanup mutex\n");
   connection->resuming = MHD_YES;
   daemon->resuming = MHD_YES;
@@ -1768,7 +1769,7 @@
 #endif
     }
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
 }
 
@@ -1789,7 +1790,7 @@
 
   ret = MHD_NO;
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to acquire cleanup mutex\n");
   if (MHD_NO != daemon->resuming)
     next = daemon->suspended_connections_head;
@@ -1845,7 +1846,7 @@
       pos->resuming = MHD_NO;
     }
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
   return ret;
 }
@@ -2069,7 +2070,7 @@
   struct MHD_Connection *pos;
 
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to acquire cleanup mutex\n");
   while (NULL != (pos = daemon->cleanup_head))
     {
@@ -2140,7 +2141,7 @@
       free (pos);
     }
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
 }
 
@@ -3856,7 +3857,7 @@
        }
     }
 
-  if (MHD_YES != MHD_mutex_create_ (&daemon->nnc_lock))
+  if (!MHD_mutex_init_ (&daemon->nnc_lock))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -4184,7 +4185,7 @@
     }
 #endif
 
-  if (MHD_YES != MHD_mutex_create_ (&daemon->per_ip_connection_mutex))
+  if (!MHD_mutex_init_ (&daemon->per_ip_connection_mutex))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -4195,7 +4196,7 @@
        MHD_PANIC ("close failed\n");
       goto free_and_fail;
     }
-  if (MHD_YES != MHD_mutex_create_ (&daemon->cleanup_connection_mutex))
+  if (!MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -4331,7 +4332,7 @@
            goto thread_failed;
 #endif
           /* Must init cleanup connection mutex for each worker */
-          if (MHD_YES != MHD_mutex_create_ (&d->cleanup_connection_mutex))
+          if (!MHD_mutex_init_ (&d->cleanup_connection_mutex))
             {
 #ifdef HAVE_MESSAGES
               MHD_DLOG (daemon,
@@ -4466,7 +4467,7 @@
   /* first, make sure all threads are aware of shutdown; need to
      traverse DLLs in peace... */
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to acquire cleanup mutex\n");
   if (NULL != daemon->suspended_connections_head)
     MHD_PANIC ("MHD_stop_daemon() called while we have suspended 
connections.\n");
@@ -4481,7 +4482,7 @@
 #endif
     }
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
+       (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
     MHD_PANIC ("Failed to release cleanup mutex\n");
 
   /* now, collect per-connection threads */
@@ -4928,7 +4929,7 @@
 
   if (NULL == *ppmtx)
     return ENOMEM;
-  if (MHD_YES != MHD_mutex_create_ ((MHD_mutex_*)*ppmtx))
+  if (!MHD_mutex_init_ ((MHD_mutex_*)*ppmtx))
     {
       free (*ppmtx);
       *ppmtx = NULL;
@@ -4942,7 +4943,7 @@
 static int
 gcry_w32_mutex_destroy (void **ppmtx)
 {
-  int res = (MHD_YES == MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
+  int res = (MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
   free (*ppmtx);
   return res;
 }
@@ -4951,7 +4952,7 @@
 static int
 gcry_w32_mutex_lock (void **ppmtx)
 {
-  return (MHD_YES == MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
+  return (MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
 }
 
 
@@ -4958,7 +4959,7 @@
 static int
 gcry_w32_mutex_unlock (void **ppmtx)
 {
-  return (MHD_YES == MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
+  return (MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
 }
 
 

Modified: libmicrohttpd/src/microhttpd/internal.h
===================================================================
--- libmicrohttpd/src/microhttpd/internal.h     2016-08-10 13:52:47 UTC (rev 
37687)
+++ libmicrohttpd/src/microhttpd/internal.h     2016-08-10 13:52:51 UTC (rev 
37688)
@@ -44,6 +44,7 @@
 #include <netinet/tcp.h>
 #endif
 #include "mhd_threads.h"
+#include "mhd_locks.h"
 
 
 /**

Added: libmicrohttpd/src/microhttpd/mhd_locks.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_locks.h                            (rev 0)
+++ libmicrohttpd/src/microhttpd/mhd_locks.h    2016-08-10 13:52:51 UTC (rev 
37688)
@@ -0,0 +1,150 @@
+/*
+  This file is part of libmicrohttpd
+  Copyright (C) 2016 Karlson2k (Evgeny Grin)
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
+*/
+
+/**
+ * @file microhttpd/mhd_locks.h
+ * @brief  Header for platform-independent locks abstraction
+ * @author Karlson2k (Evgeny Grin)
+ *
+ * Provides basic abstraction for locks and mutex.
+ * Any functions can be implemented as macro on some platforms
+ * unless explicitly marked otherwise.
+ * Any function argument can be skipped in macro, so avoid
+ * variable modification in function parameters.
+ *
+ * @warning Unlike pthread functions, most of functions return
+ *          nonzero on success.
+ */
+
+#ifndef MHD_LOCKS_H
+#define MHD_LOCKS_H 1
+
+#include "mhd_options.h"
+
+#if defined(MHD_USE_W32_THREADS)
+#  define MHD_W32_MUTEX_ 1
+#  ifndef WIN32_LEAN_AND_MEAN
+#    define WIN32_LEAN_AND_MEAN 1
+#  endif /* !WIN32_LEAN_AND_MEAN */
+#  include <windows.h>
+#elif defined(HAVE_PTHREAD_H) && defined(MHD_USE_POSIX_THREADS)
+#  define MHD_PTHREAD_MUTEX_ 1
+#  undef HAVE_CONFIG_H
+#  include <pthread.h>
+#  define HAVE_CONFIG_H 1
+#else
+#  error No base mutex API is available.
+#endif
+
+#if defined(MHD_PTHREAD_MUTEX_)
+  typedef pthread_mutex_t MHD_mutex_;
+#elif defined(MHD_W32_MUTEX_)
+  typedef CRITICAL_SECTION MHD_mutex_;
+#endif
+
+#if defined(MHD_PTHREAD_MUTEX_)
+/**
+ * Initialise new mutex.
+ * @param pmutex pointer to the mutex
+ * @return nonzero on success, zero otherwise
+ */
+#define MHD_mutex_init_(pmutex) (!(pthread_mutex_init((pmutex), NULL)))
+#elif defined(MHD_W32_MUTEX_)
+/**
+ * Initialise new mutex.
+ * @param pmutex pointer to mutex
+ * @return nonzero on success, zero otherwise
+ */
+#define MHD_mutex_init_(pmutex) 
(InitializeCriticalSectionAndSpinCount((pmutex),16))
+#endif
+
+#if defined(MHD_PTHREAD_MUTEX_)
+/**
+ * Destroy previously initialised mutex.
+ * @param pmutex pointer to mutex
+ * @return nonzero on success, zero otherwise
+ */
+#define MHD_mutex_destroy_(pmutex) (!(pthread_mutex_destroy((pmutex))))
+#elif defined(MHD_W32_MUTEX_)
+/**
+ * Destroy previously initialised mutex.
+ * @param pmutex pointer to mutex
+ * @return Always nonzero
+ */
+#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection((pmutex)), !0)
+#endif
+
+#if defined(MHD_PTHREAD_MUTEX_)
+/**
+ * Acquire lock on previously initialised mutex.
+ * If mutex was already locked by other thread, function
+ * blocks until mutex becomes available.
+ * @param pmutex pointer to mutex
+ * @return nonzero on success, zero otherwise
+ */
+#define MHD_mutex_lock_(pmutex) (!(pthread_mutex_lock((pmutex))))
+#elif defined(MHD_W32_MUTEX_)
+/**
+ * Acquire lock on previously initialised mutex.
+ * If mutex was already locked by other thread, function
+ * blocks until mutex becomes available.
+ * @param pmutex pointer to mutex
+ * @return Always nonzero
+ */
+#define MHD_mutex_lock_(pmutex) (EnterCriticalSection((pmutex)), !0)
+#endif
+
+#if defined(MHD_PTHREAD_MUTEX_)
+/**
+ * Try to acquire lock on previously initialised mutex.
+ * Function returns immediately.
+ * @param pmutex pointer to mutex
+ * @return nonzero if mutex is locked, zero if
+ *         mutex was not locked.
+ */
+#define MHD_mutex_trylock_(pmutex) (!(pthread_mutex_trylock((pmutex))))
+#elif defined(MHD_W32_MUTEX_)
+/**
+ * Try to acquire lock on previously initialised mutex.
+ * Function returns immediately.
+ * @param pmutex pointer to mutex
+ * @return nonzero if mutex is locked, zero if
+ *         mutex was not locked.
+ */
+#define MHD_mutex_trylock_(pmutex) (TryEnterCriticalSection((pmutex))))
+#endif
+
+#if defined(MHD_PTHREAD_MUTEX_)
+/**
+ * Unlock previously initialised and locked mutex.
+ * @param pmutex pointer to mutex
+ * @return nonzero on success, zero otherwise
+ */
+#define MHD_mutex_unlock_(pmutex) (!(pthread_mutex_unlock((pmutex))))
+#elif defined(MHD_W32_MUTEX_)
+/**
+ * Unlock previously initialised and locked mutex.
+ * @param pmutex pointer to mutex
+ * @return Always nonzero
+ */
+#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection((pmutex)), !0)
+#endif
+
+#endif /* ! MHD_LOCKS_H */

Modified: libmicrohttpd/src/microhttpd/response.c
===================================================================
--- libmicrohttpd/src/microhttpd/response.c     2016-08-10 13:52:47 UTC (rev 
37687)
+++ libmicrohttpd/src/microhttpd/response.c     2016-08-10 13:52:51 UTC (rev 
37688)
@@ -257,7 +257,7 @@
   response->fd = -1;
   response->data = (void *) &response[1];
   response->data_buffer_size = block_size;
-  if (MHD_YES != MHD_mutex_create_ (&response->mutex))
+  if (!MHD_mutex_init_ (&response->mutex))
     {
       free (response);
       return NULL;
@@ -513,7 +513,7 @@
     return NULL;
   memset (response, 0, sizeof (struct MHD_Response));
   response->fd = -1;
-  if (MHD_YES != MHD_mutex_create_ (&response->mutex))
+  if (!MHD_mutex_init_ (&response->mutex))
     {
       free (response);
       return NULL;

Modified: libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj
===================================================================
--- libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj        2016-08-10 
13:52:47 UTC (rev 37687)
+++ libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj        2016-08-10 
13:52:51 UTC (rev 37688)
@@ -39,6 +39,7 @@
     <ClInclude Include="$(MhdSrc)microhttpd\sysfdsetsize.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_str.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_threads.h" />
+    <ClInclude Include="$(MhdSrc)microhttpd\mhd_locks.h" />
     <ClInclude Include="$(MhdW32Common)MHD_config.h" />
   </ItemGroup>
   <ItemGroup>

Modified: libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj
===================================================================
--- libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj      2016-08-10 
13:52:47 UTC (rev 37687)
+++ libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj      2016-08-10 
13:52:51 UTC (rev 37688)
@@ -136,6 +136,9 @@
     <ClCompile Include="$(MhdSrc)microhttpd\mhd_threads.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClInclude Include="$(MhdSrc)microhttpd\mhd_locks.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="$(MhdW32Common)microhttpd_dll_res_vc.rc">




reply via email to

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