4 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id: timer_api.c,v 1.4 2009/09/02 23:48:02 tbox Exp */
26 #include <isc/magic.h>
27 #include <isc/mutex.h>
29 #include <isc/timer.h>
32 static isc_mutex_t createlock
;
33 static isc_once_t once
= ISC_ONCE_INIT
;
34 static isc_timermgrcreatefunc_t timermgr_createfunc
= NULL
;
38 RUNTIME_CHECK(isc_mutex_init(&createlock
) == ISC_R_SUCCESS
);
42 isc_timer_register(isc_timermgrcreatefunc_t createfunc
) {
43 isc_result_t result
= ISC_R_SUCCESS
;
45 RUNTIME_CHECK(isc_once_do(&once
, initialize
) == ISC_R_SUCCESS
);
48 if (timermgr_createfunc
== NULL
)
49 timermgr_createfunc
= createfunc
;
51 result
= ISC_R_EXISTS
;
58 isc_timermgr_createinctx(isc_mem_t
*mctx
, isc_appctx_t
*actx
,
59 isc_timermgr_t
**managerp
)
65 REQUIRE(timermgr_createfunc
!= NULL
);
66 result
= (*timermgr_createfunc
)(mctx
, managerp
);
70 if (result
== ISC_R_SUCCESS
)
71 isc_appctx_settimermgr(actx
, *managerp
);
77 isc_timermgr_create(isc_mem_t
*mctx
, isc_timermgr_t
**managerp
) {
82 REQUIRE(timermgr_createfunc
!= NULL
);
83 result
= (*timermgr_createfunc
)(mctx
, managerp
);
91 isc_timermgr_destroy(isc_timermgr_t
**managerp
) {
92 REQUIRE(*managerp
!= NULL
&& ISCAPI_TIMERMGR_VALID(*managerp
));
94 (*managerp
)->methods
->destroy(managerp
);
96 ENSURE(*managerp
== NULL
);
100 isc_timer_create(isc_timermgr_t
*manager
, isc_timertype_t type
,
101 isc_time_t
*expires
, isc_interval_t
*interval
,
102 isc_task_t
*task
, isc_taskaction_t action
, const void *arg
,
103 isc_timer_t
**timerp
)
105 REQUIRE(ISCAPI_TIMERMGR_VALID(manager
));
107 return (manager
->methods
->timercreate(manager
, type
, expires
,
108 interval
, task
, action
, arg
,
113 isc_timer_attach(isc_timer_t
*timer
, isc_timer_t
**timerp
) {
114 REQUIRE(ISCAPI_TIMER_VALID(timer
));
115 REQUIRE(timerp
!= NULL
&& *timerp
== NULL
);
117 timer
->methods
->attach(timer
, timerp
);
119 ENSURE(*timerp
== timer
);
123 isc_timer_detach(isc_timer_t
**timerp
) {
124 REQUIRE(timerp
!= NULL
&& ISCAPI_TIMER_VALID(*timerp
));
126 (*timerp
)->methods
->detach(timerp
);
128 ENSURE(*timerp
== NULL
);
132 isc_timer_reset(isc_timer_t
*timer
, isc_timertype_t type
,
133 isc_time_t
*expires
, isc_interval_t
*interval
,
136 REQUIRE(ISCAPI_TIMER_VALID(timer
));
138 return (timer
->methods
->reset(timer
, type
, expires
, interval
, purge
));
142 isc_timer_touch(isc_timer_t
*timer
) {
143 REQUIRE(ISCAPI_TIMER_VALID(timer
));
145 return (timer
->methods
->touch(timer
));