Procházet zdrojové kódy

removing dead semaphore logic

Christian Grothoff před 9 roky
rodič
revize
79309bb602

+ 1 - 1
src/microhttpd/Makefile.am

@@ -65,7 +65,7 @@ libmicrohttpd_la_SOURCES = \
   sysfdsetsize.c sysfdsetsize.h \
   mhd_str.c mhd_str.h \
   mhd_threads.c mhd_threads.h \
-  mhd_locks.h mhd_sem.c \
+  mhd_locks.h \
   mhd_sockets.c mhd_sockets.h \
   mhd_itc.c mhd_itc.h mhd_itc_types.h \
   mhd_compat.h \

+ 0 - 8
src/microhttpd/internal.h

@@ -889,14 +889,6 @@ struct MHD_Connection
    */
   struct MHD_UpgradeResponseHandle *urh;
 
-  /**
-   * If this connection was upgraded and if we are using
-   * #MHD_USE_THREAD_PER_CONNECTION without encryption,
-   * this points to the semaphore we use to signal termination
-   * to the thread handling the connection.
-   */
-  struct MHD_Semaphore *upgrade_sem;
-
 #if HTTPS_SUPPORT
 
   /**

+ 1 - 43
src/microhttpd/mhd_locks.h

@@ -24,7 +24,7 @@
  * @author Karlson2k (Evgeny Grin)
  * @author Christian Grothoff
  *
- * Provides basic abstraction for locks/mutex and semaphores.
+ * Provides basic abstraction for locks/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
@@ -170,47 +170,5 @@
       MHD_PANIC(_("Failed to unlock mutex.\n")); \
   } while(0)
 
-/**
- * A semaphore.
- */
-struct MHD_Semaphore;
-
-
-/**
- * Create a semaphore with an initial counter of @a init
- *
- * @param init initial counter
- * @return the semaphore, NULL on error
- */
-struct MHD_Semaphore *
-MHD_semaphore_create (unsigned int init);
-
-
-/**
- * Count down the semaphore, block if necessary.
- *
- * @param sem semaphore to count down.
- */
-void
-MHD_semaphore_down (struct MHD_Semaphore *sem);
-
-
-/**
- * Increment the semaphore.
- *
- * @param sem semaphore to increment.
- */
-void
-MHD_semaphore_up (struct MHD_Semaphore *sem);
-
-
-/**
- * Destroys the semaphore.
- *
- * @param sem semaphore to destroy.
- */
-void
-MHD_semaphore_destroy (struct MHD_Semaphore *sem);
-
 
 #endif /* ! MHD_LOCKS_H */

+ 0 - 138
src/microhttpd/mhd_sem.c

@@ -1,138 +0,0 @@
-/*
-  This file is part of libmicrohttpd
-  Copyright (C) 2016 Christian Grothoff
-
-  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_sem.c
- * @brief  implementation of semaphores
- * @author Christian Grothoff
- */
-#include "internal.h"
-#include "mhd_locks.h"
-
-/**
- * A semaphore.
- */
-struct MHD_Semaphore
-{
-  /**
-   * Mutex we use internally.
-   */
-  pthread_mutex_t mutex;
-
-  /**
-   * Condition variable used to implement the semaphore.
-   */
-  pthread_cond_t cv;
-
-  /**
-   * Current value of the semaphore.
-   */
-  unsigned int counter;
-};
-
-
-/**
- * Create a semaphore with an initial counter of @a init
- *
- * @param init initial counter
- * @return the semaphore, NULL on error
- */
-struct MHD_Semaphore *
-MHD_semaphore_create (unsigned int init)
-{
-  struct MHD_Semaphore *sem;
-
-  sem = malloc (sizeof (struct MHD_Semaphore));
-  if (NULL == sem)
-    return NULL;
-  sem->counter = init;
-  if (0 != pthread_mutex_init (&sem->mutex,
-                               NULL))
-    {
-      free (sem);
-      return NULL;
-    }
-  if (0 != pthread_cond_init (&sem->cv,
-                              NULL))
-    {
-      (void) pthread_mutex_destroy (&sem->mutex);
-      free (sem);
-      return NULL;
-    }
-  return sem;
-}
-
-
-/**
- * Count down the semaphore, block if necessary.
- *
- * @param sem semaphore to count down.
- */
-void
-MHD_semaphore_down (struct MHD_Semaphore *sem)
-{
-  if (0 != pthread_mutex_lock (&sem->mutex))
-    MHD_PANIC (_("Failed to lock mutex\n"));
-  while (0 == sem->counter)
-    {
-      if (0 != pthread_cond_wait (&sem->cv,
-                                  &sem->mutex))
-        MHD_PANIC (_("pthread_cond_wait failed\n"));
-    }
-  sem->counter--;
-  if (0 != pthread_mutex_unlock (&sem->mutex))
-    MHD_PANIC (_("Failed to unlock mutex\n"));
-}
-
-
-/**
- * Increment the semaphore.
- *
- * @param sem semaphore to increment.
- */
-void
-MHD_semaphore_up (struct MHD_Semaphore *sem)
-{
-  if (0 != pthread_mutex_lock (&sem->mutex))
-    MHD_PANIC (_("Failed to lock mutex\n"));
-  sem->counter++;
-  pthread_cond_signal (&sem->cv);
-  if (0 != pthread_mutex_unlock (&sem->mutex))
-    MHD_PANIC (_("Failed to unlock mutex\n"));
-}
-
-
-/**
- * Destroys the semaphore.
- *
- * @param sem semaphore to destroy.
- */
-void
-MHD_semaphore_destroy (struct MHD_Semaphore *sem)
-{
-  if (0 != pthread_cond_destroy (&sem->cv))
-    MHD_PANIC (_("pthread_cond_destroy failed\n"));
-  if (0 != pthread_mutex_destroy (&sem->mutex))
-    MHD_PANIC (_("Failed to destroy mutex\n"));
-  free (sem);
-}
-
-
-/* end of mhd_sem.c */

+ 0 - 21
src/microhttpd/response.c

@@ -785,12 +785,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
     urh->mhd.celi = MHD_EPOLL_STATE_UNREADY;
     pool = connection->pool;
     avail = MHD_pool_get_free (pool);
-    if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) )
-      {
-        /* Need to give the thread something to block on... */
-        connection->upgrade_sem = MHD_semaphore_create (0);
-      }
-
     if (avail < 8)
       {
         /* connection's pool is totally at the limit,
@@ -905,22 +899,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
 #endif
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) )
     {
-      /* Need to give the thread something to block on... */
-      connection->upgrade_sem = MHD_semaphore_create (0);
       connection->urh = urh;
-        if (NULL == connection->upgrade_sem)
-        {
-#ifdef HAVE_MESSAGES
-          MHD_DLOG (daemon,
-                    _("Failed to create semaphore for upgrade handling\n"));
-#endif
-          MHD_connection_close_ (connection,
-                                 MHD_REQUEST_TERMINATED_WITH_ERROR);
-          return MHD_NO;
-        }
-      /* Our caller will set 'connection->state' to
-         MHD_CONNECTION_UPGRADE, thereby triggering the
-         main method of the thread to block on the semaphore. */
     }
   else
     {