Lines Matching refs:alarm
138 static void alarm_set_internal(alarm_t* alarm, uint64_t period_ms,
141 static void alarm_cancel_internal(alarm_t* alarm);
142 static void remove_pending_alarm(alarm_t* alarm);
143 static void schedule_next_instance(alarm_t* alarm);
191 void alarm_free(alarm_t* alarm) { in alarm_free() argument
192 if (!alarm) return; in alarm_free()
194 alarm_cancel(alarm); in alarm_free()
196 osi_free((void*)alarm->stats.name); in alarm_free()
197 alarm->closure.~CancelableClosureInStruct(); in alarm_free()
198 osi_free(alarm); in alarm_free()
201 uint64_t alarm_get_remaining_ms(const alarm_t* alarm) { in alarm_get_remaining_ms() argument
202 CHECK(alarm != NULL); in alarm_get_remaining_ms()
207 if (alarm->deadline_ms > just_now_ms) in alarm_get_remaining_ms()
208 remaining_ms = alarm->deadline_ms - just_now_ms; in alarm_get_remaining_ms()
213 void alarm_set(alarm_t* alarm, uint64_t interval_ms, alarm_callback_t cb, in alarm_set() argument
215 alarm_set_internal(alarm, interval_ms, cb, data, default_callback_queue, in alarm_set()
219 void alarm_set_on_mloop(alarm_t* alarm, uint64_t interval_ms, in alarm_set_on_mloop() argument
221 alarm_set_internal(alarm, interval_ms, cb, data, NULL, true); in alarm_set_on_mloop()
225 static void alarm_set_internal(alarm_t* alarm, uint64_t period_ms, in alarm_set_internal() argument
229 CHECK(alarm != NULL); in alarm_set_internal()
234 alarm->creation_time_ms = now_ms(); in alarm_set_internal()
235 alarm->period_ms = period_ms; in alarm_set_internal()
236 alarm->queue = queue; in alarm_set_internal()
237 alarm->callback = cb; in alarm_set_internal()
238 alarm->data = data; in alarm_set_internal()
239 alarm->for_msg_loop = for_msg_loop; in alarm_set_internal()
241 schedule_next_instance(alarm); in alarm_set_internal()
242 alarm->stats.scheduled_count++; in alarm_set_internal()
245 void alarm_cancel(alarm_t* alarm) { in alarm_cancel() argument
247 if (!alarm) return; in alarm_cancel()
252 local_mutex_ref = alarm->callback_mutex; in alarm_cancel()
253 alarm_cancel_internal(alarm); in alarm_cancel()
262 static void alarm_cancel_internal(alarm_t* alarm) { in alarm_cancel_internal() argument
264 (!list_is_empty(alarms) && list_front(alarms) == alarm); in alarm_cancel_internal()
266 remove_pending_alarm(alarm); in alarm_cancel_internal()
268 alarm->deadline_ms = 0; in alarm_cancel_internal()
269 alarm->prev_deadline_ms = 0; in alarm_cancel_internal()
270 alarm->callback = NULL; in alarm_cancel_internal()
271 alarm->data = NULL; in alarm_cancel_internal()
272 alarm->stats.canceled_count++; in alarm_cancel_internal()
273 alarm->queue = NULL; in alarm_cancel_internal()
278 bool alarm_is_scheduled(const alarm_t* alarm) { in alarm_is_scheduled() argument
279 if ((alarms == NULL) || (alarm == NULL)) return false; in alarm_is_scheduled()
280 return (alarm->callback != NULL); in alarm_is_scheduled()
403 static void remove_pending_alarm(alarm_t* alarm) { in remove_pending_alarm() argument
404 list_remove(alarms, alarm); in remove_pending_alarm()
406 if (alarm->for_msg_loop) { in remove_pending_alarm()
407 alarm->closure.i.Cancel(); in remove_pending_alarm()
409 while (fixed_queue_try_remove_from_queue(alarm->queue, alarm) != NULL) { in remove_pending_alarm()
418 static void schedule_next_instance(alarm_t* alarm) { in schedule_next_instance() argument
422 (!list_is_empty(alarms) && list_front(alarms) == alarm); in schedule_next_instance()
423 if (alarm->callback) remove_pending_alarm(alarm); in schedule_next_instance()
428 if ((alarm->is_periodic) && (alarm->period_ms != 0)) in schedule_next_instance()
430 ((just_now_ms - alarm->creation_time_ms) % alarm->period_ms); in schedule_next_instance()
431 alarm->deadline_ms = just_now_ms + (alarm->period_ms - ms_into_period); in schedule_next_instance()
435 ((alarm_t*)list_front(alarms))->deadline_ms > alarm->deadline_ms) { in schedule_next_instance()
436 list_prepend(alarms, alarm); in schedule_next_instance()
442 ((alarm_t*)list_node(next))->deadline_ms > alarm->deadline_ms) { in schedule_next_instance()
443 list_insert_after(alarms, node, alarm); in schedule_next_instance()
452 (!list_is_empty(alarms) && list_front(alarms) == alarm)) { in schedule_next_instance()
556 static void alarm_ready_generic(alarm_t* alarm, in alarm_ready_generic() argument
558 if (alarm == NULL) { in alarm_ready_generic()
567 if (!alarm->callback) { in alarm_ready_generic()
569 << ": timer callback is NULL! Name=" << alarm->stats.name; in alarm_ready_generic()
571 alarm_callback_t callback = alarm->callback; in alarm_ready_generic()
572 void* data = alarm->data; in alarm_ready_generic()
573 uint64_t deadline_ms = alarm->deadline_ms; in alarm_ready_generic()
574 if (alarm->is_periodic) { in alarm_ready_generic()
577 deadline_ms = alarm->prev_deadline_ms; in alarm_ready_generic()
579 alarm->deadline_ms = 0; in alarm_ready_generic()
580 alarm->callback = NULL; in alarm_ready_generic()
581 alarm->data = NULL; in alarm_ready_generic()
582 alarm->queue = NULL; in alarm_ready_generic()
587 std::shared_ptr<std::recursive_mutex> local_mutex_ref = alarm->callback_mutex; in alarm_ready_generic()
592 update_scheduling_stats(&alarm->stats, now_ms(), deadline_ms); in alarm_ready_generic()
599 static void alarm_ready_mloop(alarm_t* alarm) { in alarm_ready_mloop() argument
601 alarm_ready_generic(alarm, lock); in alarm_ready_mloop()
608 alarm_t* alarm = (alarm_t*)fixed_queue_try_dequeue(queue); in alarm_queue_ready() local
609 alarm_ready_generic(alarm, lock); in alarm_queue_ready()
627 alarm_t* alarm; in callback_dispatch() local
633 (alarm = static_cast<alarm_t*>(list_front(alarms)))->deadline_ms > in callback_dispatch()
639 list_remove(alarms, alarm); in callback_dispatch()
641 if (alarm->is_periodic) { in callback_dispatch()
642 alarm->prev_deadline_ms = alarm->deadline_ms; in callback_dispatch()
643 schedule_next_instance(alarm); in callback_dispatch()
644 alarm->stats.rescheduled_count++; in callback_dispatch()
649 if (alarm->for_msg_loop) { in callback_dispatch()
652 alarm->stats.name); in callback_dispatch()
656 alarm->closure.i.Reset(Bind(alarm_ready_mloop, alarm)); in callback_dispatch()
658 FROM_HERE, alarm->closure.i.callback()); in callback_dispatch()
660 fixed_queue_enqueue(alarm->queue, alarm); in callback_dispatch()
744 alarm_t* alarm = (alarm_t*)list_node(node); in alarm_debug_dump() local
745 alarm_stats_t* stats = &alarm->stats; in alarm_debug_dump()
748 (alarm->is_periodic) ? "PERIODIC" : "SINGLE"); in alarm_debug_dump()
761 (unsigned long long)(just_now_ms - alarm->creation_time_ms), in alarm_debug_dump()
762 (unsigned long long)alarm->period_ms, in alarm_debug_dump()
763 (long long)(alarm->deadline_ms - just_now_ms)); in alarm_debug_dump()