You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2014/12/05 14:54:30 UTC

svn commit: r1643282 - /httpd/httpd/trunk/server/mpm/worker/fdqueue.c

Author: ylavic
Date: Fri Dec  5 13:54:30 2014
New Revision: 1643282

URL: http://svn.apache.org/r1643282
Log:
mpm_worker: replace apr_atomic_cas32(+1) loop with the more efficient
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).

Modified:
    httpd/httpd/trunk/server/mpm/worker/fdqueue.c

Modified: httpd/httpd/trunk/server/mpm/worker/fdqueue.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/worker/fdqueue.c?rev=1643282&r1=1643281&r2=1643282&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/worker/fdqueue.c (original)
+++ httpd/httpd/trunk/server/mpm/worker/fdqueue.c Fri Dec  5 13:54:30 2014
@@ -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_q
                                     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_q
         }
     }
 
-    /* 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;