separate source files for eventloop implementations
This commit is contained in:
1 parent
e323f42ea3
commit
d4cacfb015
5 files changed
+187
-74
No files matched your search
+21
-1
@@ -4,7 +4,9 @@
|
||||
#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)
|
||||
@@ -22,16 +24,28 @@ typedef struct {
|
||||
struct owd_event {
|
||||
owd_event_id_t id;
|
||||
struct intrusive_list list;
|
||||
|
||||
|
||||
#if defined(EVENTLOOP_KQUEUE)
|
||||
uintptr_t kqueue_ident;
|
||||
short kqueue_filter;
|
||||
|
||||
#elif defined(EVENTLOOP_EPOLL)
|
||||
int epoll_registered_fd;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
struct owd_eventloop {
|
||||
struct intrusive_list event_list;
|
||||
|
||||
#if defined(EVENTLOOP_KQUEUE)
|
||||
uintptr_t kqueue_timer_next;
|
||||
int kqueue_fd;
|
||||
|
||||
#elif defined(EVENTLOOP_EPOLL)
|
||||
int epoll_fd;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline bool owd_event_id_eq(owd_event_id_t eid1, owd_event_id_t eid2) {
|
||||
@@ -45,3 +59,9 @@ int owd_eventloop_wait(struct owd_eventloop *el, owd_event_id_t *id_out, const s
|
||||
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);
|
||||
int owd_eventloop_add_fd(struct owd_eventloop *el, struct owd_event *e, int fd, uint32_t flags);
|
||||
|
||||
DEF_SCOPED_TYPE(eventloop_stack, struct owd_eventloop *, NULL, owd_eventloop_cleanup)
|
||||
|
||||
#define EVENTLOOP_STACK_SCOPED(VAL) SCOPED(eventloop_stack, struct owd_eventloop *, VAL)
|
||||
#define EVENTLOOP_STACK_CLOSE(EL) _scoped_eventloop_stack_cleanup(EL)
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "eventloop.h"
|
||||
|
||||
int owd_platform_el_init(struct owd_eventloop *el);
|
||||
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_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);
|
||||
Reference in new issue
Block a user