2 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
17 /* $Id: timer_api.c,v 1.4 2009/09/02 23:48:02 tbox Exp $ */
24 #include <isc/magic.h>
25 #include <isc/mutex.h>
27 #include <isc/timer.h>
30 static isc_mutex_t createlock;
31 static isc_once_t once = ISC_ONCE_INIT;
32 static isc_timermgrcreatefunc_t timermgr_createfunc = NULL;
36 RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
40 isc_timer_register(isc_timermgrcreatefunc_t createfunc) {
41 isc_result_t result = ISC_R_SUCCESS;
43 RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
46 if (timermgr_createfunc == NULL)
47 timermgr_createfunc = createfunc;
49 result = ISC_R_EXISTS;
56 isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
57 isc_timermgr_t **managerp)
63 REQUIRE(timermgr_createfunc != NULL);
64 result = (*timermgr_createfunc)(mctx, managerp);
68 if (result == ISC_R_SUCCESS)
69 isc_appctx_settimermgr(actx, *managerp);
75 isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
80 REQUIRE(timermgr_createfunc != NULL);
81 result = (*timermgr_createfunc)(mctx, managerp);
89 isc_timermgr_destroy(isc_timermgr_t **managerp) {
90 REQUIRE(*managerp != NULL && ISCAPI_TIMERMGR_VALID(*managerp));
92 (*managerp)->methods->destroy(managerp);
94 ENSURE(*managerp == NULL);
98 isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
99 isc_time_t *expires, isc_interval_t *interval,
100 isc_task_t *task, isc_taskaction_t action, const void *arg,
101 isc_timer_t **timerp)
103 REQUIRE(ISCAPI_TIMERMGR_VALID(manager));
105 return (manager->methods->timercreate(manager, type, expires,
106 interval, task, action, arg,
111 isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp) {
112 REQUIRE(ISCAPI_TIMER_VALID(timer));
113 REQUIRE(timerp != NULL && *timerp == NULL);
115 timer->methods->attach(timer, timerp);
117 ENSURE(*timerp == timer);
121 isc_timer_detach(isc_timer_t **timerp) {
122 REQUIRE(timerp != NULL && ISCAPI_TIMER_VALID(*timerp));
124 (*timerp)->methods->detach(timerp);
126 ENSURE(*timerp == NULL);
130 isc_timer_reset(isc_timer_t *timer, isc_timertype_t type,
131 isc_time_t *expires, isc_interval_t *interval,
134 REQUIRE(ISCAPI_TIMER_VALID(timer));
136 return (timer->methods->reset(timer, type, expires, interval, purge));
140 isc_timer_touch(isc_timer_t *timer) {
141 REQUIRE(ISCAPI_TIMER_VALID(timer));
143 return (timer->methods->touch(timer));