libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 5f9dfdb2b7663611df85e9d4b9d26d777a3bdd52
parent 60d4fbee43fdb6abb2f122017bdb0e084fa4a9c6
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue,  1 Apr 2014 06:16:16 +0000

Use MHD mutex macros

Diffstat:
Msrc/microhttpd/connection.c | 41++++++++++++++++++++++++-----------------
Msrc/microhttpd/daemon.c | 66+++++++++++++++++++++++++++++++++---------------------------------
Msrc/microhttpd/digestauth.c | 15+++++++++++----
Msrc/microhttpd/internal.h | 8++++----
Msrc/microhttpd/response.c | 25++++++++++++++++---------
5 files changed, 88 insertions(+), 67 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -37,6 +37,13 @@ #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 @@ -358,7 +365,7 @@ try_ready_normal_body (struct MHD_Connection *connection) /* either error or http 1.0 transfer, close socket! */ response->total_size = connection->response_write_position; if (NULL != response->crc) - pthread_mutex_unlock (&response->mutex); + MHD_mutex_unlock_ (&response->mutex); if ( ((ssize_t)MHD_CONTENT_READER_END_OF_STREAM) == ret) MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK); else @@ -372,7 +379,7 @@ try_ready_normal_body (struct MHD_Connection *connection) { connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; if (NULL != response->crc) - pthread_mutex_unlock (&response->mutex); + MHD_mutex_unlock_ (&response->mutex); return MHD_NO; } return MHD_YES; @@ -1927,7 +1934,7 @@ update_last_activity (struct MHD_Connection *connection) /* move connection to head of timeout list (by remove + add operation) */ if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (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, @@ -1936,7 +1943,7 @@ update_last_activity (struct MHD_Connection *connection) daemon->normal_timeout_tail, connection); if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); } @@ -2081,7 +2088,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) case MHD_CONNECTION_NORMAL_BODY_READY: response = connection->response; if (NULL != response->crc) - pthread_mutex_lock (&response->mutex); + MHD_mutex_lock_ (&response->mutex); if (MHD_YES != try_ready_normal_body (connection)) break; ret = connection->send_cls (connection, @@ -2101,7 +2108,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) response->data_start]); #endif if (NULL != response->crc) - pthread_mutex_unlock (&response->mutex); + MHD_mutex_unlock_ (&response->mutex); if (ret < 0) { if ((err == EINTR) || (err == EAGAIN) || (EWOULDBLOCK == err)) @@ -2179,7 +2186,7 @@ cleanup_connection (struct MHD_Connection *connection) connection->response = NULL; } if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (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, @@ -2204,7 +2211,7 @@ cleanup_connection (struct MHD_Connection *connection) connection->resuming = MHD_NO; connection->in_idle = MHD_NO; if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_(&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); } @@ -2452,18 +2459,18 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) break; case MHD_CONNECTION_NORMAL_BODY_UNREADY: if (NULL != connection->response->crc) - pthread_mutex_lock (&connection->response->mutex); + MHD_mutex_lock_ (&connection->response->mutex); if (0 == connection->response->total_size) { if (NULL != connection->response->crc) - pthread_mutex_unlock (&connection->response->mutex); + MHD_mutex_unlock_ (&connection->response->mutex); connection->state = MHD_CONNECTION_BODY_SENT; continue; } if (MHD_YES == try_ready_normal_body (connection)) { if (NULL != connection->response->crc) - pthread_mutex_unlock (&connection->response->mutex); + MHD_mutex_unlock_ (&connection->response->mutex); connection->state = MHD_CONNECTION_NORMAL_BODY_READY; break; } @@ -2474,23 +2481,23 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) break; case MHD_CONNECTION_CHUNKED_BODY_UNREADY: if (NULL != connection->response->crc) - pthread_mutex_lock (&connection->response->mutex); + MHD_mutex_lock_ (&connection->response->mutex); if (0 == connection->response->total_size) { if (NULL != connection->response->crc) - pthread_mutex_unlock (&connection->response->mutex); + MHD_mutex_unlock_ (&connection->response->mutex); connection->state = MHD_CONNECTION_BODY_SENT; continue; } if (MHD_YES == try_ready_chunked_body (connection)) { if (NULL != connection->response->crc) - pthread_mutex_unlock (&connection->response->mutex); + MHD_mutex_unlock_ (&connection->response->mutex); connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; continue; } if (NULL != connection->response->crc) - pthread_mutex_unlock (&connection->response->mutex); + MHD_mutex_unlock_ (&connection->response->mutex); break; case MHD_CONNECTION_BODY_SENT: build_header_response (connection); @@ -2776,7 +2783,7 @@ MHD_set_connection_option (struct MHD_Connection *connection, { case MHD_CONNECTION_OPTION_TIMEOUT: if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (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, @@ -2798,7 +2805,7 @@ MHD_set_connection_option (struct MHD_Connection *connection, daemon->manual_timeout_tail, connection); if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); return MHD_YES; default: diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -214,7 +214,7 @@ struct MHD_IPCount static void MHD_ip_count_lock (struct MHD_Daemon *daemon) { - if (0 != pthread_mutex_lock(&daemon->per_ip_connection_mutex)) + if (MHD_YES != MHD_mutex_lock_(&daemon->per_ip_connection_mutex)) { MHD_PANIC ("Failed to acquire IP connection limit mutex\n"); } @@ -229,7 +229,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon) static void MHD_ip_count_unlock (struct MHD_Daemon *daemon) { - if (0 != pthread_mutex_unlock(&daemon->per_ip_connection_mutex)) + if (MHD_YES != MHD_mutex_unlock_(&daemon->per_ip_connection_mutex)) { MHD_PANIC ("Failed to release IP connection limit mutex\n"); } @@ -1367,7 +1367,7 @@ internal_add_connection (struct MHD_Daemon *daemon, #endif if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (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, @@ -1376,7 +1376,7 @@ internal_add_connection (struct MHD_Daemon *daemon, daemon->connections_tail, connection); if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); /* attempt to create handler thread */ @@ -1445,7 +1445,7 @@ internal_add_connection (struct MHD_Daemon *daemon, MHD_PANIC ("close failed\n"); MHD_ip_limit_del (daemon, addr, addrlen); if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to acquire cleanup mutex\n"); DLL_remove (daemon->connections_head, daemon->connections_tail, @@ -1454,7 +1454,7 @@ internal_add_connection (struct MHD_Daemon *daemon, daemon->normal_timeout_tail, connection); if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); MHD_pool_destroy (connection->pool); free (connection->addr); @@ -1502,7 +1502,7 @@ MHD_suspend_connection (struct MHD_Connection *connection) 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)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to acquire cleanup mutex\n"); DLL_remove (daemon->connections_head, daemon->connections_tail, @@ -1541,7 +1541,7 @@ MHD_suspend_connection (struct MHD_Connection *connection) #endif connection->suspended = MHD_YES; if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); } @@ -1563,7 +1563,7 @@ MHD_resume_connection (struct MHD_Connection *connection) 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)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to acquire cleanup mutex\n"); connection->resuming = MHD_YES; daemon->resuming = MHD_YES; @@ -1576,7 +1576,7 @@ MHD_resume_connection (struct MHD_Connection *connection) #endif } if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); } @@ -1593,7 +1593,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon) struct MHD_Connection *next = NULL; if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to acquire cleanup mutex\n"); if (MHD_YES == daemon->resuming) @@ -1650,7 +1650,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon) } daemon->resuming = MHD_NO; if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); } @@ -1847,7 +1847,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) int rc; if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to acquire cleanup mutex\n"); while (NULL != (pos = daemon->cleanup_head)) { @@ -1915,7 +1915,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) daemon->max_connections++; } if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); } @@ -3441,7 +3441,7 @@ MHD_start_daemon_va (unsigned int flags, } } - if (0 != pthread_mutex_init (&daemon->nnc_lock, NULL)) + if (MHD_YES != MHD_mutex_create_ (&daemon->nnc_lock)) { #if HAVE_MESSAGES MHD_DLOG (daemon, @@ -3691,7 +3691,7 @@ MHD_start_daemon_va (unsigned int flags, } #endif - if (0 != pthread_mutex_init (&daemon->per_ip_connection_mutex, NULL)) + if (MHD_YES != MHD_mutex_create_ (&daemon->per_ip_connection_mutex)) { #if HAVE_MESSAGES MHD_DLOG (daemon, @@ -3702,13 +3702,13 @@ MHD_start_daemon_va (unsigned int flags, MHD_PANIC ("close failed\n"); goto free_and_fail; } - if (0 != pthread_mutex_init (&daemon->cleanup_connection_mutex, NULL)) + if (MHD_YES != MHD_mutex_create_ (&daemon->cleanup_connection_mutex)) { #if HAVE_MESSAGES MHD_DLOG (daemon, "MHD failed to initialize IP connection limit mutex\n"); #endif - pthread_mutex_destroy (&daemon->cleanup_connection_mutex); + MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); if ( (MHD_INVALID_SOCKET != socket_fd) && (0 != MHD_socket_close_ (socket_fd)) ) MHD_PANIC ("close failed\n"); @@ -3726,8 +3726,8 @@ MHD_start_daemon_va (unsigned int flags, if ( (MHD_INVALID_SOCKET != socket_fd) && (0 != MHD_socket_close_ (socket_fd)) ) MHD_PANIC ("close failed\n"); - pthread_mutex_destroy (&daemon->cleanup_connection_mutex); - pthread_mutex_destroy (&daemon->per_ip_connection_mutex); + MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); + MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); goto free_and_fail; } #endif @@ -3743,8 +3743,8 @@ MHD_start_daemon_va (unsigned int flags, "Failed to create listen thread: %s\n", MHD_strerror_ (res_thread_create)); #endif - pthread_mutex_destroy (&daemon->cleanup_connection_mutex); - pthread_mutex_destroy (&daemon->per_ip_connection_mutex); + MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); + MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); if ( (MHD_INVALID_SOCKET != socket_fd) && (0 != MHD_socket_close_ (socket_fd)) ) MHD_PANIC ("close failed\n"); @@ -3843,7 +3843,7 @@ MHD_start_daemon_va (unsigned int flags, goto thread_failed; #endif /* Must init cleanup connection mutex for each worker */ - if (0 != pthread_mutex_init (&d->cleanup_connection_mutex, NULL)) + if (MHD_YES != MHD_mutex_create_ (&d->cleanup_connection_mutex)) { #if HAVE_MESSAGES MHD_DLOG (daemon, @@ -3863,7 +3863,7 @@ MHD_start_daemon_va (unsigned int flags, #endif /* Free memory for this worker; cleanup below handles * all previously-created workers. */ - pthread_mutex_destroy (&d->cleanup_connection_mutex); + MHD_mutex_destroy_ (&d->cleanup_connection_mutex); goto thread_failed; } } @@ -3880,8 +3880,8 @@ thread_failed: if ( (MHD_INVALID_SOCKET != socket_fd) && (0 != MHD_socket_close_ (socket_fd)) ) MHD_PANIC ("close failed\n"); - pthread_mutex_destroy (&daemon->cleanup_connection_mutex); - pthread_mutex_destroy (&daemon->per_ip_connection_mutex); + MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); + MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); if (NULL != daemon->worker_pool) free (daemon->worker_pool); goto free_and_fail; @@ -3904,7 +3904,7 @@ thread_failed: #endif #ifdef DAUTH_SUPPORT free (daemon->nnc); - pthread_mutex_destroy (&daemon->nnc_lock); + MHD_mutex_destroy_ (&daemon->nnc_lock); #endif #if HTTPS_SUPPORT if (0 != (flags & MHD_USE_SSL)) @@ -3963,13 +3963,13 @@ close_all_connections (struct MHD_Daemon *daemon) /* first, make sure all threads are aware of shutdown; need to traverse DLLs in peace... */ if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to acquire cleanup mutex\n"); for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX) shutdown (pos->socket_fd, (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR); if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) + (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) MHD_PANIC ("Failed to release cleanup mutex\n"); /* now, collect threads from thread pool */ @@ -4093,7 +4093,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused))) MHD_PANIC ("Failed to join a thread\n"); close_all_connections (&daemon->worker_pool[i]); - pthread_mutex_destroy (&daemon->worker_pool[i].cleanup_connection_mutex); + MHD_mutex_destroy_ (&daemon->worker_pool[i].cleanup_connection_mutex); #if EPOLL_SUPPORT if ( (-1 != daemon->worker_pool[i].epoll_fd) && (0 != MHD_socket_close_ (daemon->worker_pool[i].epoll_fd)) ) @@ -4148,10 +4148,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) #ifdef DAUTH_SUPPORT free (daemon->nnc); - pthread_mutex_destroy (&daemon->nnc_lock); + MHD_mutex_destroy_ (&daemon->nnc_lock); #endif - pthread_mutex_destroy (&daemon->per_ip_connection_mutex); - pthread_mutex_destroy (&daemon->cleanup_connection_mutex); + MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); + MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) { diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c @@ -27,6 +27,13 @@ #include "internal.h" #include "md5.h" +#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_ */ + #define HASH_MD5_HEX_LEN (2 * MD5_DIGEST_SIZE) /** @@ -317,19 +324,19 @@ check_nonce_nc (struct MHD_Connection *connection, * then only increase the nonce counter by one. */ - (void) pthread_mutex_lock (&connection->daemon->nnc_lock); + (void) MHD_mutex_lock_ (&connection->daemon->nnc_lock); if (0 == nc) { strcpy(connection->daemon->nnc[off].nonce, nonce); connection->daemon->nnc[off].nc = 0; - (void) pthread_mutex_unlock (&connection->daemon->nnc_lock); + (void) MHD_mutex_unlock_ (&connection->daemon->nnc_lock); return MHD_YES; } if ( (nc <= connection->daemon->nnc[off].nc) || (0 != strcmp(connection->daemon->nnc[off].nonce, nonce)) ) { - (void) pthread_mutex_unlock (&connection->daemon->nnc_lock); + (void) MHD_mutex_unlock_ (&connection->daemon->nnc_lock); #if HAVE_MESSAGES MHD_DLOG (connection->daemon, "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, return MHD_NO; } connection->daemon->nnc[off].nc = nc; - (void) pthread_mutex_unlock (&connection->daemon->nnc_lock); + (void) MHD_mutex_unlock_ (&connection->daemon->nnc_lock); return MHD_YES; } diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -287,7 +287,7 @@ struct MHD_Response * Mutex to synchronize access to data/size and * reference counts. */ - pthread_mutex_t mutex; + MHD_mutex_ mutex; /** * Set to MHD_SIZE_UNKNOWN if size is not known. @@ -1077,12 +1077,12 @@ struct MHD_Daemon /** * Mutex for per-IP connection counts. */ - pthread_mutex_t per_ip_connection_mutex; + MHD_mutex_ per_ip_connection_mutex; /** * Mutex for (modifying) access to the "cleanup" connection DLL. */ - pthread_mutex_t cleanup_connection_mutex; + MHD_mutex_ cleanup_connection_mutex; /** * Listen socket. @@ -1218,7 +1218,7 @@ struct MHD_Daemon /** * A rw-lock for synchronizing access to `nnc'. */ - pthread_mutex_t nnc_lock; + MHD_mutex_ nnc_lock; /** * Size of `digest_auth_random. diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -27,6 +27,13 @@ #include "internal.h" #include "response.h" +#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_ */ + /** * Add a header or footer line to the response. @@ -244,7 +251,7 @@ MHD_create_response_from_callback (uint64_t size, response->fd = -1; response->data = (void *) &response[1]; response->data_buffer_size = block_size; - if (0 != pthread_mutex_init (&response->mutex, NULL)) + if (MHD_YES != MHD_mutex_create_ (&response->mutex)) { free (response); return NULL; @@ -381,7 +388,7 @@ MHD_create_response_from_data (size_t size, return NULL; memset (response, 0, sizeof (struct MHD_Response)); response->fd = -1; - if (0 != pthread_mutex_init (&response->mutex, NULL)) + if (MHD_YES != MHD_mutex_create_ (&response->mutex)) { free (response); return NULL; @@ -390,7 +397,7 @@ MHD_create_response_from_data (size_t size, { if (NULL == (tmp = malloc (size))) { - pthread_mutex_destroy (&response->mutex); + MHD_mutex_destroy_ (&response->mutex); free (response); return NULL; } @@ -447,14 +454,14 @@ MHD_destroy_response (struct MHD_Response *response) if (NULL == response) return; - pthread_mutex_lock (&response->mutex); + MHD_mutex_lock_ (&response->mutex); if (0 != --(response->reference_count)) { - pthread_mutex_unlock (&response->mutex); + MHD_mutex_unlock_ (&response->mutex); return; } - pthread_mutex_unlock (&response->mutex); - pthread_mutex_destroy (&response->mutex); + MHD_mutex_unlock_ (&response->mutex); + MHD_mutex_destroy_ (&response->mutex); if (response->crfc != NULL) response->crfc (response->crc_cls); while (NULL != response->first_header) @@ -472,9 +479,9 @@ MHD_destroy_response (struct MHD_Response *response) void MHD_increment_response_rc (struct MHD_Response *response) { - pthread_mutex_lock (&response->mutex); + MHD_mutex_lock_ (&response->mutex); (response->reference_count)++; - pthread_mutex_unlock (&response->mutex); + MHD_mutex_unlock_ (&response->mutex); }