From: Yann Ylavic Date: Fri, 5 Dec 2014 13:54:30 +0000 (+0000) Subject: mpm_worker: replace apr_atomic_cas32(+1) loop with the more efficient X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=924ee6ef1c43bba7c4ed3817afb8d038a862b0d2;p=thirdparty%2Fapache%2Fhttpd.git 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). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1643282 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/mpm/worker/fdqueue.c b/server/mpm/worker/fdqueue.c index fe5881b4ce8..f8fab766d8a 100644 --- a/server/mpm/worker/fdqueue.c +++ b/server/mpm/worker/fdqueue.c @@ -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;