You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2013/11/25 15:08:17 UTC

svn commit: r1545292 - in /httpd/httpd/trunk/server/mpm/eventopt: eventopt.c fdqueue.c

Author: jim
Date: Mon Nov 25 14:08:17 2013
New Revision: 1545292

URL: http://svn.apache.org/r1545292
Log:
r1545286 for eventopt

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

Modified: httpd/httpd/trunk/server/mpm/eventopt/eventopt.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/eventopt/eventopt.c?rev=1545292&r1=1545291&r2=1545292&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/eventopt/eventopt.c (original)
+++ httpd/httpd/trunk/server/mpm/eventopt/eventopt.c Mon Nov 25 14:08:17 2013
@@ -3024,16 +3024,14 @@ static int event_pre_config(apr_pool_t *
     }
     ++retained->module_loads;
     if (retained->module_loads == 2) {
-        int i;
-        static apr_uint32_t foo = 0;
+        /* test for correct operation of fdqueue */
+        static apr_uint32_t foo1, foo2;
 
-        apr_atomic_inc32(&foo);
-        apr_atomic_dec32(&foo);
-        apr_atomic_dec32(&foo);
-        i = apr_atomic_dec32(&foo);
-        if (i >= 0) {
+        apr_atomic_set32(&foo1, 100);
+        foo2 = apr_atomic_add32(&foo1, -10);
+        if (foo2 != 100 || foo1 != 90) {
             ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, APLOGNO(02406)
-                         "atomics not working as expected");
+                         "atomics not working as expected - add32 of negative number");
             return HTTP_INTERNAL_SERVER_ERROR;
         }
         rv = apr_pollset_create(&event_pollset, 1, plog,

Modified: httpd/httpd/trunk/server/mpm/eventopt/fdqueue.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/eventopt/fdqueue.c?rev=1545292&r1=1545291&r2=1545292&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/eventopt/fdqueue.c (original)
+++ httpd/httpd/trunk/server/mpm/eventopt/fdqueue.c Mon Nov 25 14:08:17 2013
@@ -82,6 +82,7 @@ apr_status_t ap_queue_info_create(fd_que
     qi->recycled_pools = NULL;
     qi->max_recycled_pools = max_recycled_pools;
     qi->max_idlers = max_idlers;
+    qi->idlers = zero_pt;
     apr_pool_cleanup_register(pool, qi, queue_info_cleanup,
                               apr_pool_cleanup_null);
 
@@ -99,13 +100,7 @@ apr_status_t ap_queue_info_set_idle(fd_q
     ap_push_pool(queue_info, pool_to_recycle);
 
     /* Atomically increment the count of idle workers */
-    /*
-     * TODO: The atomics expect unsigned whereas we're using signed.
-     *       Need to double check that they work as expected or else
-     *       rework how we determine blocked.
-     * UPDATE: Correct operation is performed during open_logs()
-     */
-    prev_idlers = apr_atomic_inc32((apr_uint32_t *)&(queue_info->idlers));
+    prev_idlers = apr_atomic_inc32((apr_uint32_t *)&(queue_info->idlers)) - zero_pt;
 
     /* If other threads are waiting on a worker, wake one up */
     if (prev_idlers < 0) {
@@ -131,7 +126,7 @@ apr_status_t ap_queue_info_set_idle(fd_q
 apr_status_t ap_queue_info_try_get_idler(fd_queue_info_t * queue_info)
 {
     int prev_idlers;
-    prev_idlers = apr_atomic_dec32((apr_uint32_t *)&(queue_info->idlers));
+    prev_idlers = apr_atomic_add32((apr_uint32_t *)&(queue_info->idlers), -1) - zero_pt;
     if (prev_idlers <= 0) {
         apr_atomic_inc32((apr_uint32_t *)&(queue_info->idlers));    /* back out dec */
         return APR_EAGAIN;
@@ -147,7 +142,7 @@ apr_status_t ap_queue_info_wait_for_idle
 
     /* Atomically decrement the idle worker count, saving the old value */
     /* See TODO in ap_queue_info_set_idle() */
-    prev_idlers = apr_atomic_add32((apr_uint32_t *)&(queue_info->idlers), -1);
+    prev_idlers = apr_atomic_add32((apr_uint32_t *)&(queue_info->idlers), -1) - zero_pt;
 
     /* Block if there weren't any idle workers */
     if (prev_idlers <= 0) {
@@ -174,10 +169,11 @@ apr_status_t ap_queue_info_wait_for_idle
          *     now non-negative, it's safe for this function to
          *     return immediately.
          *
-         *     A negative value in queue_info->idlers tells how many
+         *     A "negative value" (relative to zero_pt) in
+         *     queue_info->idlers tells how many
          *     threads are waiting on an idle worker.
          */
-        if (queue_info->idlers < 0) {
+        if (queue_info->idlers < zero_pt) {
             *had_to_block = 1;
             rv = apr_thread_cond_wait(queue_info->wait_for_idler,
                                       queue_info->idlers_mutex);
@@ -208,7 +204,7 @@ apr_status_t ap_queue_info_wait_for_idle
 apr_uint32_t ap_queue_info_get_idlers(fd_queue_info_t * queue_info)
 {
     apr_int32_t val;
-    val = (apr_int32_t)apr_atomic_read32((apr_uint32_t *)&queue_info->idlers);
+    val = (apr_int32_t)apr_atomic_read32((apr_uint32_t *)&queue_info->idlers) - zero_pt;
     if (val < 0)
         return 0;
     return val;