AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
callout.c File Reference

Callouts: functions to call at a time to come (see sys/callout.h). More...

#include <core/system.h>
#include <core/arch.h>
#include <sys/callout.h>

Go to the source code of this file.

Functions

void callout_stop (struct callout *c)
 Cancels a callout, if it is pending.
void callout_set_on (struct callout_list *list, struct callout *c, uint64_t ns, void(*fn)(void *), void *arg)
 Sets a callout on a list: fn(arg) will be called once ns ns have passed, by whoever runs the list.
void callout_set (struct callout *c, uint64_t ns, void(*fn)(void *), void *arg)
 Sets a callout on the timer's list: fn(arg) will be called from the timer interrupt once ns ns have passed.
void callout_list_run (struct callout_list *list, uint64_t now)
 Calls the callouts of a list that are due, taking each off the list first.
uint64_t callout_list_next (struct callout_list *list)
 Finds when the first callout of a list is due.
void callout_run (uint64_t now)
 Calls the timer's callouts that are due, from the timer interrupt.

Variables

static struct callout_list timer_callouts

Detailed Description

Callouts: functions to call at a time to come (see sys/callout.h).

Each list of callouts is run from one place only. The timer's list is run by the timer interrupt (sched_timer_tick()), which checks it on every tick. Any other list is run by the thread that owns it, which sleeps until the first callout is due (callout_list_next()): TCP's timers run in the network's thread this way. The caller owns each struct callout, so setting one never allocates and never fails.

Definition in file callout.c.

Function Documentation

◆ callout_list_next()

uint64_t callout_list_next ( struct callout_list * list)

Finds when the first callout of a list is due.

Parameters
listthe list
Returns
the time, in arch_rtime_ns() time, or 0 if the list is empty

Definition at line 115 of file callout.c.

References callout_list_next(), list::head, callout::next, and callout::when.

Referenced by callout_list_next(), and net_main().

◆ callout_list_run()

void callout_list_run ( struct callout_list * list,
uint64_t now )

Calls the callouts of a list that are due, taking each off the list first.

Parameters
listthe list
nowthe time, in arch_rtime_ns() time

Definition at line 86 of file callout.c.

References callout::arg, callout_list_run(), callout::fn, list::head, callout::list, callout::next, NULL, callout::pending, and callout::when.

Referenced by callout_list_run(), callout_run(), and net_main().

◆ callout_run()

void callout_run ( uint64_t now)

Calls the timer's callouts that are due, from the timer interrupt.

Parameters
nowthe time, in arch_rtime_ns() time

Definition at line 131 of file callout.c.

References callout_list_run(), callout_run(), and timer_callouts.

Referenced by callout_run(), and sched_timer_tick().

◆ callout_set()

void callout_set ( struct callout * c,
uint64_t ns,
void(* fn )(void *),
void * arg )

Sets a callout on the timer's list: fn(arg) will be called from the timer interrupt once ns ns have passed.

Parameters
cthe callout
nsthe delay, in ns
fnthe function to call
argits argument

Definition at line 74 of file callout.c.

References callout_set(), callout_set_on(), and timer_callouts.

Referenced by callout_set().

◆ callout_set_on()

void callout_set_on ( struct callout_list * list,
struct callout * c,
uint64_t ns,
void(* fn )(void *),
void * arg )

Sets a callout on a list: fn(arg) will be called once ns ns have passed, by whoever runs the list.

A callout that was pending is cancelled first.

Parameters
listthe list it goes on
cthe callout
nsthe delay, in ns
fnthe function to call
argits argument

Definition at line 50 of file callout.c.

References arch_rtime_ns(), callout::arg, callout_set_on(), callout_stop(), callout::fn, list::head, callout::list, callout::next, callout::pending, and callout::when.

Referenced by callout_set(), callout_set_on(), and net_callout_set().

◆ callout_stop()

void callout_stop ( struct callout * c)

Variable Documentation

◆ timer_callouts

struct callout_list timer_callouts
static

Definition at line 16 of file callout.c.

Referenced by callout_run(), and callout_set().