You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by pq...@apache.org on 2008/11/01 08:13:29 UTC

svn commit: r709657 - in /httpd/httpd/trunk/server/mpm/simple: simple_children.c simple_core.c simple_event.c simple_event.h simple_io.c simple_run.c simple_types.h

Author: pquerna
Date: Sat Nov  1 00:13:29 2008
New Revision: 709657

URL: http://svn.apache.org/viewvc?rev=709657&view=rev
Log:
Convert events to have an associated pool.

* server/mpm/simple/simple_types.h
    (simple_timer_t): Add Pool and a pointer to the associated simple core.
    (simple_core_t): Remove dead timer ring, no recycling of timer events for now.

* server/mpm/simple/simple_event.h: Update register_timer signature with pool.

* server/mpm/simple/simple_event.c
    (simple_register_timer): Allocate the event structure out of the pool,
        and when this pool is destroyed, unregister the timer.
    (simple_timer_run): New util function for running a timer and cleaning up 
        the pool callbacks.

* server/mpm/simple/simple_core.c
    (simple_core_init): Remvoe dead timer ring

* server/mpm/simple/simple_run.c
    (simple_main_setup_timers): Pass in pool to register call.
    (simple_timer_invoke): Use new simple_timer_run function.
    (simple_child_loop): Remove dead timer ring.

* server/mpm/simple/simple_io.c
    (simple_io_process): Pass in pool when registering timers.

Modified:
    httpd/httpd/trunk/server/mpm/simple/simple_children.c
    httpd/httpd/trunk/server/mpm/simple/simple_core.c
    httpd/httpd/trunk/server/mpm/simple/simple_event.c
    httpd/httpd/trunk/server/mpm/simple/simple_event.h
    httpd/httpd/trunk/server/mpm/simple/simple_io.c
    httpd/httpd/trunk/server/mpm/simple/simple_run.c
    httpd/httpd/trunk/server/mpm/simple/simple_types.h

Modified: httpd/httpd/trunk/server/mpm/simple/simple_children.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/simple/simple_children.c?rev=709657&r1=709656&r2=709657&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/simple/simple_children.c (original)
+++ httpd/httpd/trunk/server/mpm/simple/simple_children.c Sat Nov  1 00:13:29 2008
@@ -118,7 +118,8 @@
 
     simple_register_timer(sc,
                           simple_check_children_size,
-                          NULL, SPAWN_CHILDREN_INTERVAL);
+                          NULL, SPAWN_CHILDREN_INTERVAL,
+                          sc->pool);
 
     if (sc->run_single_process && sc->restart_num == 2) {
         static int run = 0;

Modified: httpd/httpd/trunk/server/mpm/simple/simple_core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/simple/simple_core.c?rev=709657&r1=709656&r2=709657&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/simple/simple_core.c (original)
+++ httpd/httpd/trunk/server/mpm/simple/simple_core.c Sat Nov  1 00:13:29 2008
@@ -53,7 +53,6 @@
     sc->spawn_via = SIMPLE_SPAWN_FORK;
 
     APR_RING_INIT(&sc->timer_ring, simple_timer_t, link);
-    APR_RING_INIT(&sc->dead_timer_ring, simple_timer_t, link);
 
     rv = apr_thread_mutex_create(&sc->mtx, 0, sc->pool);
 

Modified: httpd/httpd/trunk/server/mpm/simple/simple_event.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/simple/simple_event.c?rev=709657&r1=709656&r2=709657&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/simple/simple_event.c (original)
+++ httpd/httpd/trunk/server/mpm/simple/simple_event.c Sat Nov  1 00:13:29 2008
@@ -19,10 +19,25 @@
 #include "simple_types.h"
 #include "simple_event.h"
 
+static apr_status_t
+simple_timer_pool_cleanup(void *baton)
+{
+    simple_timer_t *elem = (simple_timer_t *)baton;
+    simple_core_t *sc = elem->sc;
+
+    apr_thread_mutex_lock(sc->mtx);
+    APR_RING_REMOVE(elem, link);
+    apr_thread_mutex_unlock(sc->mtx);
+
+    return APR_SUCCESS;
+}
+
+
 void
 simple_register_timer(simple_core_t * sc,
                       simple_timer_cb cb,
-                      void *baton, apr_time_t relative_time)
+                      void *baton, apr_time_t relative_time,
+                      apr_pool_t *shutdown_pool)
 {
     simple_timer_t *elem = NULL;
     simple_timer_t *ep = NULL;
@@ -32,23 +47,16 @@
     apr_thread_mutex_lock(sc->mtx);
 
     APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
-    APR_RING_CHECK_CONSISTENCY(&sc->dead_timer_ring, simple_timer_t, link);
 
-    if (!APR_RING_EMPTY(&sc->dead_timer_ring, simple_timer_t, link)) {
-        elem = APR_RING_FIRST(&sc->dead_timer_ring);
-        APR_RING_REMOVE(elem, link);
-        APR_RING_CHECK_CONSISTENCY(&sc->dead_timer_ring, simple_timer_t,
-                                   link);
-    }
-    else {
-        elem =
-            (simple_timer_t *) apr_pcalloc(sc->pool, sizeof(simple_timer_t));
-    }
+    elem = (simple_timer_t *) apr_pcalloc(shutdown_pool, sizeof(simple_timer_t));
 
     APR_RING_ELEM_INIT(elem, link);
     elem->expires = t;
     elem->cb = cb;
     elem->baton = baton;
+    elem->pool = shutdown_pool;
+    elem->sc = sc;
+    apr_pool_cleanup_register(elem->pool, elem, simple_timer_pool_cleanup, apr_pool_cleanup_null);
 
     APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
 
@@ -80,3 +88,14 @@
 
     apr_thread_mutex_unlock(sc->mtx);
 }
+
+
+void
+simple_timer_run(simple_timer_t *ep)
+{
+    apr_pool_cleanup_kill(ep->pool, ep, simple_timer_pool_cleanup);
+
+    ep->cb(ep->sc, ep->baton);
+}
+
+

Modified: httpd/httpd/trunk/server/mpm/simple/simple_event.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/simple/simple_event.h?rev=709657&r1=709656&r2=709657&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/simple/simple_event.h (original)
+++ httpd/httpd/trunk/server/mpm/simple/simple_event.h Sat Nov  1 00:13:29 2008
@@ -27,8 +27,14 @@
 void
 simple_register_timer(simple_core_t * sc,
                       simple_timer_cb cb,
-                      void *baton, apr_time_t relative_time);
+                      void *baton,
+                      apr_time_t relative_time, 
+                      apr_pool_t *shutdown_pool);
 
+void
+simple_timer_run(simple_timer_t *ep);
+
+#if THESE_ARE_JUST_IDEAS_PATCHES_WELCOME
 /**
  * @see apr_poll.h for watch_for values
  */
@@ -49,5 +55,6 @@
                         apr_file_t * file,
                         int watch_for, apr_time_t relative_timeout);
 
+#endif
 
 #endif /* APACHE_MPM_SIMPLE_EVENT_H */

Modified: httpd/httpd/trunk/server/mpm/simple/simple_io.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/simple/simple_io.c?rev=709657&r1=709656&r2=709657&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/simple/simple_io.c (original)
+++ httpd/httpd/trunk/server/mpm/simple/simple_io.c Sat Nov  1 00:13:29 2008
@@ -102,7 +102,8 @@
                                       scon,
                                       scon->c->base_server !=
                                       NULL ? scon->c->base_server->
-                                      timeout : ap_server_conf->timeout);
+                                      timeout : ap_server_conf->timeout,
+                                      scon->pool);
 
                 cs->pfd.reqevents = APR_POLLOUT | APR_POLLHUP | APR_POLLERR;
 
@@ -139,7 +140,8 @@
                                   scon,
                                   scon->c->base_server !=
                                   NULL ? scon->c->base_server->
-                                  timeout : ap_server_conf->timeout);
+                                  timeout : ap_server_conf->timeout,
+                                  scon->pool);
 
             cs->pfd.reqevents = APR_POLLIN;
 

Modified: httpd/httpd/trunk/server/mpm/simple/simple_run.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/simple/simple_run.c?rev=709657&r1=709656&r2=709657&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/simple/simple_run.c (original)
+++ httpd/httpd/trunk/server/mpm/simple/simple_run.c Sat Nov  1 00:13:29 2008
@@ -35,7 +35,7 @@
  */
 static apr_status_t simple_main_setup_timers(simple_core_t * sc)
 {
-    simple_register_timer(sc, simple_check_children_size, NULL, 0);
+    simple_register_timer(sc, simple_check_children_size, NULL, 0, sc->pool);
 
     return APR_SUCCESS;
 }
@@ -129,14 +129,8 @@
 static void *simple_timer_invoke(apr_thread_t * thread, void *baton)
 {
     simple_timer_t *ep = (simple_timer_t *) baton;
-    simple_core_t *sc = simple_core_get();
 
-    ep->cb(sc, ep->baton);
-
-    apr_thread_mutex_lock(sc->mtx);
-    APR_RING_ELEM_INIT(ep, link);
-    APR_RING_INSERT_TAIL(&sc->dead_timer_ring, ep, simple_timer_t, link);
-    apr_thread_mutex_unlock(sc->mtx);
+    simple_timer_run(ep);
 
     return NULL;
 }
@@ -285,7 +279,6 @@
      * thought out than this. 
      */
     APR_RING_INIT(&sc->timer_ring, simple_timer_t, link);
-    APR_RING_INIT(&sc->dead_timer_ring, simple_timer_t, link);
 
     rv = simple_setup_workers(sc);
     if (rv) {

Modified: httpd/httpd/trunk/server/mpm/simple/simple_types.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/simple/simple_types.h?rev=709657&r1=709656&r2=709657&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/simple/simple_types.h (original)
+++ httpd/httpd/trunk/server/mpm/simple/simple_types.h Sat Nov  1 00:13:29 2008
@@ -70,6 +70,8 @@
     apr_time_t expires;
     simple_timer_cb cb;
     void *baton;
+    apr_pool_t *pool;
+    simple_core_t *sc;
 };
 
 typedef struct simple_child_t simple_child_t;
@@ -100,18 +102,7 @@
 
     /* List of upcoming timers, sorted by nearest first.
      */
-         
-               APR_RING_HEAD(simple_timer_ring_t, simple_timer_t) timer_ring;
-
-    /* used to recycle simple_timer_t structs, since we allocate them out of 
-     * the global pool.
-     */
-         
-         
-         
-         
-         APR_RING_HEAD(simple_dead_timer_ring_t,
-                       simple_timer_t) dead_timer_ring;
+    APR_RING_HEAD(simple_timer_ring_t, simple_timer_t) timer_ring;
 
     apr_thread_pool_t *workers;
 };