| 1 | /* @title: DPCs */ |
| 2 | #pragma once |
| 3 | #include <stdatomic.h> |
| 4 | #include <stdbool.h> |
| 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
| 8 | struct dpc; |
| 9 | typedef void (*dpc_func_t)(void *ctx); |
| 10 | |
| 11 | struct dpc { |
| 12 | dpc_func_t func; |
| 13 | void *ctx; |
| 14 | _Atomic(struct dpc *) next; /* for MPSC push */ |
| 15 | _Atomic bool enqueued; /* prevents double-enqueue */ |
| 16 | }; |
| 17 | |
| 18 | struct dpc_queue { |
| 19 | _Atomic(struct dpc *) head; |
| 20 | _Atomic size_t count; |
| 21 | }; |
| 22 | |
| 23 | /* Per-cpu DPC data */ |
| 24 | struct dpc_cpu { |
| 25 | _Atomic bool ipi_queued; |
| 26 | struct dpc_queue queue; |
| 27 | }; |
| 28 | |
| 29 | void dpc_drain_local(void); |
| 30 | void dpc_run_local(void); |
| 31 | void dpc_run_dpcs_from_irq(void); |
| 32 | struct dpc *dpc_create(dpc_func_t fn, void *ctx); |
| 33 | struct dpc *dpc_init(struct dpc *d, dpc_func_t fn, void *ctx); |
| 34 | void dpc_init_percpu(void); |
| 35 | bool dpc_enqueue_local(struct dpc *d); |
| 36 | bool dpc_enqueue_on_cpu(size_t cpu, struct dpc *d); |
| 37 | |