AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
callout.c
Go to the documentation of this file.
1
11
12
#include <
core/system.h
>
13
#include <
core/arch.h
>
14
#include <
sys/callout.h
>
15
16
static
struct
callout_list
timer_callouts
;
17
23
void
callout_stop
(
struct
callout
*c)
24
{
25
if
(!c->
pending
)
26
return
;
27
28
for
(
struct
callout
**p = &c->
list
->
head
; *p; p = &(*p)->
next
) {
29
if
(*p == c) {
30
*p = c->
next
;
31
break
;
32
}
33
}
34
35
c->
pending
= 0;
36
c->
list
=
NULL
;
37
}
38
50
void
callout_set_on
(
struct
callout_list
*
list
,
struct
callout
*c,
uint64_t
ns,
51
void
(*fn)(
void
*),
void
*arg)
52
{
53
callout_stop
(c);
54
55
c->
when
=
arch_rtime_ns
() + ns;
56
c->
fn
= fn;
57
c->
arg
= arg;
58
c->
list
=
list
;
59
c->
pending
= 1;
60
61
c->
next
=
list
->
head
;
62
list
->
head
= c;
63
}
64
74
void
callout_set
(
struct
callout
*c,
uint64_t
ns,
void
(*fn)(
void
*),
void
*arg)
75
{
76
callout_set_on
(&
timer_callouts
, c, ns, fn, arg);
77
}
78
86
void
callout_list_run
(
struct
callout_list
*
list
,
uint64_t
now)
87
{
88
struct
callout
**p = &
list
->
head
;
89
90
while
(*p) {
91
struct
callout
*c = *p;
92
93
if
(now < c->
when
) {
94
p = &c->
next
;
95
continue
;
96
}
97
98
/* take it off the list before calling it: it may set itself again */
99
*p = c->
next
;
100
c->
pending
= 0;
101
c->
list
=
NULL
;
102
c->
fn
(c->
arg
);
103
104
/* the function may have changed the list: start over */
105
p = &
list
->
head
;
106
}
107
}
108
115
uint64_t
callout_list_next
(
struct
callout_list
*
list
)
116
{
117
uint64_t
first = 0;
118
119
for
(
struct
callout
*c =
list
->
head
; c; c = c->
next
)
120
if
(!first || c->
when
< first)
121
first = c->
when
;
122
123
return
first;
124
}
125
131
void
callout_run
(
uint64_t
now)
132
{
133
callout_list_run
(&
timer_callouts
, now);
134
}
timer_callouts
static struct callout_list timer_callouts
Definition
callout.c:16
callout.h
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 p...
Definition
callout.c:74
callout_run
void callout_run(uint64_t now)
Calls the timer's callouts that are due, from the timer interrupt.
Definition
callout.c:131
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.
Definition
callout.c:86
callout_list_next
uint64_t callout_list_next(struct callout_list *list)
Finds when the first callout of a list is due.
Definition
callout.c:115
callout_stop
void callout_stop(struct callout *c)
Cancels a callout, if it is pending.
Definition
callout.c:23
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.
Definition
callout.c:50
arch.h
system.h
NULL
#define NULL
Definition
stddef.h:27
uint64_t
unsigned long long int uint64_t
Definition
stddef.h:23
callout_list
A list of callouts called from one context: the timer's interrupt (callout_set()),...
Definition
callout.h:24
callout_list::head
struct callout * head
Definition
callout.h:25
callout
A function to call later, with its argument.
Definition
callout.h:13
callout::arg
void * arg
Definition
callout.h:16
callout::fn
void(*) fn(void *arg)
Definition
callout.h:15
callout::list
struct callout_list * list
Definition
callout.h:18
callout::next
struct callout * next
Definition
callout.h:17
callout::when
uint64_t when
Definition
callout.h:14
callout::pending
int pending
Definition
callout.h:19
list
A list: its first and last nodes, and how many there are.
Definition
list.h:37
list::head
struct list_node * head
Definition
list.h:38
arch_rtime_ns
uint64_t arch_rtime_ns(void)
Reads the monotonic clock, which starts at boot.
Definition
timer.c:56
kernel
sys
callout.c
Generated by
1.18.0