#include <keel/event_ctx.h>
#include <stdint.h>
Go to the source code of this file.
|
| typedef void(* | KlTimerFn) (void *user_data) |
| | Timer callback function.
|
| |
◆ KlTimerFn
| typedef void(* KlTimerFn) (void *user_data) |
Timer callback function.
- Parameters
-
| user_data | Opaque pointer passed to kl_timer_add. |
◆ kl_timer_add()
Schedule a one-shot timer.
The callback fires after delay_ms milliseconds on the event loop thread. Timers are one-shot: the callback can re-add itself via kl_timer_add if repeating behavior is needed.
Safe to call from within a timer callback.
- Parameters
-
| ctx | Event context (owns the timer heap). |
| delay_ms | Delay in milliseconds (0 = fire on next kl_timer_fire). |
| cb | Callback invoked when the timer expires. |
| user_data | Opaque pointer passed to cb. |
- Returns
- Timer ID >= 0 on success, -1 on error.
◆ kl_timer_cancel()
| int kl_timer_cancel |
( |
KlEventCtx * |
ctx, |
|
|
int64_t |
timer_id |
|
) |
| |
Cancel a pending timer.
Safe to call from within a timer callback. No-op if the timer has already fired (IDs are never reused).
- Parameters
-
| ctx | Event context. |
| timer_id | ID returned by kl_timer_add. |
- Returns
- 0 if cancelled, -1 if not found.
◆ kl_timer_next_timeout()
| int kl_timer_next_timeout |
( |
KlEventCtx * |
ctx, |
|
|
int |
max_ms |
|
) |
| |
Compute the timeout for the next kl_event_wait call.
Returns the smaller of max_ms and the time until the next timer fires. Returns 0 if a timer is already overdue. Returns max_ms if no timers are pending.
- Parameters
-
| ctx | Event context. |
| max_ms | Maximum timeout (e.g. KL_POLL_TIMEOUT_MS). |
- Returns
- Clamped timeout in milliseconds.
◆ kl_timer_fire()
Fire all expired timers.
Pops and invokes all timers whose deadline <= kl_monotonic_ms(). Safe for callbacks to add or cancel timers.
- Parameters
-
- Returns
- Number of timers fired.