diff options
author | Maria Matejka <mq@ucw.cz> | 2021-10-20 23:08:58 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2021-11-22 19:05:43 +0100 |
commit | 6e841b3153565632b6753f6b1fe74850c37f2808 (patch) | |
tree | 2673e3718fec066c90a000c0ad216f62a4de3755 /lib/event.h | |
parent | 94eb0858c2b938549d9d1703c872c6149901e7dd (diff) |
Adding a generic cork mechanism for events
Diffstat (limited to 'lib/event.h')
-rw-r--r-- | lib/event.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/event.h b/lib/event.h index 6c358f84..cd85bf78 100644 --- a/lib/event.h +++ b/lib/event.h @@ -15,6 +15,7 @@ #include <stdatomic.h> DEFINE_DOMAIN(event); +DEFINE_DOMAIN(cork); typedef struct event { resource r; @@ -22,6 +23,8 @@ typedef struct event { void *data; node n; /* Internal link */ struct event_list *list; /* List where this event is put in */ + struct event_cork *cork; /* Event execution limiter */ + node cork_node; } event; typedef struct event_list { @@ -31,6 +34,12 @@ typedef struct event_list { DOMAIN(event) lock; } event_list; +struct event_cork { + DOMAIN(cork) lock; + u32 count; + list events; +}; + extern event_list global_event_list; extern event_list global_work_list; @@ -44,6 +53,13 @@ static inline void ev_init_list(event_list *el, struct birdloop *loop, const cha el->lock = DOMAIN_NEW(event, name); } +static inline void ev_init_cork(struct event_cork *ec, const char *name) +{ + init_list(&ec->events); + ec->lock = DOMAIN_NEW(cork, name); + ec->count = 0; +}; + void ev_send(event_list *, event *); #define ev_send_loop(l, e) ev_send(birdloop_event_list((l)), (e)) @@ -56,6 +72,20 @@ int ev_run_list_limited(event_list *, uint); #define LEGACY_EVENT_LIST(l) (((l) == &global_event_list) || ((l) == &global_work_list)) +void ev_cork(struct event_cork *); +void ev_uncork(struct event_cork *); + +static inline u32 ev_corked(struct event_cork *ec) +{ + if (!ec) + return 0; + + LOCK_DOMAIN(cork, ec->lock); + u32 out = ec->count; + UNLOCK_DOMAIN(cork, ec->lock); + return out; +} + _Bool birdloop_inside(struct birdloop *loop); static inline int |