![]() |
The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Various types of event timer list. More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/time.h>
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/event.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/util/lst.h>
#include <freeradius-devel/util/rb.h>
Go to the source code of this file.
Data Structures | |
struct | fr_timer_list_s |
An event timer list. More... | |
union | fr_timer_list_s.__unnamed158__ |
struct | fr_timer_list_s.__unnamed158__.shared |
struct | fr_timer_s |
A timer event. More... | |
union | fr_timer_s.__unnamed161__ |
struct | timer_list_funcs_t |
Macros | |
#define | _TIMER_PRIVATE 1 |
#define | CHECK_PARENT(_ev) |
#define | EVENT_ARMED(_ev) ((_ev)->tl != NULL) |
#define | TIMER_UCTX_TO_TIME(_tl, _x) ((fr_time_t *)(((uintptr_t) (_x)) + (_tl)->shared.time_offset)) |
Typedefs | |
typedef struct fr_timer_list_s | fr_timer_list_t |
typedef int(* | timer_disarm_t) (fr_timer_t *ev) |
Specialisation function to delete a timer. | |
typedef int(* | timer_insert_t) (fr_timer_list_t *tl, fr_timer_t *ev) |
Specialisation function to insert a timer. | |
typedef int(* | timer_list_deferred_t) (fr_timer_list_t *tl) |
Process any deferred timer events. | |
typedef fr_timer_t *(* | timer_list_head_t) (fr_timer_list_t *tl) |
Return the soonest timer event. | |
typedef uint64_t(* | timer_list_num_elements_t) (fr_timer_list_t *tl) |
Return the number of elements in the list. | |
typedef int(* | timer_list_run_t) (fr_timer_list_t *tl, fr_time_t *when) |
Specialisation function to execute any pending timers. | |
Enumerations | |
enum | timer_list_type_t { TIMER_LIST_TYPE_LST = 1 , TIMER_LIST_TYPE_ORDERED = 2 , TIMER_LIST_TYPE_SHARED = 3 } |
What type of event list the timer is inserted into. More... | |
Functions | |
bool | _fr_timer_armed (fr_timer_t *ev) |
Check if a timer event is armed. | |
int | _fr_timer_at (NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, fr_timer_list_t *tl, fr_timer_t **ev_p, fr_time_t when, bool free_on_fire, fr_timer_cb_t callback, void const *uctx) |
Insert a timer event into an event list. | |
int | _fr_timer_in (NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, fr_timer_list_t *tl, fr_timer_t **ev_p, fr_time_delta_t delta, bool free_on_fire, fr_timer_cb_t callback, void const *uctx) |
Insert a timer event into an event list. | |
static void | _parent_timer_cb (UNUSED fr_timer_list_t *parent_tl, fr_time_t when, void *uctx) |
This callback fires in the parent to execute events in this sublist. | |
static int | _timer_free (fr_timer_t *ev) |
Remove an event from the event loop. | |
static int | _timer_list_free (fr_timer_list_t *tl) |
Cleanup all timers currently in the list. | |
int | fr_timer_delete (fr_timer_t **ev_p) |
Delete a timer event and free its memory. | |
int | fr_timer_disarm (fr_timer_t *ev) |
Remove an event from the event list, but don't free the memory. | |
int | fr_timer_list_arm (fr_timer_list_t *tl) |
Arm (or re-arm) a timer list. | |
int | fr_timer_list_disarm (fr_timer_list_t *tl) |
Disarm a timer list. | |
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_lst_alloc (TALLOC_CTX *ctx, fr_timer_list_t *parent) |
Allocate a new lst based timer list. | |
uint64_t | fr_timer_list_num_events (fr_timer_list_t *tl) |
Return number of pending events. | |
fr_timer_list_t * | fr_timer_list_ordered_alloc (TALLOC_CTX *ctx, fr_timer_list_t *parent) |
Allocate a new sorted event timer list. | |
int | fr_timer_list_run (fr_timer_list_t *tl, fr_time_t *when) |
Execute any pending events in the event loop. | |
void | fr_timer_list_set_time_func (fr_timer_list_t *tl, fr_event_time_source_t func) |
Override event list time source. | |
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_time_t | fr_timer_list_when (fr_timer_list_t *tl) |
Return the time of the next event. | |
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_uctx_insert (fr_timer_list_t *tl, void *uctx) |
Insert a uctx into a shared timer, and update the timer. | |
void * | fr_timer_uctx_peek (fr_timer_list_t *tl) |
int | fr_timer_uctx_remove (fr_timer_list_t *tl, void *uctx) |
Remove a uctx from a shared timer. | |
fr_time_t | fr_timer_when (fr_timer_t *ev) |
Internal timestamp representing when the timer should fire. | |
static int8_t | timer_cmp (void const *a, void const *b) |
Compare two timer events to see which one should occur first. | |
static fr_timer_list_t * | timer_list_alloc (TALLOC_CTX *ctx, fr_timer_list_t *parent) |
static int | timer_list_lst_deferred (fr_timer_list_t *tl) |
Move all deferred events into the lst. | |
static fr_timer_t * | timer_list_lst_head (fr_timer_list_t *tl) |
Return the head of the lst. | |
static uint64_t | timer_list_lst_num_events (fr_timer_list_t *tl) |
static int | timer_list_lst_run (fr_timer_list_t *tl, fr_time_t *when) |
Run all scheduled timer events in a lst. | |
static int | timer_list_ordered_deferred (fr_timer_list_t *tl) |
Move all deferred events into the ordered event list. | |
static fr_timer_t * | timer_list_ordered_head (fr_timer_list_t *tl) |
Return the head of the ordered list. | |
static uint64_t | timer_list_ordered_num_events (fr_timer_list_t *tl) |
static int | timer_list_ordered_run (fr_timer_list_t *tl, fr_time_t *when) |
Run all scheduled events in an ordered list. | |
static int | timer_list_parent_update (fr_timer_list_t *tl) |
Utility function to update parent timers. | |
static int | timer_list_shared_deferred (fr_timer_list_t *tl) |
Move all deferred events into the shared list. | |
static uint64_t | timer_list_shared_num_events (fr_timer_list_t *tl) |
static int | timer_list_shared_run (fr_timer_list_t *tl, fr_time_t *when) |
Run all scheduled events in an ordered list. | |
static fr_time_t * | timer_list_when (fr_timer_list_t *tl) |
static int | timer_lst_disarm (fr_timer_t *ev) |
static int | timer_lst_insert_at (fr_timer_list_t *tl, fr_timer_t *ev) |
Insert a timer event into a single event timer list. | |
static int | timer_ordered_disarm (fr_timer_t *ev) |
Remove a timer from a timer list, but don't free it. | |
static int | timer_ordered_insert_at (fr_timer_list_t *tl, fr_timer_t *ev) |
Insert an event into an ordered timer list. | |
Variables | |
static timer_list_funcs_t const | timer_funcs [] |
Functions for performing operations on various types of timer list. | |
Various types of event timer list.
Definition in file timer.c.
struct fr_timer_list_s |
Data Fields | ||
---|---|---|
union fr_timer_list_s.__unnamed158__ | __unnamed__ | |
timer_head_t | deferred |
A list of timer events to be inserted, after the current batch has been processed. This prevents "busy" timer loops, where other events may starve, or we may never exit. |
bool | disarmed | the entire timer list is disarmed |
bool | in_handler | Whether we're currently in a callback. |
fr_timer_list_t * | parent | Parent list to insert event into (if any). |
fr_timer_t * | parent_ev | Event in the parent's event loop. |
struct fr_timer_list_pub_s | pub | Public interface to the event timer list. |
timer_list_type_t | type |
union fr_timer_list_s.__unnamed158__ |
Data Fields | ||
---|---|---|
fr_lst_t * | lst | of timer events to be executed. |
timer_head_t | ordered | A list of timer events to be executed. |
struct fr_timer_list_s.__unnamed158__.shared | shared |
struct fr_timer_list_s.__unnamed158__.shared |
Data Fields | ||
---|---|---|
fr_timer_cb_t | callback | the callback to run |
fr_rb_tree_t * | deferred | a tree of deferred things |
size_t | node_offset | offset from uctx to the fr_rb_node it contains |
fr_rb_tree_t * | rb | a tree of raw pointers |
size_t | time_offset | offset from uctx to the fr_time_t it contains |
struct fr_timer_s |
Data Fields | ||
---|---|---|
union fr_timer_s.__unnamed161__ | __unnamed__ | |
fr_timer_cb_t | callback | Callback to execute when the timer fires. |
fr_timer_entry_t | entry | Entry in a list of timer events. |
char const * | file | Source file this event was last updated in. |
bool | free_on_fire | Whether to free the event when it fires. |
int | line | Line this event was last updated on. |
TALLOC_CTX * | linked_ctx | talloc ctx this event was bound to. |
fr_timer_t ** | parent | A pointer to the parent structure containing the timer event. |
fr_timer_list_t * | tl |
The event list this timer is part of. This is set to NULL when an event is disarmed, but all other fields are left intact. |
void const * | uctx | Context pointer to pass to the callback. |
fr_time_t | when | When this timer should fire. |
union fr_timer_s.__unnamed161__ |
Data Fields | ||
---|---|---|
fr_lst_index_t | lst_idx | Where to store opaque lst data, not used for ordered lists. |
fr_dlist_t | ordered_entry | Entry in an ordered list of timer events. |
struct timer_list_funcs_t |
Data Fields | ||
---|---|---|
timer_list_deferred_t | deferred | Function to process deferred events. |
timer_disarm_t | disarm | Function to delete a timer event. |
timer_list_head_t | head | Function to get the head of the list. |
timer_insert_t | insert | Function to insert a timer event. |
timer_list_num_elements_t | num_events | Function to get the number of elements in the list. |
timer_list_run_t | run | Function to run a timer event. |
#define CHECK_PARENT | ( | _ev | ) |
#define TIMER_UCTX_TO_TIME | ( | _tl, | |
_x | |||
) | ((fr_time_t *)(((uintptr_t) (_x)) + (_tl)->shared.time_offset)) |
typedef struct fr_timer_list_s fr_timer_list_t |
typedef int(* timer_disarm_t) (fr_timer_t *ev) |
typedef int(* timer_insert_t) (fr_timer_list_t *tl, fr_timer_t *ev) |
typedef int(* timer_list_deferred_t) (fr_timer_list_t *tl) |
typedef fr_timer_t *(* timer_list_head_t) (fr_timer_list_t *tl) |
typedef uint64_t(* timer_list_num_elements_t) (fr_timer_list_t *tl) |
typedef int(* timer_list_run_t) (fr_timer_list_t *tl, fr_time_t *when) |
Specialisation function to execute any pending timers.
[in] | tl | Timer list to execute. |
[in,out] | when | Our current time, updated to the next event time (i.e. the next time we'll need to run something) |
enum timer_list_type_t |
bool _fr_timer_armed | ( | fr_timer_t * | ev | ) |
int _fr_timer_at | ( | NDEBUG_LOCATION_ARGS TALLOC_CTX * | ctx, |
fr_timer_list_t * | tl, | ||
fr_timer_t ** | ev_p, | ||
fr_time_t | when, | ||
bool | free_on_fire, | ||
fr_timer_cb_t | callback, | ||
void const * | uctx | ||
) |
Insert a timer event into an event list.
[in] | ctx | to bind lifetime of the event to. |
[in] | tl | to insert event into. |
[in,out] | ev_p | If not NULL modify this event instead of creating a new one. This is a parent in a temporal sense, not in a memory structure or dependency sense. |
[in] | when | we should run the event. |
[in] | free_on_fire | Whether event memory should be freed if the event fires. |
[in] | callback | function to execute if the event fires. |
[in] | uctx | user data to pass to the event. |
Definition at line 422 of file timer.c.
int _fr_timer_in | ( | NDEBUG_LOCATION_ARGS TALLOC_CTX * | ctx, |
fr_timer_list_t * | tl, | ||
fr_timer_t ** | ev_p, | ||
fr_time_delta_t | delta, | ||
bool | free_on_fire, | ||
fr_timer_cb_t | callback, | ||
void const * | uctx | ||
) |
Insert a timer event into an event list.
[in] | ctx | to bind lifetime of the event to. |
[in] | tl | to insert event into. |
[in,out] | ev_p | If not NULL modify this event instead of creating a new one. This is a parent in a temporal sense, not in a memory structure or dependency sense. |
[in] | delta | In how many nanoseconds to wait before should we execute the event. |
[in] | callback | function to execute if the event fires. |
[in] | uctx | user data to pass to the event. |
Definition at line 583 of file timer.c.
|
static |
This callback fires in the parent to execute events in this sublist.
[in] | parent_tl | Parent event timer list. |
[in] | when | When the parent timer fired. |
[in] | uctx | Sublist to execute. |
Definition at line 266 of file timer.c.
|
static |
|
static |
int fr_timer_delete | ( | fr_timer_t ** | ev_p | ) |
int fr_timer_disarm | ( | fr_timer_t * | ev | ) |
int fr_timer_list_arm | ( | fr_timer_list_t * | tl | ) |
int fr_timer_list_disarm | ( | fr_timer_list_t * | tl | ) |
int fr_timer_list_force_run | ( | fr_timer_list_t * | tl | ) |
Forcibly run all events in an event loop.
This is used to forcefully run every event in the event loop.
We pass in the real time, which may theoretically cause issues if timer callbacks are checking... But the uses of this function are very limited.
Definition at line 920 of file timer.c.
fr_timer_list_t * fr_timer_list_lst_alloc | ( | TALLOC_CTX * | ctx, |
fr_timer_list_t * | parent | ||
) |
uint64_t fr_timer_list_num_events | ( | fr_timer_list_t * | tl | ) |
fr_timer_list_t * fr_timer_list_ordered_alloc | ( | TALLOC_CTX * | ctx, |
fr_timer_list_t * | parent | ||
) |
int fr_timer_list_run | ( | fr_timer_list_t * | tl, |
fr_time_t * | when | ||
) |
Execute any pending events in the event loop.
[in] | tl | to execute events in. |
[in] | when | Process events scheduled to run before or at this time.
|
Definition at line 938 of file timer.c.
void fr_timer_list_set_time_func | ( | fr_timer_list_t * | tl, |
fr_event_time_source_t | func | ||
) |
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.
[in] | ctx | to allocate the event timer list from. |
[in] | parent | to insert the head timer event into. |
[in] | cmp | comparison routine (smaller times are earlier) |
[in] | callback | to run on timer event |
[in] | node_offset | offset from uctx to the fr_rb_node_t it contains |
[in] | time_offset | offset from uctx to the fr_time_t it contains |
Definition at line 1308 of file timer.c.
fr_time_t fr_timer_list_when | ( | fr_timer_list_t * | tl | ) |
fr_time_delta_t fr_timer_remaining | ( | fr_timer_t * | ev | ) |
int fr_timer_uctx_insert | ( | fr_timer_list_t * | tl, |
void * | uctx | ||
) |
void * fr_timer_uctx_peek | ( | fr_timer_list_t * | tl | ) |
int fr_timer_uctx_remove | ( | fr_timer_list_t * | tl, |
void * | uctx | ||
) |
Remove a uctx from a shared timer.
[in] | tl | Timer list to insert into. |
[in] | uctx | to remove |
Definition at line 1367 of file timer.c.
fr_time_t fr_timer_when | ( | fr_timer_t * | ev | ) |
|
static |
Compare two timer events to see which one should occur first.
[in] | a | the first timer event. |
[in] | b | the second timer event. |
Definition at line 252 of file timer.c.
|
static |
|
static |
|
static |
|
static |
|
static |
Run all scheduled timer events in a lst.
[in] | tl | containing the timer events. |
[in] | when | Process events scheduled to run before or at this time.
|
Definition at line 758 of file timer.c.
|
static |
|
static |
|
static |
|
static |
Run all scheduled events in an ordered list.
[in] | tl | containing the timer events. |
[in] | when | Process events scheduled to run before or at this time.
|
Definition at line 817 of file timer.c.
|
inlinestatic |
|
static |
|
static |
|
static |
Run all scheduled events in an ordered list.
[in] | tl | containing the timer events. |
[in] | when | Process events scheduled to run before or at this time.
|
Definition at line 876 of file timer.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Functions for performing operations on various types of timer list.