Lines Matching refs:timer

34 #include <isc/timer.h>
66 /*! Locked by timer lock. */
111 schedule(isc_timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
124 REQUIRE(timer->type != isc_timertype_inactive);
130 manager = timer->manager;
144 if (timer->type != isc_timertype_once) {
145 result = isc_time_add(now, &timer->interval, &due);
148 if (timer->type == isc_timertype_limited &&
149 isc_time_compare(&timer->expires, &due) < 0)
150 due = timer->expires;
152 if (isc_time_isepoch(&timer->idle))
153 due = timer->expires;
154 else if (isc_time_isepoch(&timer->expires))
155 due = timer->idle;
156 else if (isc_time_compare(&timer->idle, &timer->expires) < 0)
157 due = timer->idle;
159 due = timer->expires;
163 * Schedule the timer.
166 if (timer->index > 0) {
170 cmp = isc_time_compare(&due, &timer->due);
171 timer->due = due;
174 isc_heap_increased(manager->heap, timer->index);
177 isc_heap_decreased(manager->heap, timer->index);
184 timer->due = due;
185 result = isc_heap_insert(manager->heap, timer);
194 ISC_MSG_SCHEDULE, "schedule"), timer, due);
197 * If this timer is at the head of the queue, we need to ensure
199 * the current "next" timer. We do this either by waking up the
229 if (timer->index == 1 && signal_ok) {
236 if (timer->index == 1 &&
237 isc_time_compare(&timer->due, &manager->due) < 0)
238 manager->due = timer->due;
245 deschedule(isc_timer_t *timer) {
255 manager = timer->manager;
256 if (timer->index > 0) {
258 if (timer->index == 1)
261 isc_heap_delete(manager->heap, timer->index);
262 timer->index = 0;
277 destroy(isc_timer_t *timer) {
278 isc_timermgr_t *manager = timer->manager;
281 * The caller must ensure it is safe to destroy the timer.
286 (void)isc_task_purgerange(timer->task,
287 timer,
291 deschedule(timer);
292 UNLINK(manager->timers, timer, link);
296 isc_task_detach(&timer->task);
297 DESTROYLOCK(&timer->lock);
298 timer->magic = 0;
299 isc_mem_put(manager->mctx, timer, sizeof(*timer));
308 isc_timer_t *timer;
313 * Create a new 'type' timer managed by 'manager'. The timers
316 * called with 'arg' as the arg value. The new timer is returned
348 timer = isc_mem_get(manager->mctx, sizeof(*timer));
349 if (timer == NULL)
352 timer->manager = manager;
353 timer->references = 1;
356 result = isc_time_add(&now, interval, &timer->idle);
358 isc_mem_put(manager->mctx, timer, sizeof(*timer));
362 isc_time_settoepoch(&timer->idle);
364 timer->type = type;
365 timer->expires = *expires;
366 timer->interval = *interval;
367 timer->task = NULL;
368 isc_task_attach(task, &timer->task);
369 timer->action = action;
372 * evils here. If the timer->arg member is made const, then
373 * it affects a great many recipients of the timer event
380 DE_CONST(arg, timer->arg);
381 timer->index = 0;
382 result = isc_mutex_init(&timer->lock);
384 isc_task_detach(&timer->task);
385 isc_mem_put(manager->mctx, timer, sizeof(*timer));
388 ISC_LINK_INIT(timer, link);
389 timer->magic = TIMER_MAGIC;
394 * Note we don't have to lock the timer like we normally would because
399 result = schedule(timer, &now, ISC_TRUE);
403 APPEND(manager->timers, timer, link);
408 timer->magic = 0;
409 DESTROYLOCK(&timer->lock);
410 isc_task_detach(&timer->task);
411 isc_mem_put(manager->mctx, timer, sizeof(*timer));
415 *timerp = timer;
421 isc_timer_reset(isc_timer_t *timer, isc_timertype_t type,
430 * Change the timer's type, expires, and interval values to the given
431 * values. If 'purge' is ISC_TRUE, any pending events from this timer
435 REQUIRE(VALID_TIMER(timer));
436 manager = timer->manager;
463 LOCK(&timer->lock);
466 (void)isc_task_purgerange(timer->task,
467 timer,
471 timer->type = type;
472 timer->expires = *expires;
473 timer->interval = *interval;
475 result = isc_time_add(&now, interval, &timer->idle);
477 isc_time_settoepoch(&timer->idle);
483 deschedule(timer);
486 result = schedule(timer, &now, ISC_TRUE);
489 UNLOCK(&timer->lock);
496 isc_timer_gettype(isc_timer_t *timer) {
499 REQUIRE(VALID_TIMER(timer));
501 LOCK(&timer->lock);
502 t = timer->type;
503 UNLOCK(&timer->lock);
509 isc_timer_touch(isc_timer_t *timer) {
514 * Set the last-touched time of 'timer' to the current time.
517 REQUIRE(VALID_TIMER(timer));
519 LOCK(&timer->lock);
524 * REQUIRE(timer->type == isc_timertype_once);
531 result = isc_time_add(&now, &timer->interval, &timer->idle);
533 UNLOCK(&timer->lock);
539 isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp) {
541 * Attach *timerp to timer.
544 REQUIRE(VALID_TIMER(timer));
547 LOCK(&timer->lock);
548 timer->references++;
549 UNLOCK(&timer->lock);
551 *timerp = timer;
556 isc_timer_t *timer;
560 * Detach *timerp from its timer.
564 timer = *timerp;
565 REQUIRE(VALID_TIMER(timer));
567 LOCK(&timer->lock);
568 REQUIRE(timer->references > 0);
569 timer->references--;
570 if (timer->references == 0)
572 UNLOCK(&timer->lock);
575 destroy(timer);
585 isc_timer_t *timer;
594 timer = isc_heap_element(manager->heap, 1);
595 INSIST(timer != NULL && timer->type != isc_timertype_inactive);
596 if (isc_time_compare(now, &timer->due) >= 0) {
597 if (timer->type == isc_timertype_ticker) {
601 } else if (timer->type == isc_timertype_limited) {
603 cmp = isc_time_compare(now, &timer->expires);
613 } else if (!isc_time_isepoch(&timer->expires) &&
615 &timer->expires) >= 0) {
622 LOCK(&timer->lock);
623 if (!isc_time_isepoch(&timer->idle) &&
625 &timer->idle) >= 0) {
628 UNLOCK(&timer->lock);
635 * Idle timer has been touched;
642 timer);
652 "posting"), timer);
657 timer,
659 timer->action,
660 timer->arg,
664 event->due = timer->due;
665 isc_task_send(timer->task,
676 timer->index = 0;
681 result = schedule(timer, now, ISC_FALSE);
689 "timer"),
693 manager->due = timer->due;
758 isc_timer_t *timer;
760 timer = what;
761 REQUIRE(VALID_TIMER(timer));
763 timer->index = index;
772 * Create a timer manager.
861 * Destroy a timer manager.