[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r37012 - libmicrohttpd/src/microhttpd
From: |
gnunet |
Subject: |
[GNUnet-SVN] r37012 - libmicrohttpd/src/microhttpd |
Date: |
Sun, 10 Apr 2016 21:12:38 +0200 |
Author: Karlson2k
Date: 2016-04-10 21:12:37 +0200 (Sun, 10 Apr 2016)
New Revision: 37012
Modified:
libmicrohttpd/src/microhttpd/connection.c
libmicrohttpd/src/microhttpd/daemon.c
libmicrohttpd/src/microhttpd/internal.h
Log:
Use less locking with MHD_USE_THREAD_PER_CONNECTION.
Do not maintain global list out timeouts as each thread use individual timeout.
As result - global mutex is not acquired after each single send()/recv().
Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c 2016-04-10 09:42:35 UTC (rev
37011)
+++ libmicrohttpd/src/microhttpd/connection.c 2016-04-10 19:12:37 UTC (rev
37012)
@@ -2132,13 +2132,13 @@
struct MHD_Daemon *daemon = connection->daemon;
connection->last_activity = MHD_monotonic_sec_counter();
+ if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+ return; /* each connection has personal timeout */
+
if (connection->connection_timeout != daemon->connection_timeout)
return; /* custom timeout, no need to move it in "normal" DLL */
/* move connection to head of timeout list (by remove + add operation) */
- if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
- MHD_PANIC ("Failed to acquire cleanup mutex\n");
XDLL_remove (daemon->normal_timeout_head,
daemon->normal_timeout_tail,
connection);
@@ -2145,9 +2145,6 @@
XDLL_insert (daemon->normal_timeout_head,
daemon->normal_timeout_tail,
connection);
- if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
- MHD_PANIC ("Failed to release cleanup mutex\n");
}
@@ -2397,17 +2394,22 @@
MHD_destroy_response (connection->response);
connection->response = NULL;
}
- if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
- MHD_PANIC ("Failed to acquire cleanup mutex\n");
- if (connection->connection_timeout == daemon->connection_timeout)
- XDLL_remove (daemon->normal_timeout_head,
- daemon->normal_timeout_tail,
- connection);
+ if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+ {
+ if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+ MHD_PANIC ("Failed to acquire cleanup mutex\n");
+ }
else
- XDLL_remove (daemon->manual_timeout_head,
- daemon->manual_timeout_tail,
- connection);
+ {
+ if (connection->connection_timeout == daemon->connection_timeout)
+ XDLL_remove (daemon->normal_timeout_head,
+ daemon->normal_timeout_tail,
+ connection);
+ else
+ XDLL_remove (daemon->manual_timeout_head,
+ daemon->manual_timeout_tail,
+ connection);
+ }
if (MHD_YES == connection->suspended)
DLL_remove (daemon->suspended_connections_head,
daemon->suspended_connections_tail,
@@ -3040,37 +3042,33 @@
switch (option)
{
case MHD_CONNECTION_OPTION_TIMEOUT:
- if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
- MHD_PANIC ("Failed to acquire cleanup mutex\n");
- if (MHD_YES != connection->suspended)
+ if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
+ (MHD_YES != connection->suspended) )
{
if (connection->connection_timeout == daemon->connection_timeout)
XDLL_remove (daemon->normal_timeout_head,
- daemon->normal_timeout_tail,
- connection);
+ daemon->normal_timeout_tail,
+ connection);
else
XDLL_remove (daemon->manual_timeout_head,
- daemon->manual_timeout_tail,
- connection);
+ daemon->manual_timeout_tail,
+ connection);
}
va_start (ap, option);
connection->connection_timeout = va_arg (ap, unsigned int);
va_end (ap);
- if (MHD_YES != connection->suspended)
+ if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
+ (MHD_YES != connection->suspended) )
{
if (connection->connection_timeout == daemon->connection_timeout)
XDLL_insert (daemon->normal_timeout_head,
- daemon->normal_timeout_tail,
- connection);
+ daemon->normal_timeout_tail,
+ connection);
else
XDLL_insert (daemon->manual_timeout_head,
- daemon->manual_timeout_tail,
- connection);
+ daemon->manual_timeout_tail,
+ connection);
}
- if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
- MHD_PANIC ("Failed to release cleanup mutex\n");
return MHD_YES;
default:
return MHD_NO;
Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c 2016-04-10 09:42:35 UTC (rev
37011)
+++ libmicrohttpd/src/microhttpd/daemon.c 2016-04-10 19:12:37 UTC (rev
37012)
@@ -842,7 +842,6 @@
MHD_socket maxsock;
struct timeval tv;
struct timeval *tvp;
- unsigned int timeout;
time_t now;
#if WINDOWS
MHD_pipe spipe = con->daemon->wpipe[0];
@@ -857,10 +856,10 @@
struct pollfd p[1 + EXTRA_SLOTS];
#endif
- timeout = con->daemon->connection_timeout;
while ( (MHD_YES != con->daemon->shutdown) &&
(MHD_CONNECTION_CLOSED != con->state) )
{
+ unsigned const int timeout = con->daemon->connection_timeout;
tvp = NULL;
#if HTTPS_SUPPORT
if (MHD_YES == con->tls_read_ready)
@@ -1563,12 +1562,15 @@
}
#endif
- if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
- MHD_PANIC ("Failed to acquire cleanup mutex\n");
- XDLL_insert (daemon->normal_timeout_head,
- daemon->normal_timeout_tail,
- connection);
+ if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+ {
+ if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+ MHD_PANIC ("Failed to acquire cleanup mutex\n");
+ }
+ else
+ XDLL_insert (daemon->normal_timeout_head,
+ daemon->normal_timeout_tail,
+ connection);
DLL_insert (daemon->connections_head,
daemon->connections_tail,
connection);
@@ -1655,15 +1657,18 @@
if (0 != MHD_socket_close_ (client_socket))
MHD_PANIC ("close failed\n");
MHD_ip_limit_del (daemon, addr, addrlen);
- if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
- MHD_PANIC ("Failed to acquire cleanup mutex\n");
+ if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+ {
+ if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+ MHD_PANIC ("Failed to acquire cleanup mutex\n");
+ }
+ else
+ XDLL_remove (daemon->normal_timeout_head,
+ daemon->normal_timeout_tail,
+ connection);
DLL_remove (daemon->connections_head,
daemon->connections_tail,
connection);
- XDLL_remove (daemon->normal_timeout_head,
- daemon->normal_timeout_tail,
- connection);
if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
(MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
MHD_PANIC ("Failed to release cleanup mutex\n");
@@ -1712,9 +1717,22 @@
daemon = connection->daemon;
if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
MHD_PANIC ("Cannot suspend 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_PANIC ("Failed to acquire cleanup mutex\n");
+ if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+ {
+ if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+ MHD_PANIC ("Failed to acquire cleanup mutex\n");
+ }
+ else
+ {
+ if (connection->connection_timeout == daemon->connection_timeout)
+ XDLL_remove (daemon->normal_timeout_head,
+ daemon->normal_timeout_tail,
+ connection);
+ else
+ XDLL_remove (daemon->manual_timeout_head,
+ daemon->manual_timeout_tail,
+ connection);
+ }
DLL_remove (daemon->connections_head,
daemon->connections_tail,
connection);
@@ -1721,14 +1739,6 @@
DLL_insert (daemon->suspended_connections_head,
daemon->suspended_connections_tail,
connection);
- if (connection->connection_timeout == daemon->connection_timeout)
- XDLL_remove (daemon->normal_timeout_head,
- daemon->normal_timeout_tail,
- connection);
- else
- XDLL_remove (daemon->manual_timeout_head,
- daemon->manual_timeout_tail,
- connection);
#if EPOLL_SUPPORT
if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
{
@@ -1826,14 +1836,17 @@
DLL_insert (daemon->connections_head,
daemon->connections_tail,
pos);
- if (pos->connection_timeout == daemon->connection_timeout)
- XDLL_insert (daemon->normal_timeout_head,
- daemon->normal_timeout_tail,
- pos);
- else
- XDLL_insert (daemon->manual_timeout_head,
- daemon->manual_timeout_tail,
- pos);
+ if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+ {
+ if (pos->connection_timeout == daemon->connection_timeout)
+ XDLL_insert (daemon->normal_timeout_head,
+ daemon->normal_timeout_tail,
+ pos);
+ else
+ XDLL_insert (daemon->manual_timeout_head,
+ daemon->manual_timeout_tail,
+ pos);
+ }
#if EPOLL_SUPPORT
if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
{
Modified: libmicrohttpd/src/microhttpd/internal.h
===================================================================
--- libmicrohttpd/src/microhttpd/internal.h 2016-04-10 09:42:35 UTC (rev
37011)
+++ libmicrohttpd/src/microhttpd/internal.h 2016-04-10 19:12:37 UTC (rev
37012)
@@ -976,6 +976,8 @@
* All connections by default start in this list; if a custom
* timeout that does not match @e connection_timeout is set, they
* are moved to the @e manual_timeout_head-XDLL.
+ * Not used in MHD_USE_THREAD_PER_CONNECTION mode as each thread
+ * needs only one connection-specific timeout.
*/
struct MHD_Connection *normal_timeout_head;
@@ -982,6 +984,7 @@
/**
* Tail of the XDLL of ALL connections with a default timeout,
* sorted by timeout (earliest timeout at the tail).
+ * Not used in MHD_USE_THREAD_PER_CONNECTION mode.
*/
struct MHD_Connection *normal_timeout_tail;
@@ -989,6 +992,7 @@
* Head of the XDLL of ALL connections with a non-default/custom
* timeout, unsorted. MHD will do a O(n) scan over this list to
* determine the current timeout.
+ * Not used in MHD_USE_THREAD_PER_CONNECTION mode.
*/
struct MHD_Connection *manual_timeout_head;
@@ -995,6 +999,7 @@
/**
* Tail of the XDLL of ALL connections with a non-default/custom
* timeout, unsorted.
+ * Not used in MHD_USE_THREAD_PER_CONNECTION mode.
*/
struct MHD_Connection *manual_timeout_tail;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r37012 - libmicrohttpd/src/microhttpd,
gnunet <=