25RCSIDH(timer_h,
"$Id: b57afbaa66f82bb1d24303a7804e42862b132aed $")
31#include <freeradius-devel/util/time.h>
32#include <freeradius-devel/util/misc.h>
33#include <freeradius-devel/util/talloc.h>
39# error _CONST can only be defined in the local header
81#define fr_timer_at(...) _fr_timer_at(NDEBUG_LOCATION_EXP __VA_ARGS__)
87#define fr_timer_in(...) _fr_timer_in(NDEBUG_LOCATION_EXP __VA_ARGS__)
91#define FR_TIMER_DISARM(_ev) \
93 if (likely((_ev) != NULL) && unlikely(fr_timer_disarm(_ev) < 0)) { \
94 fr_assert_msg(0, "Failed to disarm timer %p", (_ev)); \
98#define FR_TIMER_DISARM_RETURN(_ev) \
99 if ((likely(((_ev)) != NULL) && unlikely(!fr_cond_assert_msg(fr_timer_disarm(_ev) == 0, "Failed to disarm timer %p", (_ev))))) return -1;
103#define FR_TIMER_DELETE(_ev_p) \
105 if ((likely((*(_ev_p)) != NULL) && unlikely(fr_timer_delete(_ev_p) < 0))) { \
106 fr_assert_msg(0, "Failed to delete timer %p", *(_ev_p)); \
110#define FR_TIMER_DELETE_RETURN(_ev_p) \
111 if ((likely((*(_ev_p)) != NULL) && unlikely(!fr_cond_assert_msg(fr_timer_delete(_ev_p) == 0, "Failed to delete timer %p", *(_ev_p))))) return -1;
150#ifdef WITH_EVENT_DEBUG
#define NDEBUG_LOCATION_ARGS
Pass caller information to the function.
#define NDEBUG_LOCATION_NONNULL(_num)
int8_t(* fr_cmp_t)(void const *a, void const *b)
struct fr_time_s fr_time_t
"server local" time.
A time delta, a difference in time measured in nanoseconds.
void const * uctx
Context pointer to pass to the callback.
fr_timer_cb_t callback
Callback to execute when the timer fires.
fr_time_t when
When this timer should fire.
bool free_on_fire
Whether to free the event when it fires.
fr_timer_list_t * tl
The event list this timer is part of.
int fr_timer_list_run(fr_timer_list_t *tl, fr_time_t *when)
Execute any pending events in the event loop.
int _fr_timer_in(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, fr_timer_list_t *tl, fr_timer_t **ev, fr_time_delta_t delta, bool free_on_fire, fr_timer_cb_t callback, void const *uctx)
int fr_timer_list_disarm(fr_timer_list_t *tl)
Disarm a timer list.
fr_time_t fr_timer_when(fr_timer_t *ev)
Internal timestamp representing when the timer should fire.
uint64_t fr_timer_list_num_events(fr_timer_list_t *tl)
Return number of pending events.
int _fr_timer_at(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, fr_timer_list_t *tl, fr_timer_t **ev, fr_time_t when, bool free_on_fire, fr_timer_cb_t callback, void const *uctx)
int fr_timer_uctx_insert(fr_timer_list_t *tl, void *uctx)
Insert a uctx into a shared timer, and update the timer.
fr_time_t fr_timer_list_when(fr_timer_list_t *tl)
Return the time of the next event.
fr_timer_list_t * fr_timer_list_ordered_alloc(TALLOC_CTX *ctx, fr_timer_list_t *parent)
Allocate a new sorted event timer list.
bool _fr_timer_armed(fr_timer_t *ev)
Check if a timer event is armed.
fr_time_delta_t fr_timer_remaining(fr_timer_t *ev)
Return time delta between now and when the timer should fire.
int fr_timer_list_force_run(fr_timer_list_t *tl)
Forcibly run all events in an event loop.
fr_timer_list_t * fr_timer_list_shared_alloc(TALLOC_CTX *ctx, fr_timer_list_t *parent, fr_cmp_t cmp, fr_timer_cb_t callback, size_t node_offset, size_t time_offset)
Allocate a new shared event timer list.
fr_timer_list_t * fr_timer_list_lst_alloc(TALLOC_CTX *ctx, fr_timer_list_t *parent)
Allocate a new lst based timer list.
int fr_timer_disarm(fr_timer_t *ev)
Remove an event from the event list, but don't free the memory.
int fr_timer_uctx_remove(fr_timer_list_t *tl, void *uctx)
Remove a uctx from a shared timer.
void fr_timer_list_set_time_func(fr_timer_list_t *tl, fr_event_time_source_t func)
Override event list time source.
fr_time_t(* fr_event_time_source_t)(void)
Alternative time source, useful for testing.
void(* fr_timer_cb_t)(fr_timer_list_t *tl, fr_time_t now, void *uctx)
Called when a timer event fires.
static bool fr_timer_armed(fr_timer_t *ev)
void * fr_timer_uctx_peek(fr_timer_list_t *tl)
int fr_timer_list_arm(fr_timer_list_t *tl)
Arm (or re-arm) a timer list.
int fr_timer_delete(fr_timer_t **ev_p)
Delete a timer event and free its memory.
fr_event_time_source_t _CONST time
Time source this list uses to get the current time when calculating deltas (fr_timer_in).
Public event timer list structure.
fr_time_delta_t time_offset