aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2014-04-01 06:16:16 +0000
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2014-04-01 06:16:16 +0000
commit5f9dfdb2b7663611df85e9d4b9d26d777a3bdd52 (patch)
tree82247cd166241f855f9a760549b3b8c1d31f1bd6
parent60d4fbee43fdb6abb2f122017bdb0e084fa4a9c6 (diff)
downloadlibmicrohttpd-5f9dfdb2b7663611df85e9d4b9d26d777a3bdd52.tar.gz
libmicrohttpd-5f9dfdb2b7663611df85e9d4b9d26d777a3bdd52.zip
Use MHD mutex macros
-rw-r--r--src/microhttpd/connection.c41
-rw-r--r--src/microhttpd/daemon.c66
-rw-r--r--src/microhttpd/digestauth.c15
-rw-r--r--src/microhttpd/internal.h8
-rw-r--r--src/microhttpd/response.c25
5 files changed, 88 insertions, 67 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index dae28a41..5d5a1562 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -37,6 +37,13 @@
37#include <netinet/tcp.h> 37#include <netinet/tcp.h>
38#endif 38#endif
39 39
40#if defined(_WIN32) && defined(MHD_W32_MUTEX_)
41#ifndef WIN32_LEAN_AND_MEAN
42#define WIN32_LEAN_AND_MEAN 1
43#endif /* !WIN32_LEAN_AND_MEAN */
44#include <windows.h>
45#endif /* _WIN32 && MHD_W32_MUTEX_ */
46
40 47
41/** 48/**
42 * Message to transmit when http 1.1 request is received 49 * Message to transmit when http 1.1 request is received
@@ -358,7 +365,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
358 /* either error or http 1.0 transfer, close socket! */ 365 /* either error or http 1.0 transfer, close socket! */
359 response->total_size = connection->response_write_position; 366 response->total_size = connection->response_write_position;
360 if (NULL != response->crc) 367 if (NULL != response->crc)
361 pthread_mutex_unlock (&response->mutex); 368 MHD_mutex_unlock_ (&response->mutex);
362 if ( ((ssize_t)MHD_CONTENT_READER_END_OF_STREAM) == ret) 369 if ( ((ssize_t)MHD_CONTENT_READER_END_OF_STREAM) == ret)
363 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK); 370 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK);
364 else 371 else
@@ -372,7 +379,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
372 { 379 {
373 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; 380 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY;
374 if (NULL != response->crc) 381 if (NULL != response->crc)
375 pthread_mutex_unlock (&response->mutex); 382 MHD_mutex_unlock_ (&response->mutex);
376 return MHD_NO; 383 return MHD_NO;
377 } 384 }
378 return MHD_YES; 385 return MHD_YES;
@@ -1927,7 +1934,7 @@ update_last_activity (struct MHD_Connection *connection)
1927 1934
1928 /* move connection to head of timeout list (by remove + add operation) */ 1935 /* move connection to head of timeout list (by remove + add operation) */
1929 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1936 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1930 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1937 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1931 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1938 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1932 XDLL_remove (daemon->normal_timeout_head, 1939 XDLL_remove (daemon->normal_timeout_head,
1933 daemon->normal_timeout_tail, 1940 daemon->normal_timeout_tail,
@@ -1936,7 +1943,7 @@ update_last_activity (struct MHD_Connection *connection)
1936 daemon->normal_timeout_tail, 1943 daemon->normal_timeout_tail,
1937 connection); 1944 connection);
1938 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1945 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1939 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1946 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1940 MHD_PANIC ("Failed to release cleanup mutex\n"); 1947 MHD_PANIC ("Failed to release cleanup mutex\n");
1941} 1948}
1942 1949
@@ -2081,7 +2088,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2081 case MHD_CONNECTION_NORMAL_BODY_READY: 2088 case MHD_CONNECTION_NORMAL_BODY_READY:
2082 response = connection->response; 2089 response = connection->response;
2083 if (NULL != response->crc) 2090 if (NULL != response->crc)
2084 pthread_mutex_lock (&response->mutex); 2091 MHD_mutex_lock_ (&response->mutex);
2085 if (MHD_YES != try_ready_normal_body (connection)) 2092 if (MHD_YES != try_ready_normal_body (connection))
2086 break; 2093 break;
2087 ret = connection->send_cls (connection, 2094 ret = connection->send_cls (connection,
@@ -2101,7 +2108,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2101 response->data_start]); 2108 response->data_start]);
2102#endif 2109#endif
2103 if (NULL != response->crc) 2110 if (NULL != response->crc)
2104 pthread_mutex_unlock (&response->mutex); 2111 MHD_mutex_unlock_ (&response->mutex);
2105 if (ret < 0) 2112 if (ret < 0)
2106 { 2113 {
2107 if ((err == EINTR) || (err == EAGAIN) || (EWOULDBLOCK == err)) 2114 if ((err == EINTR) || (err == EAGAIN) || (EWOULDBLOCK == err))
@@ -2179,7 +2186,7 @@ cleanup_connection (struct MHD_Connection *connection)
2179 connection->response = NULL; 2186 connection->response = NULL;
2180 } 2187 }
2181 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2188 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2182 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 2189 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
2183 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 2190 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2184 if (connection->connection_timeout == daemon->connection_timeout) 2191 if (connection->connection_timeout == daemon->connection_timeout)
2185 XDLL_remove (daemon->normal_timeout_head, 2192 XDLL_remove (daemon->normal_timeout_head,
@@ -2204,7 +2211,7 @@ cleanup_connection (struct MHD_Connection *connection)
2204 connection->resuming = MHD_NO; 2211 connection->resuming = MHD_NO;
2205 connection->in_idle = MHD_NO; 2212 connection->in_idle = MHD_NO;
2206 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2213 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2207 (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) ) 2214 (MHD_YES != MHD_mutex_unlock_(&daemon->cleanup_connection_mutex)) )
2208 MHD_PANIC ("Failed to release cleanup mutex\n"); 2215 MHD_PANIC ("Failed to release cleanup mutex\n");
2209} 2216}
2210 2217
@@ -2452,18 +2459,18 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2452 break; 2459 break;
2453 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 2460 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
2454 if (NULL != connection->response->crc) 2461 if (NULL != connection->response->crc)
2455 pthread_mutex_lock (&connection->response->mutex); 2462 MHD_mutex_lock_ (&connection->response->mutex);
2456 if (0 == connection->response->total_size) 2463 if (0 == connection->response->total_size)
2457 { 2464 {
2458 if (NULL != connection->response->crc) 2465 if (NULL != connection->response->crc)
2459 pthread_mutex_unlock (&connection->response->mutex); 2466 MHD_mutex_unlock_ (&connection->response->mutex);
2460 connection->state = MHD_CONNECTION_BODY_SENT; 2467 connection->state = MHD_CONNECTION_BODY_SENT;
2461 continue; 2468 continue;
2462 } 2469 }
2463 if (MHD_YES == try_ready_normal_body (connection)) 2470 if (MHD_YES == try_ready_normal_body (connection))
2464 { 2471 {
2465 if (NULL != connection->response->crc) 2472 if (NULL != connection->response->crc)
2466 pthread_mutex_unlock (&connection->response->mutex); 2473 MHD_mutex_unlock_ (&connection->response->mutex);
2467 connection->state = MHD_CONNECTION_NORMAL_BODY_READY; 2474 connection->state = MHD_CONNECTION_NORMAL_BODY_READY;
2468 break; 2475 break;
2469 } 2476 }
@@ -2474,23 +2481,23 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2474 break; 2481 break;
2475 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 2482 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
2476 if (NULL != connection->response->crc) 2483 if (NULL != connection->response->crc)
2477 pthread_mutex_lock (&connection->response->mutex); 2484 MHD_mutex_lock_ (&connection->response->mutex);
2478 if (0 == connection->response->total_size) 2485 if (0 == connection->response->total_size)
2479 { 2486 {
2480 if (NULL != connection->response->crc) 2487 if (NULL != connection->response->crc)
2481 pthread_mutex_unlock (&connection->response->mutex); 2488 MHD_mutex_unlock_ (&connection->response->mutex);
2482 connection->state = MHD_CONNECTION_BODY_SENT; 2489 connection->state = MHD_CONNECTION_BODY_SENT;
2483 continue; 2490 continue;
2484 } 2491 }
2485 if (MHD_YES == try_ready_chunked_body (connection)) 2492 if (MHD_YES == try_ready_chunked_body (connection))
2486 { 2493 {
2487 if (NULL != connection->response->crc) 2494 if (NULL != connection->response->crc)
2488 pthread_mutex_unlock (&connection->response->mutex); 2495 MHD_mutex_unlock_ (&connection->response->mutex);
2489 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; 2496 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY;
2490 continue; 2497 continue;
2491 } 2498 }
2492 if (NULL != connection->response->crc) 2499 if (NULL != connection->response->crc)
2493 pthread_mutex_unlock (&connection->response->mutex); 2500 MHD_mutex_unlock_ (&connection->response->mutex);
2494 break; 2501 break;
2495 case MHD_CONNECTION_BODY_SENT: 2502 case MHD_CONNECTION_BODY_SENT:
2496 build_header_response (connection); 2503 build_header_response (connection);
@@ -2776,7 +2783,7 @@ MHD_set_connection_option (struct MHD_Connection *connection,
2776 { 2783 {
2777 case MHD_CONNECTION_OPTION_TIMEOUT: 2784 case MHD_CONNECTION_OPTION_TIMEOUT:
2778 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2785 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2779 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 2786 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
2780 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 2787 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2781 if (connection->connection_timeout == daemon->connection_timeout) 2788 if (connection->connection_timeout == daemon->connection_timeout)
2782 XDLL_remove (daemon->normal_timeout_head, 2789 XDLL_remove (daemon->normal_timeout_head,
@@ -2798,7 +2805,7 @@ MHD_set_connection_option (struct MHD_Connection *connection,
2798 daemon->manual_timeout_tail, 2805 daemon->manual_timeout_tail,
2799 connection); 2806 connection);
2800 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2807 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2801 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 2808 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
2802 MHD_PANIC ("Failed to release cleanup mutex\n"); 2809 MHD_PANIC ("Failed to release cleanup mutex\n");
2803 return MHD_YES; 2810 return MHD_YES;
2804 default: 2811 default:
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index efccdf7a..1292b421 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -214,7 +214,7 @@ struct MHD_IPCount
214static void 214static void
215MHD_ip_count_lock (struct MHD_Daemon *daemon) 215MHD_ip_count_lock (struct MHD_Daemon *daemon)
216{ 216{
217 if (0 != pthread_mutex_lock(&daemon->per_ip_connection_mutex)) 217 if (MHD_YES != MHD_mutex_lock_(&daemon->per_ip_connection_mutex))
218 { 218 {
219 MHD_PANIC ("Failed to acquire IP connection limit mutex\n"); 219 MHD_PANIC ("Failed to acquire IP connection limit mutex\n");
220 } 220 }
@@ -229,7 +229,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon)
229static void 229static void
230MHD_ip_count_unlock (struct MHD_Daemon *daemon) 230MHD_ip_count_unlock (struct MHD_Daemon *daemon)
231{ 231{
232 if (0 != pthread_mutex_unlock(&daemon->per_ip_connection_mutex)) 232 if (MHD_YES != MHD_mutex_unlock_(&daemon->per_ip_connection_mutex))
233 { 233 {
234 MHD_PANIC ("Failed to release IP connection limit mutex\n"); 234 MHD_PANIC ("Failed to release IP connection limit mutex\n");
235 } 235 }
@@ -1367,7 +1367,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1367#endif 1367#endif
1368 1368
1369 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1369 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1370 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1370 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1371 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1371 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1372 XDLL_insert (daemon->normal_timeout_head, 1372 XDLL_insert (daemon->normal_timeout_head,
1373 daemon->normal_timeout_tail, 1373 daemon->normal_timeout_tail,
@@ -1376,7 +1376,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1376 daemon->connections_tail, 1376 daemon->connections_tail,
1377 connection); 1377 connection);
1378 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1378 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1379 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1379 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1380 MHD_PANIC ("Failed to release cleanup mutex\n"); 1380 MHD_PANIC ("Failed to release cleanup mutex\n");
1381 1381
1382 /* attempt to create handler thread */ 1382 /* attempt to create handler thread */
@@ -1445,7 +1445,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1445 MHD_PANIC ("close failed\n"); 1445 MHD_PANIC ("close failed\n");
1446 MHD_ip_limit_del (daemon, addr, addrlen); 1446 MHD_ip_limit_del (daemon, addr, addrlen);
1447 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1447 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1448 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1448 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1449 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1449 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1450 DLL_remove (daemon->connections_head, 1450 DLL_remove (daemon->connections_head,
1451 daemon->connections_tail, 1451 daemon->connections_tail,
@@ -1454,7 +1454,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1454 daemon->normal_timeout_tail, 1454 daemon->normal_timeout_tail,
1455 connection); 1455 connection);
1456 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1456 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1457 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1457 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1458 MHD_PANIC ("Failed to release cleanup mutex\n"); 1458 MHD_PANIC ("Failed to release cleanup mutex\n");
1459 MHD_pool_destroy (connection->pool); 1459 MHD_pool_destroy (connection->pool);
1460 free (connection->addr); 1460 free (connection->addr);
@@ -1502,7 +1502,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
1502 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) 1502 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
1503 MHD_PANIC ("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n"); 1503 MHD_PANIC ("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n");
1504 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1504 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1505 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1505 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1506 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1506 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1507 DLL_remove (daemon->connections_head, 1507 DLL_remove (daemon->connections_head,
1508 daemon->connections_tail, 1508 daemon->connections_tail,
@@ -1541,7 +1541,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
1541#endif 1541#endif
1542 connection->suspended = MHD_YES; 1542 connection->suspended = MHD_YES;
1543 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1543 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1544 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1544 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1545 MHD_PANIC ("Failed to release cleanup mutex\n"); 1545 MHD_PANIC ("Failed to release cleanup mutex\n");
1546} 1546}
1547 1547
@@ -1563,7 +1563,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
1563 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) 1563 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
1564 MHD_PANIC ("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n"); 1564 MHD_PANIC ("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n");
1565 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1565 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1566 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1566 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1567 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1567 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1568 connection->resuming = MHD_YES; 1568 connection->resuming = MHD_YES;
1569 daemon->resuming = MHD_YES; 1569 daemon->resuming = MHD_YES;
@@ -1576,7 +1576,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
1576#endif 1576#endif
1577 } 1577 }
1578 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1578 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1579 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1579 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1580 MHD_PANIC ("Failed to release cleanup mutex\n"); 1580 MHD_PANIC ("Failed to release cleanup mutex\n");
1581} 1581}
1582 1582
@@ -1593,7 +1593,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1593 struct MHD_Connection *next = NULL; 1593 struct MHD_Connection *next = NULL;
1594 1594
1595 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1595 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1596 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1596 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1597 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1597 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1598 1598
1599 if (MHD_YES == daemon->resuming) 1599 if (MHD_YES == daemon->resuming)
@@ -1650,7 +1650,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1650 } 1650 }
1651 daemon->resuming = MHD_NO; 1651 daemon->resuming = MHD_NO;
1652 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1652 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1653 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1653 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1654 MHD_PANIC ("Failed to release cleanup mutex\n"); 1654 MHD_PANIC ("Failed to release cleanup mutex\n");
1655} 1655}
1656 1656
@@ -1847,7 +1847,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1847 int rc; 1847 int rc;
1848 1848
1849 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1849 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1850 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1850 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1851 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1851 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1852 while (NULL != (pos = daemon->cleanup_head)) 1852 while (NULL != (pos = daemon->cleanup_head))
1853 { 1853 {
@@ -1915,7 +1915,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1915 daemon->max_connections++; 1915 daemon->max_connections++;
1916 } 1916 }
1917 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1917 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1918 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1918 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1919 MHD_PANIC ("Failed to release cleanup mutex\n"); 1919 MHD_PANIC ("Failed to release cleanup mutex\n");
1920} 1920}
1921 1921
@@ -3441,7 +3441,7 @@ MHD_start_daemon_va (unsigned int flags,
3441 } 3441 }
3442 } 3442 }
3443 3443
3444 if (0 != pthread_mutex_init (&daemon->nnc_lock, NULL)) 3444 if (MHD_YES != MHD_mutex_create_ (&daemon->nnc_lock))
3445 { 3445 {
3446#if HAVE_MESSAGES 3446#if HAVE_MESSAGES
3447 MHD_DLOG (daemon, 3447 MHD_DLOG (daemon,
@@ -3691,7 +3691,7 @@ MHD_start_daemon_va (unsigned int flags,
3691 } 3691 }
3692#endif 3692#endif
3693 3693
3694 if (0 != pthread_mutex_init (&daemon->per_ip_connection_mutex, NULL)) 3694 if (MHD_YES != MHD_mutex_create_ (&daemon->per_ip_connection_mutex))
3695 { 3695 {
3696#if HAVE_MESSAGES 3696#if HAVE_MESSAGES
3697 MHD_DLOG (daemon, 3697 MHD_DLOG (daemon,
@@ -3702,13 +3702,13 @@ MHD_start_daemon_va (unsigned int flags,
3702 MHD_PANIC ("close failed\n"); 3702 MHD_PANIC ("close failed\n");
3703 goto free_and_fail; 3703 goto free_and_fail;
3704 } 3704 }
3705 if (0 != pthread_mutex_init (&daemon->cleanup_connection_mutex, NULL)) 3705 if (MHD_YES != MHD_mutex_create_ (&daemon->cleanup_connection_mutex))
3706 { 3706 {
3707#if HAVE_MESSAGES 3707#if HAVE_MESSAGES
3708 MHD_DLOG (daemon, 3708 MHD_DLOG (daemon,
3709 "MHD failed to initialize IP connection limit mutex\n"); 3709 "MHD failed to initialize IP connection limit mutex\n");
3710#endif 3710#endif
3711 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3711 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
3712 if ( (MHD_INVALID_SOCKET != socket_fd) && 3712 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3713 (0 != MHD_socket_close_ (socket_fd)) ) 3713 (0 != MHD_socket_close_ (socket_fd)) )
3714 MHD_PANIC ("close failed\n"); 3714 MHD_PANIC ("close failed\n");
@@ -3726,8 +3726,8 @@ MHD_start_daemon_va (unsigned int flags,
3726 if ( (MHD_INVALID_SOCKET != socket_fd) && 3726 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3727 (0 != MHD_socket_close_ (socket_fd)) ) 3727 (0 != MHD_socket_close_ (socket_fd)) )
3728 MHD_PANIC ("close failed\n"); 3728 MHD_PANIC ("close failed\n");
3729 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3729 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
3730 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 3730 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
3731 goto free_and_fail; 3731 goto free_and_fail;
3732 } 3732 }
3733#endif 3733#endif
@@ -3743,8 +3743,8 @@ MHD_start_daemon_va (unsigned int flags,
3743 "Failed to create listen thread: %s\n", 3743 "Failed to create listen thread: %s\n",
3744 MHD_strerror_ (res_thread_create)); 3744 MHD_strerror_ (res_thread_create));
3745#endif 3745#endif
3746 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3746 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
3747 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 3747 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
3748 if ( (MHD_INVALID_SOCKET != socket_fd) && 3748 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3749 (0 != MHD_socket_close_ (socket_fd)) ) 3749 (0 != MHD_socket_close_ (socket_fd)) )
3750 MHD_PANIC ("close failed\n"); 3750 MHD_PANIC ("close failed\n");
@@ -3843,7 +3843,7 @@ MHD_start_daemon_va (unsigned int flags,
3843 goto thread_failed; 3843 goto thread_failed;
3844#endif 3844#endif
3845 /* Must init cleanup connection mutex for each worker */ 3845 /* Must init cleanup connection mutex for each worker */
3846 if (0 != pthread_mutex_init (&d->cleanup_connection_mutex, NULL)) 3846 if (MHD_YES != MHD_mutex_create_ (&d->cleanup_connection_mutex))
3847 { 3847 {
3848#if HAVE_MESSAGES 3848#if HAVE_MESSAGES
3849 MHD_DLOG (daemon, 3849 MHD_DLOG (daemon,
@@ -3863,7 +3863,7 @@ MHD_start_daemon_va (unsigned int flags,
3863#endif 3863#endif
3864 /* Free memory for this worker; cleanup below handles 3864 /* Free memory for this worker; cleanup below handles
3865 * all previously-created workers. */ 3865 * all previously-created workers. */
3866 pthread_mutex_destroy (&d->cleanup_connection_mutex); 3866 MHD_mutex_destroy_ (&d->cleanup_connection_mutex);
3867 goto thread_failed; 3867 goto thread_failed;
3868 } 3868 }
3869 } 3869 }
@@ -3880,8 +3880,8 @@ thread_failed:
3880 if ( (MHD_INVALID_SOCKET != socket_fd) && 3880 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3881 (0 != MHD_socket_close_ (socket_fd)) ) 3881 (0 != MHD_socket_close_ (socket_fd)) )
3882 MHD_PANIC ("close failed\n"); 3882 MHD_PANIC ("close failed\n");
3883 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3883 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
3884 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 3884 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
3885 if (NULL != daemon->worker_pool) 3885 if (NULL != daemon->worker_pool)
3886 free (daemon->worker_pool); 3886 free (daemon->worker_pool);
3887 goto free_and_fail; 3887 goto free_and_fail;
@@ -3904,7 +3904,7 @@ thread_failed:
3904#endif 3904#endif
3905#ifdef DAUTH_SUPPORT 3905#ifdef DAUTH_SUPPORT
3906 free (daemon->nnc); 3906 free (daemon->nnc);
3907 pthread_mutex_destroy (&daemon->nnc_lock); 3907 MHD_mutex_destroy_ (&daemon->nnc_lock);
3908#endif 3908#endif
3909#if HTTPS_SUPPORT 3909#if HTTPS_SUPPORT
3910 if (0 != (flags & MHD_USE_SSL)) 3910 if (0 != (flags & MHD_USE_SSL))
@@ -3963,13 +3963,13 @@ close_all_connections (struct MHD_Daemon *daemon)
3963 /* first, make sure all threads are aware of shutdown; need to 3963 /* first, make sure all threads are aware of shutdown; need to
3964 traverse DLLs in peace... */ 3964 traverse DLLs in peace... */
3965 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3965 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3966 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 3966 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
3967 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 3967 MHD_PANIC ("Failed to acquire cleanup mutex\n");
3968 for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX) 3968 for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX)
3969 shutdown (pos->socket_fd, 3969 shutdown (pos->socket_fd,
3970 (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR); 3970 (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR);
3971 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3971 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3972 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 3972 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
3973 MHD_PANIC ("Failed to release cleanup mutex\n"); 3973 MHD_PANIC ("Failed to release cleanup mutex\n");
3974 3974
3975 /* now, collect threads from thread pool */ 3975 /* now, collect threads from thread pool */
@@ -4093,7 +4093,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
4093 if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused))) 4093 if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused)))
4094 MHD_PANIC ("Failed to join a thread\n"); 4094 MHD_PANIC ("Failed to join a thread\n");
4095 close_all_connections (&daemon->worker_pool[i]); 4095 close_all_connections (&daemon->worker_pool[i]);
4096 pthread_mutex_destroy (&daemon->worker_pool[i].cleanup_connection_mutex); 4096 MHD_mutex_destroy_ (&daemon->worker_pool[i].cleanup_connection_mutex);
4097#if EPOLL_SUPPORT 4097#if EPOLL_SUPPORT
4098 if ( (-1 != daemon->worker_pool[i].epoll_fd) && 4098 if ( (-1 != daemon->worker_pool[i].epoll_fd) &&
4099 (0 != MHD_socket_close_ (daemon->worker_pool[i].epoll_fd)) ) 4099 (0 != MHD_socket_close_ (daemon->worker_pool[i].epoll_fd)) )
@@ -4148,10 +4148,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
4148 4148
4149#ifdef DAUTH_SUPPORT 4149#ifdef DAUTH_SUPPORT
4150 free (daemon->nnc); 4150 free (daemon->nnc);
4151 pthread_mutex_destroy (&daemon->nnc_lock); 4151 MHD_mutex_destroy_ (&daemon->nnc_lock);
4152#endif 4152#endif
4153 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 4153 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
4154 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 4154 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
4155 4155
4156 if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) 4156 if (MHD_INVALID_PIPE_ != daemon->wpipe[1])
4157 { 4157 {
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 3250b1a8..0816b3ff 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -27,6 +27,13 @@
27#include "internal.h" 27#include "internal.h"
28#include "md5.h" 28#include "md5.h"
29 29
30#if defined(_WIN32) && defined(MHD_W32_MUTEX_)
31#ifndef WIN32_LEAN_AND_MEAN
32#define WIN32_LEAN_AND_MEAN 1
33#endif /* !WIN32_LEAN_AND_MEAN */
34#include <windows.h>
35#endif /* _WIN32 && MHD_W32_MUTEX_ */
36
30#define HASH_MD5_HEX_LEN (2 * MD5_DIGEST_SIZE) 37#define HASH_MD5_HEX_LEN (2 * MD5_DIGEST_SIZE)
31 38
32/** 39/**
@@ -317,19 +324,19 @@ check_nonce_nc (struct MHD_Connection *connection,
317 * then only increase the nonce counter by one. 324 * then only increase the nonce counter by one.
318 */ 325 */
319 326
320 (void) pthread_mutex_lock (&connection->daemon->nnc_lock); 327 (void) MHD_mutex_lock_ (&connection->daemon->nnc_lock);
321 if (0 == nc) 328 if (0 == nc)
322 { 329 {
323 strcpy(connection->daemon->nnc[off].nonce, 330 strcpy(connection->daemon->nnc[off].nonce,
324 nonce); 331 nonce);
325 connection->daemon->nnc[off].nc = 0; 332 connection->daemon->nnc[off].nc = 0;
326 (void) pthread_mutex_unlock (&connection->daemon->nnc_lock); 333 (void) MHD_mutex_unlock_ (&connection->daemon->nnc_lock);
327 return MHD_YES; 334 return MHD_YES;
328 } 335 }
329 if ( (nc <= connection->daemon->nnc[off].nc) || 336 if ( (nc <= connection->daemon->nnc[off].nc) ||
330 (0 != strcmp(connection->daemon->nnc[off].nonce, nonce)) ) 337 (0 != strcmp(connection->daemon->nnc[off].nonce, nonce)) )
331 { 338 {
332 (void) pthread_mutex_unlock (&connection->daemon->nnc_lock); 339 (void) MHD_mutex_unlock_ (&connection->daemon->nnc_lock);
333#if HAVE_MESSAGES 340#if HAVE_MESSAGES
334 MHD_DLOG (connection->daemon, 341 MHD_DLOG (connection->daemon,
335 "Stale nonce received. If this happens a lot, you should probably increase the size of the nonce array.\n"); 342 "Stale nonce received. If this happens a lot, you should probably increase the size of the nonce array.\n");
@@ -337,7 +344,7 @@ check_nonce_nc (struct MHD_Connection *connection,
337 return MHD_NO; 344 return MHD_NO;
338 } 345 }
339 connection->daemon->nnc[off].nc = nc; 346 connection->daemon->nnc[off].nc = nc;
340 (void) pthread_mutex_unlock (&connection->daemon->nnc_lock); 347 (void) MHD_mutex_unlock_ (&connection->daemon->nnc_lock);
341 return MHD_YES; 348 return MHD_YES;
342} 349}
343 350
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 53d1f85f..57c1aebb 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -287,7 +287,7 @@ struct MHD_Response
287 * Mutex to synchronize access to data/size and 287 * Mutex to synchronize access to data/size and
288 * reference counts. 288 * reference counts.
289 */ 289 */
290 pthread_mutex_t mutex; 290 MHD_mutex_ mutex;
291 291
292 /** 292 /**
293 * Set to MHD_SIZE_UNKNOWN if size is not known. 293 * Set to MHD_SIZE_UNKNOWN if size is not known.
@@ -1077,12 +1077,12 @@ struct MHD_Daemon
1077 /** 1077 /**
1078 * Mutex for per-IP connection counts. 1078 * Mutex for per-IP connection counts.
1079 */ 1079 */
1080 pthread_mutex_t per_ip_connection_mutex; 1080 MHD_mutex_ per_ip_connection_mutex;
1081 1081
1082 /** 1082 /**
1083 * Mutex for (modifying) access to the "cleanup" connection DLL. 1083 * Mutex for (modifying) access to the "cleanup" connection DLL.
1084 */ 1084 */
1085 pthread_mutex_t cleanup_connection_mutex; 1085 MHD_mutex_ cleanup_connection_mutex;
1086 1086
1087 /** 1087 /**
1088 * Listen socket. 1088 * Listen socket.
@@ -1218,7 +1218,7 @@ struct MHD_Daemon
1218 /** 1218 /**
1219 * A rw-lock for synchronizing access to `nnc'. 1219 * A rw-lock for synchronizing access to `nnc'.
1220 */ 1220 */
1221 pthread_mutex_t nnc_lock; 1221 MHD_mutex_ nnc_lock;
1222 1222
1223 /** 1223 /**
1224 * Size of `digest_auth_random. 1224 * Size of `digest_auth_random.
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index abaa64ca..ad05c5fb 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -27,6 +27,13 @@
27#include "internal.h" 27#include "internal.h"
28#include "response.h" 28#include "response.h"
29 29
30#if defined(_WIN32) && defined(MHD_W32_MUTEX_)
31#ifndef WIN32_LEAN_AND_MEAN
32#define WIN32_LEAN_AND_MEAN 1
33#endif /* !WIN32_LEAN_AND_MEAN */
34#include <windows.h>
35#endif /* _WIN32 && MHD_W32_MUTEX_ */
36
30 37
31/** 38/**
32 * Add a header or footer line to the response. 39 * Add a header or footer line to the response.
@@ -244,7 +251,7 @@ MHD_create_response_from_callback (uint64_t size,
244 response->fd = -1; 251 response->fd = -1;
245 response->data = (void *) &response[1]; 252 response->data = (void *) &response[1];
246 response->data_buffer_size = block_size; 253 response->data_buffer_size = block_size;
247 if (0 != pthread_mutex_init (&response->mutex, NULL)) 254 if (MHD_YES != MHD_mutex_create_ (&response->mutex))
248 { 255 {
249 free (response); 256 free (response);
250 return NULL; 257 return NULL;
@@ -381,7 +388,7 @@ MHD_create_response_from_data (size_t size,
381 return NULL; 388 return NULL;
382 memset (response, 0, sizeof (struct MHD_Response)); 389 memset (response, 0, sizeof (struct MHD_Response));
383 response->fd = -1; 390 response->fd = -1;
384 if (0 != pthread_mutex_init (&response->mutex, NULL)) 391 if (MHD_YES != MHD_mutex_create_ (&response->mutex))
385 { 392 {
386 free (response); 393 free (response);
387 return NULL; 394 return NULL;
@@ -390,7 +397,7 @@ MHD_create_response_from_data (size_t size,
390 { 397 {
391 if (NULL == (tmp = malloc (size))) 398 if (NULL == (tmp = malloc (size)))
392 { 399 {
393 pthread_mutex_destroy (&response->mutex); 400 MHD_mutex_destroy_ (&response->mutex);
394 free (response); 401 free (response);
395 return NULL; 402 return NULL;
396 } 403 }
@@ -447,14 +454,14 @@ MHD_destroy_response (struct MHD_Response *response)
447 454
448 if (NULL == response) 455 if (NULL == response)
449 return; 456 return;
450 pthread_mutex_lock (&response->mutex); 457 MHD_mutex_lock_ (&response->mutex);
451 if (0 != --(response->reference_count)) 458 if (0 != --(response->reference_count))
452 { 459 {
453 pthread_mutex_unlock (&response->mutex); 460 MHD_mutex_unlock_ (&response->mutex);
454 return; 461 return;
455 } 462 }
456 pthread_mutex_unlock (&response->mutex); 463 MHD_mutex_unlock_ (&response->mutex);
457 pthread_mutex_destroy (&response->mutex); 464 MHD_mutex_destroy_ (&response->mutex);
458 if (response->crfc != NULL) 465 if (response->crfc != NULL)
459 response->crfc (response->crc_cls); 466 response->crfc (response->crc_cls);
460 while (NULL != response->first_header) 467 while (NULL != response->first_header)
@@ -472,9 +479,9 @@ MHD_destroy_response (struct MHD_Response *response)
472void 479void
473MHD_increment_response_rc (struct MHD_Response *response) 480MHD_increment_response_rc (struct MHD_Response *response)
474{ 481{
475 pthread_mutex_lock (&response->mutex); 482 MHD_mutex_lock_ (&response->mutex);
476 (response->reference_count)++; 483 (response->reference_count)++;
477 pthread_mutex_unlock (&response->mutex); 484 MHD_mutex_unlock_ (&response->mutex);
478} 485}
479 486
480 487