From efca84e8b5204c4d5ce28113474df0bf0b67dbf3 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 16:55:45 +0300 Subject: Wake and post to loops from any thread, and watch signals wsap_term runs its own eventfds to wake the loop from its pty worker and accessibility threads, and its own signalfd or self-pipe per platform. yasl_loop_kick() is now documented as safe from any thread and from a signal handler. yasl_loop_post() queues a function to run on the owning thread during a later step. yasl_loop_watch_signals() installs a process-wide SA_RESTART handler per signal that records the signal and kicks the loop, so callbacks run on the loop thread on every platform without touching thread masks. Cocoa dispatch waited only for AppKit events, so kicks, posts, and fd watches could not end an indefinite wait, and yasl_post_event() did not wake yasl_run(). While waiting, Cocoa now mirrors the loop's descriptors in a kqueue whose run loop source posts a wake event. If kqueue rejects a descriptor, the wait is bounded to 10 ms. The Cocoa change is not built or run here; it needs a macOS check. Co-Authored-By: Claude Opus 5.5 --- src/common/loop.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/common/loop.h') diff --git a/src/common/loop.h b/src/common/loop.h index 663417a..60c5b64 100644 --- a/src/common/loop.h +++ b/src/common/loop.h @@ -3,7 +3,12 @@ #include "yasl/loop.h" +struct pollfd; + int yasl_loop_next_timeout_ms(const struct yasl_loop *l); +/* The loop's current poll set, valid until the next watch change. Backends + * that wait on native events use it to wake on loop readiness. */ +int yasl_loop_poll_set(const struct yasl_loop *l, const struct pollfd **fds); /* Whether id is armed: added, not deleted, and not retired by its callback. */ bool yasl_loop_timer_armed(const struct yasl_loop *l, yasl_timer_id id); -- cgit v1.2.3