From: Yann Ylavic Date: Tue, 15 Sep 2015 16:05:31 +0000 (+0000) Subject: mpm_event/worker: make ap_queue_term() atomic (acquire/release the mutex once). X-Git-Tag: 2.5.0-alpha~2838 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2d6eab07ac95e05069478aed2e7014cabf51f10;p=apache mpm_event/worker: make ap_queue_term() atomic (acquire/release the mutex once). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1703241 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/mpm/event/fdqueue.c b/server/mpm/event/fdqueue.c index aad847038d..e78174f05e 100644 --- a/server/mpm/event/fdqueue.c +++ b/server/mpm/event/fdqueue.c @@ -474,31 +474,30 @@ apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd, return rv; } -apr_status_t ap_queue_interrupt_all(fd_queue_t * queue) +static apr_status_t queue_interrupt_all(fd_queue_t *queue, int term) { apr_status_t rv; if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) { return rv; } + /* we must hold one_big_mutex when setting this... otherwise, + * we could end up setting it and waking everybody up just after a + * would-be popper checks it but right before they block + */ + if (term) { + queue->terminated = 1; + } apr_thread_cond_broadcast(queue->not_empty); return apr_thread_mutex_unlock(queue->one_big_mutex); } -apr_status_t ap_queue_term(fd_queue_t * queue) +apr_status_t ap_queue_interrupt_all(fd_queue_t * queue) { - apr_status_t rv; + return queue_interrupt_all(queue, 0); +} - if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) { - return rv; - } - /* we must hold one_big_mutex when setting this... otherwise, - * we could end up setting it and waking everybody up just after a - * would-be popper checks it but right before they block - */ - queue->terminated = 1; - if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) { - return rv; - } - return ap_queue_interrupt_all(queue); +apr_status_t ap_queue_term(fd_queue_t * queue) +{ + return queue_interrupt_all(queue, 1); } diff --git a/server/mpm/worker/fdqueue.c b/server/mpm/worker/fdqueue.c index f8fab766d8..3cb131090a 100644 --- a/server/mpm/worker/fdqueue.c +++ b/server/mpm/worker/fdqueue.c @@ -372,31 +372,30 @@ apr_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p) return rv; } -apr_status_t ap_queue_interrupt_all(fd_queue_t *queue) +static apr_status_t queue_interrupt_all(fd_queue_t *queue, int term) { apr_status_t rv; if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) { return rv; } + /* we must hold one_big_mutex when setting this... otherwise, + * we could end up setting it and waking everybody up just after a + * would-be popper checks it but right before they block + */ + if (term) { + queue->terminated = 1; + } apr_thread_cond_broadcast(queue->not_empty); return apr_thread_mutex_unlock(queue->one_big_mutex); } -apr_status_t ap_queue_term(fd_queue_t *queue) +apr_status_t ap_queue_interrupt_all(fd_queue_t *queue) { - apr_status_t rv; + return queue_interrupt_all(queue, 0); +} - if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) { - return rv; - } - /* we must hold one_big_mutex when setting this... otherwise, - * we could end up setting it and waking everybody up just after a - * would-be popper checks it but right before they block - */ - queue->terminated = 1; - if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) { - return rv; - } - return ap_queue_interrupt_all(queue); +apr_status_t ap_queue_term(fd_queue_t *queue) +{ + return queue_interrupt_all(queue, 1); }