]> granicus.if.org Git - apache/commitdiff
mpm_event/worker: make ap_queue_term() atomic (acquire/release the mutex once).
authorYann Ylavic <ylavic@apache.org>
Tue, 15 Sep 2015 16:05:31 +0000 (16:05 +0000)
committerYann Ylavic <ylavic@apache.org>
Tue, 15 Sep 2015 16:05:31 +0000 (16:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1703241 13f79535-47bb-0310-9956-ffa450edef68

server/mpm/event/fdqueue.c
server/mpm/worker/fdqueue.c

index aad847038d01de6eb10199e4c09ef1ce164db681..e78174f05e772148cb7b3befd40a0fc06c75460b 100644 (file)
@@ -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);
 }
index f8fab766d8ab39a91814042dbdb9c787ba519230..3cb131090a72e0cf81e280d8a98dc24638ca30d2 100644 (file)
@@ -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);
 }