picofuse

runloop.h
Go to the documentation of this file.
1 
48 #pragma once
49 
50 #include "event.h"
51 #include <stdbool.h>
52 #include <stdint.h>
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
59 // TYPES
60 
71 typedef void (*sys_runloop_init_func_t)(uint8_t worker_index);
72 
78 typedef void (*sys_runloop_event_func_t)(sys_event_t event);
79 
88 typedef void (*sys_runloop_poll_func_t)(void);
89 
99 typedef void (*sys_runloop_exit_func_t)(uint8_t worker_index);
100 
102 // METHODS
103 
129 uint32_t sys_runloop_run(uint8_t num_workers, sys_event_queue_t *queue,
130  sys_runloop_init_func_t init_fn,
131  sys_runloop_event_func_t event_fn,
132  sys_runloop_poll_func_t poll_fn,
133  sys_runloop_exit_func_t exit_fn);
134 
146 void sys_runloop_shutdown(uint32_t exit_value);
147 
159 bool sys_runloop_post(sys_event_t event);
160 
163 #ifdef __cplusplus
164 }
165 #endif
void(* sys_runloop_init_func_t)(uint8_t worker_index)
Per-worker initialisation callback.
Definition: runloop.h:71
uint32_t sys_runloop_run(uint8_t num_workers, sys_event_queue_t *queue, sys_runloop_init_func_t init_fn, sys_runloop_event_func_t event_fn, sys_runloop_poll_func_t poll_fn, sys_runloop_exit_func_t exit_fn)
Start the run loop and block until shutdown.
void(* sys_runloop_exit_func_t)(uint8_t worker_index)
Per-worker exit callback.
Definition: runloop.h:99
bool sys_runloop_post(sys_event_t event)
Post an event to be processed by the run loop.
void(* sys_runloop_event_func_t)(sys_event_t event)
Event handler called on a worker for each posted event.
Definition: runloop.h:78
void(* sys_runloop_poll_func_t)(void)
Optional periodic poll callback invoked by worker 0.
Definition: runloop.h:88
struct sys_event_queue_t sys_event_queue_t
Opaque event queue.
Definition: event.h:75
Defines opaque event queues for producer/consumer coordination.
void * sys_event_t
Event payload stored in a queue.
Definition: event.h:68
void sys_runloop_shutdown(uint32_t exit_value)
Signal the run loop to stop accepting events and exit when drained.