Lines Matching refs:timer

28 #include <isc/timer.h>
74 /*! Locked by timer lock. */
124 isc__timer_reset(isc_timer_t *timer, isc_timertype_t type,
128 isc_timer_gettype(isc_timer_t *timer);
130 isc__timer_touch(isc_timer_t *timer);
178 schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
191 REQUIRE(timer->type != isc_timertype_inactive);
197 manager = timer->manager;
211 if (timer->type != isc_timertype_once) {
212 result = isc_time_add(now, &timer->interval, &due);
215 if (timer->type == isc_timertype_limited &&
216 isc_time_compare(&timer->expires, &due) < 0)
217 due = timer->expires;
219 if (isc_time_isepoch(&timer->idle))
220 due = timer->expires;
221 else if (isc_time_isepoch(&timer->expires))
222 due = timer->idle;
223 else if (isc_time_compare(&timer->idle, &timer->expires) < 0)
224 due = timer->idle;
226 due = timer->expires;
230 * Schedule the timer.
233 if (timer->index > 0) {
237 cmp = isc_time_compare(&due, &timer->due);
238 timer->due = due;
241 isc_heap_increased(manager->heap, timer->index);
244 isc_heap_decreased(manager->heap, timer->index);
251 timer->due = due;
252 result = isc_heap_insert(manager->heap, timer);
261 ISC_MSG_SCHEDULE, "schedule"), timer, due);
264 * If this timer is at the head of the queue, we need to ensure
266 * the current "next" timer. We do this either by waking up the
296 if (timer->index == 1 && signal_ok) {
303 if (timer->index == 1 &&
304 isc_time_compare(&timer->due, &manager->due) < 0)
305 manager->due = timer->due;
312 deschedule(isc__timer_t *timer) {
322 manager = timer->manager;
323 if (timer->index > 0) {
325 if (timer->index == 1)
328 isc_heap_delete(manager->heap, timer->index);
329 timer->index = 0;
344 destroy(isc__timer_t *timer) {
345 isc__timermgr_t *manager = timer->manager;
348 * The caller must ensure it is safe to destroy the timer.
353 (void)isc_task_purgerange(timer->task,
354 timer,
358 deschedule(timer);
359 UNLINK(manager->timers, timer, link);
363 isc_task_detach(&timer->task);
364 DESTROYLOCK(&timer->lock);
365 timer->common.impmagic = 0;
366 timer->common.magic = 0;
367 isc_mem_put(manager->mctx, timer, sizeof(*timer));
377 isc__timer_t *timer;
382 * Create a new 'type' timer managed by 'manager'. The timers
385 * called with 'arg' as the arg value. The new timer is returned
417 timer = isc_mem_get(manager->mctx, sizeof(*timer));
418 if (timer == NULL)
421 timer->manager = manager;
422 timer->references = 1;
425 result = isc_time_add(&now, interval, &timer->idle);
427 isc_mem_put(manager->mctx, timer, sizeof(*timer));
431 isc_time_settoepoch(&timer->idle);
433 timer->type = type;
434 timer->expires = *expires;
435 timer->interval = *interval;
436 timer->task = NULL;
437 isc_task_attach(task, &timer->task);
438 timer->action = action;
441 * evils here. If the timer->arg member is made const, then
442 * it affects a great many recipients of the timer event
449 DE_CONST(arg, timer->arg);
450 timer->index = 0;
451 result = isc_mutex_init(&timer->lock);
453 isc_task_detach(&timer->task);
454 isc_mem_put(manager->mctx, timer, sizeof(*timer));
457 ISC_LINK_INIT(timer, link);
458 timer->common.impmagic = TIMER_MAGIC;
459 timer->common.magic = ISCAPI_TIMER_MAGIC;
460 timer->common.methods = (isc_timermethods_t *)&timermethods;
465 * Note we don't have to lock the timer like we normally would because
470 result = schedule(timer, &now, ISC_TRUE);
474 APPEND(manager->timers, timer, link);
479 timer->common.impmagic = 0;
480 timer->common.magic = 0;
481 DESTROYLOCK(&timer->lock);
482 isc_task_detach(&timer->task);
483 isc_mem_put(manager->mctx, timer, sizeof(*timer));
487 *timerp = (isc_timer_t *)timer;
497 isc__timer_t *timer = (isc__timer_t *)timer0;
503 * Change the timer's type, expires, and interval values to the given
504 * values. If 'purge' is ISC_TRUE, any pending events from this timer
508 REQUIRE(VALID_TIMER(timer));
509 manager = timer->manager;
536 LOCK(&timer->lock);
539 (void)isc_task_purgerange(timer->task,
540 timer,
544 timer->type = type;
545 timer->expires = *expires;
546 timer->interval = *interval;
548 result = isc_time_add(&now, interval, &timer->idle);
550 isc_time_settoepoch(&timer->idle);
556 deschedule(timer);
559 result = schedule(timer, &now, ISC_TRUE);
562 UNLOCK(&timer->lock);
570 isc__timer_t *timer = (isc__timer_t *)timer0;
573 REQUIRE(VALID_TIMER(timer));
575 LOCK(&timer->lock);
576 t = timer->type;
577 UNLOCK(&timer->lock);
584 isc__timer_t *timer = (isc__timer_t *)timer0;
589 * Set the last-touched time of 'timer' to the current time.
592 REQUIRE(VALID_TIMER(timer));
594 LOCK(&timer->lock);
599 * REQUIRE(timer->type == isc_timertype_once);
606 result = isc_time_add(&now, &timer->interval, &timer->idle);
608 UNLOCK(&timer->lock);
615 isc__timer_t *timer = (isc__timer_t *)timer0;
618 * Attach *timerp to timer.
621 REQUIRE(VALID_TIMER(timer));
624 LOCK(&timer->lock);
625 timer->references++;
626 UNLOCK(&timer->lock);
628 *timerp = (isc_timer_t *)timer;
633 isc__timer_t *timer;
637 * Detach *timerp from its timer.
641 timer = (isc__timer_t *)*timerp;
642 REQUIRE(VALID_TIMER(timer));
644 LOCK(&timer->lock);
645 REQUIRE(timer->references > 0);
646 timer->references--;
647 if (timer->references == 0)
649 UNLOCK(&timer->lock);
652 destroy(timer);
662 isc__timer_t *timer;
671 timer = isc_heap_element(manager->heap, 1);
672 INSIST(timer != NULL && timer->type != isc_timertype_inactive);
673 if (isc_time_compare(now, &timer->due) >= 0) {
674 if (timer->type == isc_timertype_ticker) {
678 } else if (timer->type == isc_timertype_limited) {
680 cmp = isc_time_compare(now, &timer->expires);
690 } else if (!isc_time_isepoch(&timer->expires) &&
692 &timer->expires) >= 0) {
699 LOCK(&timer->lock);
700 if (!isc_time_isepoch(&timer->idle) &&
702 &timer->idle) >= 0) {
705 UNLOCK(&timer->lock);
712 * Idle timer has been touched;
719 timer);
729 "posting"), timer);
734 timer,
736 timer->action,
737 timer->arg,
741 event->due = timer->due;
742 isc_task_send(timer->task,
753 timer->index = 0;
758 result = schedule(timer, now, ISC_FALSE);
766 "timer"),
770 manager->due = timer->due;
839 isc__timer_t *timer;
841 timer = what;
842 REQUIRE(VALID_TIMER(timer));
844 timer->index = index;
853 * Create a timer manager.
917 isc_thread_setname(manager->thread, "isc-timer");
948 * Destroy a timer manager.
1141 isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp) {
1142 REQUIRE(ISCAPI_TIMER_VALID(timer));
1146 isc__timer_attach(timer, timerp);
1148 timer->methods->attach(timer, timerp);
1150 ENSURE(*timerp == timer);
1166 isc_timer_reset(isc_timer_t *timer, isc_timertype_t type,
1170 REQUIRE(ISCAPI_TIMER_VALID(timer));
1173 return (isc__timer_reset(timer, type, expires,
1176 return (timer->methods->reset(timer, type, expires, interval, purge));
1180 isc_timer_touch(isc_timer_t *timer) {
1181 REQUIRE(ISCAPI_TIMER_VALID(timer));
1184 return (isc__timer_touch(timer));
1186 return (timer->methods->touch(timer));