diff --git a/src/events.c b/src/events.c index ace167f..194e20b 100644 --- a/src/events.c +++ b/src/events.c @@ -277,7 +277,25 @@ void *event_executor_thread(void *arg) { if (read(fill_wake_fd, &val, sizeof(val)) < 0) {} } - /* Keepalive */ + /* Check slot BEFORE keepalive — signal takes priority */ + if (atomic_load_explicit(&slot->state, memory_order_acquire) == EXECUTOR_SLOT_READY) { + signal_entry_t sig = slot->signal; + atomic_store_explicit(&slot->state, EXECUTOR_SLOT_IN_FLIGHT, memory_order_release); + + executor_execute_triangle(exec, &sig); + + atomic_store_explicit(&slot->state, EXECUTOR_SLOT_FREE, memory_order_release); + + /* Keepalive after execution (if still idle) */ + int64_t now = now_mono_ms(); + if (last_keepalive_ms == 0 || now - last_keepalive_ms >= 30000) { + executor_keepalive(exec); + last_keepalive_ms = now_mono_ms(); + } + continue; + } + + /* Keepalive only if slot is not ready */ int64_t now = now_mono_ms(); if (last_keepalive_ms == 0 || now - last_keepalive_ms >= 30000) { executor_keepalive(exec);