mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-06 01:40:22 -05:00
fdm: add support for managing signals
Add fdm_signal_add() and fdm_signal_del(). Signals added to the fdm will be monitored, and the provided callback called as “soon as possible” from the main context (i.e not from the signal handler context). Monitored signals are *blocked* by default. We use epoll_pwait() to unblock them while we’re polling. This allows us to do race-free signal detection. We use a single handler for all monitored signals; the handler simply updates the signal’s slot in a global array (sized to fit SIGRTMAX signals). When epoll_pwait() returns EINTR, we loop the global array. The callback associated with each signal that fired is called.
This commit is contained in:
parent
ac46e58448
commit
cf1335f258
3 changed files with 147 additions and 26 deletions
8
fdm.h
8
fdm.h
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
struct fdm;
|
||||
|
||||
typedef bool (*fdm_handler_t)(struct fdm *fdm, int fd, int events, void *data);
|
||||
typedef bool (*fdm_fd_handler_t)(struct fdm *fdm, int fd, int events, void *data);
|
||||
typedef bool (*fdm_signal_handler_t)(struct fdm *fdm, int signo, void *data);
|
||||
typedef void (*fdm_hook_t)(struct fdm *fdm, void *data);
|
||||
|
||||
enum fdm_hook_priority {
|
||||
|
|
@ -16,7 +17,7 @@ enum fdm_hook_priority {
|
|||
struct fdm *fdm_init(void);
|
||||
void fdm_destroy(struct fdm *fdm);
|
||||
|
||||
bool fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data);
|
||||
bool fdm_add(struct fdm *fdm, int fd, int events, fdm_fd_handler_t handler, void *data);
|
||||
bool fdm_del(struct fdm *fdm, int fd);
|
||||
bool fdm_del_no_close(struct fdm *fdm, int fd);
|
||||
|
||||
|
|
@ -27,4 +28,7 @@ bool fdm_hook_add(struct fdm *fdm, fdm_hook_t hook, void *data,
|
|||
enum fdm_hook_priority priority);
|
||||
bool fdm_hook_del(struct fdm *fdm, fdm_hook_t hook, enum fdm_hook_priority priority);
|
||||
|
||||
bool fdm_signal_add(struct fdm *fdm, int signo, fdm_signal_handler_t handler, void *data);
|
||||
bool fdm_signal_del(struct fdm *fdm, int signo);
|
||||
|
||||
bool fdm_poll(struct fdm *fdm);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue