Select one of the symbols to view example projects that use it.
 
Outline
#include "pico/async_context_base.h"
async_context_base_add_at_time_worker(async_context_t *, async_at_time_worker_t *)
async_context_base_remove_at_time_worker(async_context_t *, async_at_time_worker_t *)
async_context_base_add_when_pending_worker(async_context_t *, async_when_pending_worker_t *)
async_context_base_remove_when_pending_worker(async_context_t *, async_when_pending_worker_t *)
async_context_base_remove_ready_at_time_worker(async_context_t *)
async_context_base_refresh_next_timeout(async_context_t *)
async_context_base_execute_once(async_context_t *)
async_context_base_needs_servicing(async_context_t *)
Files
loading...
SourceVuRaspberry Pi Pico SDK and ExamplesPicoSDKsrc/rp2_common/pico_async_context/async_context_base.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * Copyright (c) 2022 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause *//* ... */ #include "pico/async_context_base.h" bool async_context_base_add_at_time_worker(async_context_t *self, async_at_time_worker_t *worker) { async_at_time_worker_t **prev = &self->at_time_list; while (*prev) { if (worker == *prev) { return false; }if (worker == *prev) { ... } prev = &(*prev)->next; }while (*prev) { ... } *prev = worker; worker->next = NULL; return true; }{ ... } bool async_context_base_remove_at_time_worker(async_context_t *self, async_at_time_worker_t *worker) { async_at_time_worker_t **prev = &self->at_time_list; while (*prev) { if (worker == *prev) { *prev = worker->next; return true; }if (worker == *prev) { ... } prev = &(*prev)->next; }while (*prev) { ... } return false; }{ ... } bool async_context_base_add_when_pending_worker(async_context_t *self, async_when_pending_worker_t *worker) { async_when_pending_worker_t **prev = &self->when_pending_list; while (*prev) { if (worker == *prev) { return false; }if (worker == *prev) { ... } prev = &(*prev)->next; }while (*prev) { ... } *prev = worker; worker->next = NULL; return true; }{ ... } bool async_context_base_remove_when_pending_worker(async_context_t *self, async_when_pending_worker_t *worker) { async_when_pending_worker_t **prev = &self->when_pending_list; while (*prev) { if (worker == *prev) { *prev = worker->next; return true; }if (worker == *prev) { ... } prev = &(*prev)->next; }while (*prev) { ... } return false; }{ ... } async_at_time_worker_t *async_context_base_remove_ready_at_time_worker(async_context_t *self) { async_at_time_worker_t **best_prev = NULL; if (self->at_time_list) { absolute_time_t earliest = get_absolute_time(); for (async_at_time_worker_t **prev = &self->at_time_list; *prev; prev = &(*prev)->next) { if (absolute_time_diff_us((*prev)->next_time, earliest) >= 0) { earliest = (*prev)->next_time; assert(!is_at_the_end_of_time(earliest)); // should never be less than now best_prev = prev; }if (absolute_time_diff_us((*prev)->next_time, earliest) >= 0) { ... } }for (async_at_time_worker_t **prev = &self->at_time_list; *prev; prev = &(*prev)->next) { ... } }if (self->at_time_list) { ... } async_at_time_worker_t *rc; if (best_prev) { rc = *best_prev; *best_prev = rc->next; }if (best_prev) { ... } else { rc = NULL; }else { ... } return rc; }{ ... } void async_context_base_refresh_next_timeout(async_context_t *self) { absolute_time_t earliest = at_the_end_of_time; for (async_at_time_worker_t *worker = self->at_time_list; worker; ) { async_at_time_worker_t *next = worker->next; if (absolute_time_diff_us(worker->next_time, earliest) > 0) { earliest = worker->next_time; }if (absolute_time_diff_us(worker->next_time, earliest) > 0) { ... } worker = next; }for (async_at_time_worker_t *worker = self->at_time_list; worker;) { ... } self->next_time = earliest; }{ ... } absolute_time_t async_context_base_execute_once(async_context_t *self) { async_at_time_worker_t *at_time_worker; while (NULL != (at_time_worker = async_context_base_remove_ready_at_time_worker(self))) { at_time_worker->do_work(self, at_time_worker); }while (NULL != (at_time_worker = async_context_base_remove_ready_at_time_worker(self))) { ... } for(async_when_pending_worker_t *when_pending_worker = self->when_pending_list; when_pending_worker; when_pending_worker = when_pending_worker->next) { if (when_pending_worker->work_pending) { when_pending_worker->work_pending = false; when_pending_worker->do_work(self, when_pending_worker); }if (when_pending_worker->work_pending) { ... } }for (async_when_pending_worker_t *when_pending_worker = self->when_pending_list; when_pending_worker; when_pending_worker = when_pending_worker->next) { ... } async_context_base_refresh_next_timeout(self); return self->next_time; }{ ... } bool async_context_base_needs_servicing(async_context_t *self) { absolute_time_t now = get_absolute_time(); if (self->at_time_list) { for (async_at_time_worker_t *worker = self->at_time_list; worker; worker = worker->next) { if (absolute_time_diff_us(worker->next_time, now) >= 0) { return true; }if (absolute_time_diff_us(worker->next_time, now) >= 0) { ... } }for (async_at_time_worker_t *worker = self->at_time_list; worker; worker = worker->next) { ... } }if (self->at_time_list) { ... } for(async_when_pending_worker_t *when_pending_worker = self->when_pending_list; when_pending_worker; when_pending_worker = when_pending_worker->next) { if (when_pending_worker->work_pending) { return true; }if (when_pending_worker->work_pending) { ... } }for (async_when_pending_worker_t *when_pending_worker = self->when_pending_list; when_pending_worker; when_pending_worker = when_pending_worker->next) { ... } return false; }{ ... }
Details
Show:
from
Types: Columns: