#pragma once #include #include #include #include "list.h" #define OWD_EVENT_READABLE (1 << 0) #define OWD_EVENT_WRITABLE (1 << 1) enum owd_event_source { OWD_EVENT_SOURCE_FD, OWD_EVENT_SOURCE_TIMER, }; typedef struct { uintptr_t obj; enum owd_event_source source; } owd_event_id_t; struct owd_event { owd_event_id_t id; struct intrusive_list list; uintptr_t kqueue_ident; short kqueue_filter; }; struct owd_eventloop { struct intrusive_list event_list; uintptr_t kqueue_timer_next; int kqueue_fd; }; static inline bool owd_event_id_eq(owd_event_id_t eid1, owd_event_id_t eid2) { return (eid1.obj == eid2.obj) && (eid1.source == eid2.source); } int owd_eventloop_init(struct owd_eventloop *el); void owd_eventloop_cleanup(struct owd_eventloop *el); int owd_eventloop_wait(struct owd_eventloop *el, owd_event_id_t *id_out, const struct timespec *timeout); int owd_eventloop_clear(struct owd_eventloop *el, struct owd_event *e); void owd_eventloop_remove(struct owd_eventloop *el, struct owd_event *e); int owd_eventloop_add_timer(struct owd_eventloop *el, struct owd_event *e, uint64_t millis, bool oneshot);