]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mpm_worker: replace apr_atomic_cas32(+1) loop with the more efficient
authorYann Ylavic <ylavic@apache.org>
Fri, 5 Dec 2014 13:54:30 +0000 (13:54 +0000)
committerYann Ylavic <ylavic@apache.org>
Fri, 5 Dec 2014 13:54:30 +0000 (13:54 +0000)
apr_atomic_inc32().
Also declare fd_queue_info_t's idlers member as volatile since it is
used outside atomic functions (or it could be optimized out by the
compiler).

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1643282 13f79535-47bb-0310-9956-ffa450edef68

server/mpm/worker/fdqueue.c

index fe5881b4ce833856c44a2e52bf151dff22536ceb..f8fab766d8ab39a91814042dbdb9c787ba519230 100644 (file)
@@ -23,7 +23,7 @@ typedef struct recycled_pool {
 } recycled_pool;
 
 struct fd_queue_info_t {
-    apr_uint32_t idlers;
+    volatile apr_uint32_t idlers;
     apr_thread_mutex_t *idlers_mutex;
     apr_thread_cond_t *wait_for_idler;
     int terminated;
@@ -83,7 +83,6 @@ apr_status_t ap_queue_info_set_idle(fd_queue_info_t *queue_info,
                                     apr_pool_t *pool_to_recycle)
 {
     apr_status_t rv;
-    int prev_idlers;
 
     /* If we have been given a pool to recycle, atomically link
      * it into the queue_info's list of recycled pools
@@ -107,18 +106,9 @@ apr_status_t ap_queue_info_set_idle(fd_queue_info_t *queue_info,
         }
     }
 
-    /* Atomically increment the count of idle workers */
-    for (;;) {
-        prev_idlers = queue_info->idlers;
-        if (apr_atomic_cas32(&(queue_info->idlers), prev_idlers + 1,
-                             prev_idlers) == prev_idlers) {
-            break;
-        }
-    }
-
-    /* If this thread just made the idle worker count nonzero,
+    /* If this thread makes the idle worker count nonzero,
      * wake up the listener. */
-    if (prev_idlers == 0) {
+    if (apr_atomic_inc32(&queue_info->idlers) == 0) {
         rv = apr_thread_mutex_lock(queue_info->idlers_mutex);
         if (rv != APR_SUCCESS) {
             return rv;