mirror of
https://github.com/apache/httpd.git
synced 2025-11-06 16:49:32 +03:00
* 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.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@709657 13f79535-47bb-0310-9956-ffa450edef68
102 lines
3.1 KiB
C
102 lines
3.1 KiB
C
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright ownership.
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
* (the "License"); you may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/* #define APR_RING_DEBUG 1 */
|
|
|
|
#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,
|
|
apr_pool_t *shutdown_pool)
|
|
{
|
|
simple_timer_t *elem = NULL;
|
|
simple_timer_t *ep = NULL;
|
|
int inserted = 0;
|
|
apr_time_t t = apr_time_now() + relative_time;
|
|
|
|
apr_thread_mutex_lock(sc->mtx);
|
|
|
|
APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
|
|
|
|
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);
|
|
|
|
/* pqXXXXXX: skiplist would be a nice optimization here. */
|
|
if (!APR_RING_EMPTY(&sc->timer_ring, simple_timer_t, link)) {
|
|
ep = APR_RING_FIRST(&sc->timer_ring);
|
|
while (inserted == 0 &&
|
|
ep != APR_RING_SENTINEL(&sc->timer_ring, simple_timer_t, link))
|
|
{
|
|
if (ep->expires < elem->expires) {
|
|
APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t,
|
|
link);
|
|
APR_RING_INSERT_BEFORE(ep, elem, link);
|
|
inserted = 1;
|
|
APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t,
|
|
link);
|
|
}
|
|
ep = APR_RING_NEXT(ep, link);
|
|
}
|
|
}
|
|
|
|
APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
|
|
|
|
if (!inserted) {
|
|
APR_RING_INSERT_TAIL(&sc->timer_ring, elem, simple_timer_t, link);
|
|
}
|
|
|
|
APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
|
|
|
|
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);
|
|
}
|
|
|
|
|