#pragma once #include "public/typecheck.h" #include "public/eventloop.h" #define TLSL_PLATFORM_EVENT_DATA(EVENT) ({ \ TLSL_CHECK_TYPE(struct tlsl_event *, EVENT); \ TLSL_CHECK_ARRAY((EVENT)->_platform); \ _Static_assert(sizeof((EVENT)->_platform) >= sizeof(struct tlsl_event_platform), \ "event platform buf too small"); \ _Static_assert(__alignof__((EVENT)->_platform) >= __alignof__(struct tlsl_event_platform), \ "event platform buf alignment too small"); \ (struct tlsl_event_platform *)(EVENT->_platform); \ }) #define TLSL_DEFINE_PLATFORM_EVENT_DATA(EVENT, NAME) \ struct tlsl_event_platform *NAME = TLSL_PLATFORM_EVENT_DATA(EVENT) #define TLSL_PLATFORM_EVENTLOOP_DATA(EL) ({ \ TLSL_CHECK_TYPE(struct tlsl_eventloop *, EL); \ TLSL_CHECK_ARRAY((EL)->_platform); \ _Static_assert(sizeof((EL)->_platform) >= sizeof(struct tlsl_eventloop_platform), \ "eventloop platform buf too small"); \ _Static_assert(__alignof__((EL)->_platform) >= __alignof__(struct tlsl_eventloop_platform), \ "eventloop platform buf alignment too small"); \ (struct tlsl_eventloop_platform *)(EL->_platform); \ }) #define TLSL_DEFINE_PLATFORM_EVENTLOOP_DATA(EL, NAME) \ struct tlsl_eventloop_platform *NAME = TLSL_PLATFORM_EVENTLOOP_DATA(EL) struct tlsl_event_platform; struct tlsl_eventloop_platform; int tlsl_platform_el_init(struct tlsl_eventloop *el); void tlsl_platform_el_cleanup(struct tlsl_eventloop *el); void tlsl_platform_el_event_remove(struct tlsl_eventloop *el, struct tlsl_event *e); void tlsl_platform_el_event_cleanup(struct tlsl_eventloop *el, struct tlsl_event *e); int tlsl_platform_el_event_clear(struct tlsl_eventloop *el, struct tlsl_event *e); int tlsl_platform_el_wait(struct tlsl_eventloop *el, tlsl_event_id_t *id_out, uint32_t *flags_out, int timeout_ms); int tlsl_platform_el_add_timer(struct tlsl_eventloop *el, struct tlsl_event *e, uint64_t millis, bool oneshot); int tlsl_platform_el_add_fd(struct tlsl_eventloop *el, struct tlsl_event *e, int fd, uint32_t flags);