continue work on eventloop

This commit is contained in:
pantonshire committed 2025-12-24 22:02:02 +00:00
1 parent 643cc75f67
commit bcf3f8fe18
6 files changed
+215 -70

No files matched your search

+12 -7
View File
@@ -4,13 +4,16 @@
#include <stdbool.h>
#include <time.h>
#include "platform.h"
#include "list.h"
#include "scoped.h"
#define OWD_EVENT_READABLE (1 << 0)
#define OWD_EVENT_WRITABLE (1 << 1)
#if defined(OWD_EVENTLOOP_KQUEUE)
#define OWD_EVENTLOOP_KQUEUE_FILTERS_MAX 2
#endif
enum owd_event_source {
OWD_EVENT_SOURCE_FD,
OWD_EVENT_SOURCE_TIMER,
@@ -25,12 +28,14 @@ struct owd_event {
owd_event_id_t id;
struct intrusive_list list;
#if defined(EVENTLOOP_KQUEUE)
#if defined(OWD_EVENTLOOP_KQUEUE)
uintptr_t kqueue_ident;
short kqueue_filter;
uint16_t kqueue_filters[OWD_EVENTLOOP_KQUEUE_FILTERS_MAX];
uint8_t kqueue_filters_len;
#elif defined(EVENTLOOP_EPOLL)
#elif defined(OWD_EVENTLOOP_EPOLL)
int epoll_registered_fd;
bool epoll_fd_owned;
#endif
};
@@ -38,11 +43,11 @@ struct owd_event {
struct owd_eventloop {
struct intrusive_list event_list;
#if defined(EVENTLOOP_KQUEUE)
#if defined(OWD_EVENTLOOP_KQUEUE)
uintptr_t kqueue_timer_next;
int kqueue_fd;
#elif defined(EVENTLOOP_EPOLL)
#elif defined(OWD_EVENTLOOP_EPOLL)
int epoll_fd;
#endif
@@ -55,7 +60,7 @@ static inline bool owd_event_id_eq(owd_event_id_t eid1, owd_event_id_t eid2) {
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_wait(struct owd_eventloop *el, owd_event_id_t *id_out, uint32_t *flags_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);
+1 -1
View File
@@ -7,6 +7,6 @@ void owd_platform_el_cleanup(struct owd_eventloop *el);
void owd_platform_el_event_remove(struct owd_eventloop *el, struct owd_event *e);
void owd_platform_el_event_cleanup(struct owd_eventloop *el, struct owd_event *e);
int owd_platform_el_event_clear(struct owd_eventloop *el, struct owd_event *e);
int owd_platform_el_wait(struct owd_eventloop *el, owd_event_id_t *id_out, const struct timespec *timeout);
int owd_platform_el_wait(struct owd_eventloop *el, owd_event_id_t *id_out, uint32_t *flags_out, const struct timespec *timeout);
int owd_platform_el_add_timer(struct owd_eventloop *el, struct owd_event *e, uint64_t millis, bool oneshot);
int owd_platform_el_add_fd(struct owd_eventloop *el, struct owd_event *e, int fd, uint32_t flags);
-34
View File
@@ -1,34 +0,0 @@
#pragma once
#if defined(__linux__)
#define PLATFORM_LINUX
#define EVENTLOOP_EPOLL
#elif defined(__APPLE__) && defined(__MACH__)
#define PLATFORM_OSX
#define EVENTLOOP_KQUEUE
#elif defined(__FreeBSD__)
#define PLATFORM_BSD
#define PLATFORM_FREEBSD
#define EVENTLOOP_KQUEUE
#elif defined(__NetBSD__)
#define PLATFORM_BSD
#define PLATFORM_NETBSD
#define EVENTLOOP_KQUEUE
#elif defined(__OpenBSD__)
#define PLATFORM_BSD
#define PLATFORM_OPENBSD
#define EVENTLOOP_KQUEUE
#elif defined(__DragonFly__)
#define PLATFORM_BSD
#define PLATFORM_DRAGONFLY
#define EVENTLOOP_KQUEUE
#else
#error "Failed to detect supported platform"
#endif