AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
callout.h
Go to the documentation of this file.
1#ifndef _SYS_CALLOUT_H
2#define _SYS_CALLOUT_H
3
4#include <core/system.h>
5
6/*
7 * Callouts (sys/callout.c): functions called later, at a given time. The
8 * caller owns the structure, so arming one allocates nothing and can't
9 * fail.
10 */
11
13struct callout {
14 uint64_t when; /* when to call it, in arch_rtime_ns() time */
15 void (*fn)(void *arg);
16 void *arg;
17 struct callout *next;
18 struct callout_list *list; /* the list it's on, while it's pending */
20};
21
25 struct callout *head;
26};
27
28/* Calls fn(arg) in `ns` nanoseconds, from the timer's interrupt. A
29 * callout that was armed already moves to the new time. */
30void callout_set(struct callout *c, uint64_t ns, void (*fn)(void *), void *arg);
31
32/* The same, but called from whoever runs `list` (callout_list_run()). */
33void callout_set_on(struct callout_list *list, struct callout *c, uint64_t ns,
34 void (*fn)(void *), void *arg);
35
36/* Disarms a callout, if it wasn't called yet. */
37void callout_stop(struct callout *c);
38
39/* Calls the callouts of `list` that are due at `now`. */
41
42/* Returns when the first callout of `list` is due, or 0 if none is
43 * armed. */
45
46/* Calls the timer's callouts that are due, on each tick. */
47void callout_run(uint64_t now);
48
49#endif /* ! _SYS_CALLOUT_H */
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 p...
Definition callout.c:74
void callout_run(uint64_t now)
Calls the timer's callouts that are due, from the timer interrupt.
Definition callout.c:131
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.
Definition callout.c:86
uint64_t callout_list_next(struct callout_list *list)
Finds when the first callout of a list is due.
Definition callout.c:115
void callout_stop(struct callout *c)
Cancels a callout, if it is pending.
Definition callout.c:23
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.
Definition callout.c:50
unsigned long long int uint64_t
Definition stddef.h:23
A list of callouts called from one context: the timer's interrupt (callout_set()),...
Definition callout.h:24
struct callout * head
Definition callout.h:25
A function to call later, with its argument.
Definition callout.h:13
void * arg
Definition callout.h:16
void(*) fn(void *arg)
Definition callout.h:15
struct callout_list * list
Definition callout.h:18
struct callout * next
Definition callout.h:17
uint64_t when
Definition callout.h:14
int pending
Definition callout.h:19
A list: its first and last nodes, and how many there are.
Definition list.h:37