#include <config.h>
#include <isc/app.h>
#include <isc/condition.h>
#include <isc/heap.h>
#include <isc/log.h>
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/msgs.h>
#include <isc/once.h>
#include <isc/platform.h>
#include <isc/task.h>
#include <isc/thread.h>
#include <isc/time.h>
#include <isc/timer.h>
#include <isc/util.h>
#include "timer_p.h"
Go to the source code of this file.
Data Structures | |
struct | isc__timer |
struct | isc__timermgr |
struct | isc__timermethods |
struct | isc__timermgrmethods |
Defines | |
#define | USE_SHARED_MANAGER |
#define | XTRACE(s) |
#define | XTRACEID(s, t) |
#define | XTRACETIME(s, d) |
#define | XTRACETIME2(s, d, n) |
#define | XTRACETIMER(s, t, d) |
#define | TIMER_MAGIC ISC_MAGIC('T', 'I', 'M', 'R') |
#define | VALID_TIMER(t) ISC_MAGIC_VALID(t, TIMER_MAGIC) |
#define | TIMER_MANAGER_MAGIC ISC_MAGIC('T', 'I', 'M', 'M') |
#define | VALID_MANAGER(m) ISC_MAGIC_VALID(m, TIMER_MANAGER_MAGIC) |
Typedefs | |
typedef struct isc__timer | isc__timer_t |
typedef struct isc__timermgr | isc__timermgr_t |
Functions | |
isc_result_t | isc__timer_create (isc_timermgr_t *manager, isc_timertype_t type, const isc_time_t *expires, const isc_interval_t *interval, isc_task_t *task, isc_taskaction_t action, void *arg, isc_timer_t **timerp) |
The following are intended for internal use (indicated by "isc__" prefix) but are not declared as static, allowing direct access from unit tests etc. | |
isc_result_t | isc__timer_reset (isc_timer_t *timer, isc_timertype_t type, const isc_time_t *expires, const isc_interval_t *interval, isc_boolean_t purge) |
isc_timertype_t | isc_timer_gettype (isc_timer_t *timer) |
isc_result_t | isc__timer_touch (isc_timer_t *timer) |
void | isc__timer_attach (isc_timer_t *timer0, isc_timer_t **timerp) |
void | isc__timer_detach (isc_timer_t **timerp) |
isc_result_t | isc__timermgr_create (isc_mem_t *mctx, isc_timermgr_t **managerp) |
void | isc_timermgr_poke (isc_timermgr_t *manager0) |
void | isc__timermgr_destroy (isc_timermgr_t **managerp) |
static isc_result_t | schedule (isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) |
static void | deschedule (isc__timer_t *timer) |
static void | destroy (isc__timer_t *timer) |
static void | dispatch (isc__timermgr_t *manager, isc_time_t *now) |
static isc_boolean_t | sooner (void *v1, void *v2) |
static void | set_index (void *what, unsigned int index) |
isc_result_t | isc__timermgr_nextevent (isc_timermgr_t *manager0, isc_time_t *when) |
void | isc__timermgr_dispatch (isc_timermgr_t *manager0) |
isc_result_t | isc__timer_register (void) |
Register a new timer management implementation and add it to the list of supported implementations. This function must be called when a different event library is used than the one contained in the ISC library. | |
static void | initialize (void) |
isc_result_t | isc_timer_register (isc_timermgrcreatefunc_t createfunc) |
A short cut function that specifies the timer management module in the ISC library for isc_timer_register(). An application that uses the ISC library usually do not have to care about this function: it would call isc_lib_register(), which internally calls this function. | |
isc_result_t | isc_timermgr_createinctx (isc_mem_t *mctx, isc_appctx_t *actx, isc_timermgr_t **managerp) |
isc_result_t | isc_timermgr_create (isc_mem_t *mctx, isc_timermgr_t **managerp) |
Create a timer manager. isc_timermgr_createinctx() also associates the new manager with the specified application context. | |
void | isc_timermgr_destroy (isc_timermgr_t **managerp) |
Destroy a timer manager. | |
isc_result_t | isc_timer_create (isc_timermgr_t *manager, isc_timertype_t type, const isc_time_t *expires, const isc_interval_t *interval, isc_task_t *task, isc_taskaction_t action, void *arg, isc_timer_t **timerp) |
Create a new 'type' timer managed by 'manager'. The timers parameters are specified by 'expires' and 'interval'. Events will be posted to 'task' and when dispatched 'action' will be called with 'arg' as the arg value. The new timer is returned in 'timerp'. | |
void | isc_timer_attach (isc_timer_t *timer, isc_timer_t **timerp) |
Attach *timerp to timer. | |
void | isc_timer_detach (isc_timer_t **timerp) |
Detach *timerp from its timer. | |
isc_result_t | isc_timer_reset (isc_timer_t *timer, isc_timertype_t type, const isc_time_t *expires, const isc_interval_t *interval, isc_boolean_t purge) |
Change the timer's type, expires, and interval values to the given values. If 'purge' is TRUE, any pending events from this timer are purged from its task's event queue. | |
isc_result_t | isc_timer_touch (isc_timer_t *timer) |
Set the last-touched time of 'timer' to the current time. | |
Variables | |
static struct isc__timermethods | timermethods |
static struct isc__timermgrmethods | timermgrmethods |
static isc__timermgr_t * | timermgr = NULL |
static isc_mutex_t | createlock |
static isc_once_t | once = ISC_ONCE_INIT |
static isc_timermgrcreatefunc_t | timermgr_createfunc = NULL |
Definition in file timer.c.
#define XTRACEID | ( | s, | |||
t | ) |
#define XTRACETIMER | ( | s, | |||
t, | |||||
d | ) |
#define TIMER_MAGIC ISC_MAGIC('T', 'I', 'M', 'R') |
#define VALID_TIMER | ( | t | ) | ISC_MAGIC_VALID(t, TIMER_MAGIC) |
Definition at line 72 of file timer.c.
Referenced by isc__timer_attach(), isc__timer_detach(), isc__timer_reset(), isc__timer_touch(), isc_timer_gettype(), set_index(), and sooner().
#define TIMER_MANAGER_MAGIC ISC_MAGIC('T', 'I', 'M', 'M') |
#define VALID_MANAGER | ( | m | ) | ISC_MAGIC_VALID(m, TIMER_MANAGER_MAGIC) |
typedef struct isc__timer isc__timer_t |
typedef struct isc__timermgr isc__timermgr_t |
isc_result_t isc__timer_create | ( | isc_timermgr_t * | manager, | |
isc_timertype_t | type, | |||
const isc_time_t * | expires, | |||
const isc_interval_t * | interval, | |||
isc_task_t * | task, | |||
isc_taskaction_t | action, | |||
void * | arg, | |||
isc_timer_t ** | timerp | |||
) |
The following are intended for internal use (indicated by "isc__" prefix) but are not declared as static, allowing direct access from unit tests etc.
Definition at line 379 of file timer.c.
References isc__timer::action, APPEND, isc__timer::arg, isc__timer::common, DE_CONST, DESTROYLOCK, isc__timer::expires, isc__timer::idle, isc_timer::impmagic, isc__timer::index, isc__timer::interval, isc_interval_iszero(), isc_interval_zero, ISC_LINK_INIT, isc_mem_get, isc_mem_put, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_task_attach(), isc_task_detach(), isc_time_add(), isc_time_epoch, isc_time_isepoch(), isc_time_settoepoch(), isc_timertype_inactive, isc_timertype_limited, isc_timertype_once, ISC_TRUE, ISCAPI_TIMER_MAGIC, isc__timermgr::lock, LOCK, isc__timer::lock, isc_timer::magic, isc__timer::manager, isc__timermgr::mctx, isc_timer::methods, now, isc__timer::references, REQUIRE, schedule(), isc__timer::task, TIME_NOW, TIMER_MAGIC, timermethods, isc__timer::type, UNLOCK, and VALID_MANAGER.
Referenced by isc_timer_create().
isc_result_t isc__timer_reset | ( | isc_timer_t * | timer, | |
isc_timertype_t | type, | |||
const isc_time_t * | expires, | |||
const isc_interval_t * | interval, | |||
isc_boolean_t | purge | |||
) |
Definition at line 501 of file timer.c.
References deschedule(), isc__timer::expires, isc__timer::idle, isc__timer::interval, isc_interval_iszero(), isc_interval_zero, ISC_R_SUCCESS, isc_task_purgerange(), isc_time_add(), isc_time_epoch, isc_time_isepoch(), isc_time_settoepoch(), ISC_TIMEREVENT_FIRSTEVENT, ISC_TIMEREVENT_LASTEVENT, isc_timertype_inactive, isc_timertype_limited, isc_timertype_once, ISC_TRUE, isc__timer::lock, isc__timermgr::lock, LOCK, isc__timer::manager, now, REQUIRE, schedule(), isc__timer::task, TIME_NOW, isc__timer::type, UNLOCK, VALID_MANAGER, and VALID_TIMER.
Referenced by isc_timer_reset().
isc_timertype_t isc_timer_gettype | ( | isc_timer_t * | timer | ) |
isc_result_t isc__timer_touch | ( | isc_timer_t * | timer | ) |
Definition at line 591 of file timer.c.
References isc__timer::idle, isc__timer::interval, isc_time_add(), isc__timer::lock, LOCK, now, REQUIRE, TIME_NOW, UNLOCK, and VALID_TIMER.
Referenced by isc_timer_touch().
void isc__timer_attach | ( | isc_timer_t * | timer0, | |
isc_timer_t ** | timerp | |||
) |
Definition at line 622 of file timer.c.
References isc__timer::lock, LOCK, isc__timer::references, REQUIRE, UNLOCK, and VALID_TIMER.
Referenced by isc_timer_attach().
void isc__timer_detach | ( | isc_timer_t ** | timerp | ) |
Definition at line 640 of file timer.c.
References destroy(), ISC_FALSE, ISC_TRUE, isc__timer::lock, LOCK, isc__timer::references, REQUIRE, UNLOCK, and VALID_TIMER.
Referenced by isc_timer_detach().
isc_result_t isc__timermgr_create | ( | isc_mem_t * | mctx, | |
isc_timermgr_t ** | managerp | |||
) |
Definition at line 856 of file timer.c.
References isc__timermgr::common, DESTROYLOCK, isc__timermgr::done, isc_timermgr::impmagic, INIT_LIST, INSIST, isc_condition_destroy, isc_condition_init, ISC_FALSE, isc_heap_create(), isc_heap_destroy(), isc_mem_attach(), isc_mem_detach(), isc_mem_get, isc_mem_put, ISC_MSG_FAILED, isc_msgcat_get(), ISC_MSGSET_GENERAL, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, ISC_R_UNEXPECTED, isc_thread_create(), isc_time_settoepoch(), ISCAPI_TIMERMGR_MAGIC, isc__timermgr::lock, isc_timermgr::magic, isc__timermgr::mctx, isc_timermgr::methods, REQUIRE, run, set_index(), sooner(), TIMER_MANAGER_MAGIC, timermgrmethods, and UNEXPECTED_ERROR.
Referenced by isc__timer_register(), and isc_timermgr_create().
void isc_timermgr_poke | ( | isc_timermgr_t * | manager0 | ) |
void isc__timermgr_destroy | ( | isc_timermgr_t ** | managerp | ) |
Definition at line 950 of file timer.c.
References DESTROYLOCK, EMPTY, isc_timermgr::impmagic, isc__timermgr_dispatch(), isc_condition_destroy, isc_heap_destroy(), isc_mem_detach(), isc_mem_put, ISC_MSG_FAILED, ISC_MSG_SIGNALDESTROY, isc_msgcat_get(), ISC_MSGSET_GENERAL, ISC_MSGSET_TIMER, ISC_R_SUCCESS, isc_thread_join, ISC_TRUE, isc__timermgr::lock, LOCK, isc_timermgr::magic, mctx, REQUIRE, SIGNAL, UNEXPECTED_ERROR, UNLOCK, VALID_MANAGER, and XTRACE.
Referenced by isc_timermgr_destroy().
static isc_result_t schedule | ( | isc__timer_t * | timer, | |
isc_time_t * | now, | |||
isc_boolean_t | signal_ok | |||
) | [inline, static] |
Note: the caller must ensure locking.
Definition at line 186 of file timer.c.
References isc__timer::due, isc__timer::expires, isc__timer::idle, isc__timer::index, INSIST, isc__timer::interval, ISC_FALSE, isc_heap_decreased(), isc_heap_increased(), isc_heap_insert(), isc_interval_set(), isc_lctx, ISC_LOG_WARNING, isc_log_write(), ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_TIMER, ISC_MSG_SCHEDULE, ISC_MSG_SIGNALSCHED, isc_msgcat_get(), ISC_MSGSET_TIMER, ISC_R_NOMEMORY, ISC_R_SUCCESS, ISC_TF, isc_time_add(), isc_time_compare(), isc_time_isepoch(), isc_time_seconds(), isc_timertype_inactive, isc_timertype_limited, isc_timertype_once, isc__timer::manager, REQUIRE, SIGNAL, isc__timer::type, UNUSED, XTRACE, and XTRACETIMER.
Referenced by dispatch(), isc__timer_create(), and isc__timer_reset().
static void deschedule | ( | isc__timer_t * | timer | ) | [inline, static] |
Definition at line 320 of file timer.c.
References isc__timer::index, INSIST, ISC_FALSE, isc_heap_delete(), ISC_MSG_SIGNALDESCHED, isc_msgcat_get(), ISC_MSGSET_TIMER, ISC_TRUE, isc__timer::manager, SIGNAL, and XTRACE.
Referenced by destroy(), and isc__timer_reset().
static void destroy | ( | isc__timer_t * | timer | ) | [static] |
Definition at line 352 of file timer.c.
References isc__timer::common, deschedule(), DESTROYLOCK, isc_timer::impmagic, isc_mem_put, isc_task_detach(), isc_task_purgerange(), ISC_TIMEREVENT_FIRSTEVENT, ISC_TIMEREVENT_LASTEVENT, isc__timer::lock, isc__timermgr::lock, LOCK, isc_timer::magic, isc__timer::manager, isc__timermgr::mctx, isc__timer::task, UNLINK, and UNLOCK.
static void dispatch | ( | isc__timermgr_t * | manager, | |
isc_time_t * | now | |||
) | [static] |
The caller must be holding the manager lock.
Definition at line 666 of file timer.c.
References isc__timer::action, isc__timer::arg, isc__timer::due, isc__timer::expires, isc__timer::idle, isc__timer::index, INSIST, isc_event_allocate(), ISC_EVENT_PTR, ISC_FALSE, isc_heap_delete(), isc_heap_element(), ISC_MSG_EVENTNOTALLOC, ISC_MSG_IDLERESCHED, ISC_MSG_POSTING, ISC_MSG_SCHEDFAIL, isc_msgcat_get(), ISC_MSGSET_TIMER, ISC_R_SUCCESS, isc_task_send(), isc_time_compare(), isc_time_isepoch(), ISC_TIMEREVENT_IDLE, ISC_TIMEREVENT_LIFE, ISC_TIMEREVENT_TICK, isc_timertype_inactive, isc_timertype_limited, isc_timertype_ticker, ISC_TRUE, isc__timer::lock, LOCK, isc__timermgr::mctx, schedule(), isc__timer::task, isc__timer::type, UNEXPECTED_ERROR, UNLOCK, and XTRACEID.
static isc_boolean_t sooner | ( | void * | v1, | |
void * | v2 | |||
) | [static] |
Definition at line 832 of file timer.c.
References isc__timer::due, ISC_FALSE, isc_time_compare(), ISC_TRUE, REQUIRE, and VALID_TIMER.
Referenced by dns_rbtdb_create(), and isc__timermgr_create().
static void set_index | ( | void * | what, | |
unsigned int | index | |||
) | [static] |
Definition at line 846 of file timer.c.
References isc__timer::index, REQUIRE, and VALID_TIMER.
Referenced by dns_rbtdb_create(), and isc__timermgr_create().
isc_result_t isc__timermgr_nextevent | ( | isc_timermgr_t * | manager0, | |
isc_time_t * | when | |||
) |
Definition at line 1023 of file timer.c.
References ISC_R_NOTFOUND, and ISC_R_SUCCESS.
Referenced by evloop().
void isc__timermgr_dispatch | ( | isc_timermgr_t * | manager0 | ) |
Definition at line 1037 of file timer.c.
References dispatch(), and TIME_NOW.
Referenced by evloop(), and isc__timermgr_destroy().
isc_result_t isc__timer_register | ( | void | ) |
Register a new timer management implementation and add it to the list of supported implementations. This function must be called when a different event library is used than the one contained in the ISC library.
Definition at line 1053 of file timer.c.
References isc__timermgr_create(), and isc_timer_register().
Referenced by do_register().
static void initialize | ( | void | ) | [static] |
Definition at line 1062 of file timer.c.
References isc_mutex_init, ISC_R_SUCCESS, and RUNTIME_CHECK.
isc_result_t isc_timer_register | ( | isc_timermgrcreatefunc_t | createfunc | ) |
A short cut function that specifies the timer management module in the ISC library for isc_timer_register(). An application that uses the ISC library usually do not have to care about this function: it would call isc_lib_register(), which internally calls this function.
Definition at line 1067 of file timer.c.
References initialize(), isc_once_do, ISC_R_EXISTS, ISC_R_SUCCESS, LOCK, RUNTIME_CHECK, and UNLOCK.
Referenced by isc__timer_register().
isc_result_t isc_timermgr_createinctx | ( | isc_mem_t * | mctx, | |
isc_appctx_t * | actx, | |||
isc_timermgr_t ** | managerp | |||
) |
Definition at line 1083 of file timer.c.
References isc_appctx_settimermgr(), ISC_R_SUCCESS, LOCK, REQUIRE, and UNLOCK.
Referenced by dns_client_create().
isc_result_t isc_timermgr_create | ( | isc_mem_t * | mctx, | |
isc_timermgr_t ** | managerp | |||
) |
Create a timer manager. isc_timermgr_createinctx() also associates the new manager with the specified application context.
Notes:
Definition at line 1102 of file timer.c.
References isc__timermgr_create(), isc_bind9, LOCK, REQUIRE, and UNLOCK.
Referenced by create_managers(), setup_libs(), and setup_system().
void isc_timermgr_destroy | ( | isc_timermgr_t ** | managerp | ) |
Destroy a timer manager.
Notes:
Definition at line 1119 of file timer.c.
References ENSURE, isc__timermgr_destroy(), isc_bind9, ISCAPI_TIMERMGR_VALID, and REQUIRE.
Referenced by cleanup(), cleanup_managers(), destroy_libs(), destroy_managers(), destroyclient(), and dns_client_create().
isc_result_t isc_timer_create | ( | isc_timermgr_t * | manager, | |
isc_timertype_t | type, | |||
const isc_time_t * | expires, | |||
const isc_interval_t * | interval, | |||
isc_task_t * | task, | |||
isc_taskaction_t | action, | |||
void * | arg, | |||
isc_timer_t ** | timerp | |||
) |
Create a new 'type' timer managed by 'manager'. The timers parameters are specified by 'expires' and 'interval'. Events will be posted to 'task' and when dispatched 'action' will be called with 'arg' as the arg value. The new timer is returned in 'timerp'.
Notes:
Requires:
Definition at line 1131 of file timer.c.
References isc__timer_create(), isc_bind9, ISCAPI_TIMERMGR_VALID, isc_timermgr::methods, REQUIRE, and isc_timermgrmethods_t::timercreate.
Referenced by acache_cleaner_init(), bringup_timer(), cache_cleaner_init(), client_create(), dns_request_createraw4(), dns_request_createvia4(), dns_resolver_create(), dns_zone_link(), dns_zonemgr_managezone(), fctx_create(), isc_ratelimiter_create(), newconnection(), ns_client_send(), run_server(), settimer(), and xfrin_create().
void isc_timer_attach | ( | isc_timer_t * | timer, | |
isc_timer_t ** | timerp | |||
) |
Attach *timerp to timer.
Requires:
Definition at line 1148 of file timer.c.
References isc_timermethods_t::attach, ENSURE, isc__timer_attach(), isc_bind9, ISCAPI_TIMER_VALID, isc_timer::methods, and REQUIRE.
void isc_timer_detach | ( | isc_timer_t ** | timerp | ) |
Detach *timerp from its timer.
Requires:
The timer will be shutdown The timer will detach from its task All resources used by the timer have been freed Any events already posted by the timer will be purged. Therefore, if isc_timer_detach() is called in the context of the timer's task, it is guaranteed that no more timer event callbacks will run after the call. *
Definition at line 1161 of file timer.c.
References ENSURE, isc__timer_detach(), isc_bind9, ISCAPI_TIMER_VALID, and REQUIRE.
Referenced by acache_cleaner_init(), acache_cleaner_shutdown_action(), bringup_timer(), cache_cleaner_init(), cancel_all(), cancel_lookup(), cleaner_shutdown_action(), client_create(), client_delay(), control_timeout(), destroy(), destroy_lookup(), dns_ntatable_covered(), dns_resolver_create(), exit_check(), fctx_destroy(), flush_lookup_list(), force_timeout(), isc_ratelimiter_shutdown(), maybe_free(), maybe_free_connection(), newconnection(), nta_detach(), req_cancel(), req_destroy(), shutdown_server(), xfrin_create(), and zone_shutdown().
isc_result_t isc_timer_reset | ( | isc_timer_t * | timer, | |
isc_timertype_t | type, | |||
const isc_time_t * | expires, | |||
const isc_interval_t * | interval, | |||
isc_boolean_t | purge | |||
) |
Change the timer's type, expires, and interval values to the given values. If 'purge' is TRUE, any pending events from this timer are purged from its task's event queue.
Notes:
Definition at line 1173 of file timer.c.
References isc__timer_reset(), isc_bind9, ISCAPI_TIMER_VALID, isc_timer::methods, REQUIRE, and isc_timermethods_t::reset.
Referenced by dns_acache_setcleaninginterval(), dns_cache_setcleaninginterval(), dns_ntatable_covered(), dns_resolver_shutdown(), dns_timer_setidle(), exit_check(), fctx_sendevents(), fctx_startidletimer(), fctx_starttimer(), fctx_stoptimer(), fetch_done(), isc_ratelimiter_enqueue(), isc_ratelimiter_release(), isc_ratelimiter_setinterval(), isc_ratelimiter_shutdown(), isc_ratelimiter_stall(), load_configuration(), ns_client_settimeout(), nta_detach(), ratelimiter_tick(), recv_done(), set_timer(), spillattimer_countdown(), and zone_settimer().
isc_result_t isc_timer_touch | ( | isc_timer_t * | timer | ) |
Set the last-touched time of 'timer' to the current time.
Requires:
Definition at line 1187 of file timer.c.
References isc__timer_touch(), isc_bind9, ISCAPI_TIMER_VALID, isc_timer::methods, REQUIRE, and isc_timermethods_t::touch.
Referenced by recv_done(), resquery_response(), xfrin_recv_done(), and xfrout_senddone().
struct isc__timermethods timermethods [static] |
Referenced by isc__timer_create().
struct isc__timermgrmethods timermgrmethods [static] |
Referenced by isc__timermgr_create().
isc__timermgr_t* timermgr = NULL [static] |
isc_mutex_t createlock [static] |
isc_once_t once = ISC_ONCE_INIT [static] |
isc_timermgrcreatefunc_t timermgr_createfunc = NULL [static] |