universalisos/microkernel/include/uos_timer_wheel.h
Fábio Coutada 62e8454f91 build: add UEFI ISO builder, test boot scripts, EIM config
- make-uefi-iso.sh: UEFI ISO image builder
- test_boot.S, test_boot.ld: test boot assembly and linker script
- eim_config.toml: EIM (External Interface Module) configuration
- edk2-ovmf RPM for UEFI firmware
- GAP_ANALYSIS_PIKEOS_PARITY.md: PikeOS parity gap analysis
2026-07-15 15:33:07 +01:00

43 lines
1.5 KiB
C

/*
* UniversalisOS Microkernel — Delta-List Timer Wheel
*
* Replaces the O(N) tick scan with an O(1) delta list.
* Each sleeping task is inserted in expiry order. The ISR only
* checks the head — if the head hasn't expired, nothing else has.
*
* Insertion is O(N) worst case (scan to find insertion point),
* but O(1) for the common case (appending at/near the tail).
* For hard RT: switch to a hierarchical timing wheel if >32 timers.
*/
#ifndef UOS_TIMER_WHEEL_H
#define UOS_TIMER_WHEEL_H
#include "uos_types.h"
#include "uos_api.h"
/* Timer wheel — sorted delta list of sleeping tasks */
typedef struct uos_timer_node {
uos_task_t* task; /* Task that's sleeping */
uos_tick_t delta; /* Ticks from previous node (not absolute) */
struct uos_timer_node* next;
} uos_timer_node_t;
/* Per-task timer node storage (static, no malloc) */
void uos_timer_wheel_init(void);
/* Insert a task into the delta list with absolute expiry tick.
* Called with interrupts disabled. O(N) worst case, O(1) typical. */
void uos_timer_wheel_insert(uos_task_t* task, uos_tick_t expiry);
/* Remove a task from the delta list (e.g. on early wake).
* O(N) worst case. */
void uos_timer_wheel_remove(uos_task_t* task);
/* Tick handler: check head only. O(1) when nothing expired. */
void uos_timer_wheel_tick(uos_tick_t now);
#endif /* UOS_TIMER_WHEEL_H */
/* Get next absolute wake tick (for tickless idle).
* Returns 0 if no pending events. */
uos_tick_t uos_timer_wheel_next_wake(void);