mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 01:31:55 +00:00
Callback: bundling event with its target
This commit is contained in:
parent
4ac55615e4
commit
f5fd70c54a
31
lib/event.h
31
lib/event.h
@ -75,5 +75,36 @@ ev_new_init(pool *p, void (*hook)(void *), void *data)
|
||||
#define ev_new_send(loop, pool, hook, data) \
|
||||
ev_send_loop((loop), ev_new_init((pool), (hook), (data)))
|
||||
|
||||
/* Get birdloop's event list */
|
||||
event_list *birdloop_event_list(struct birdloop *loop);
|
||||
|
||||
typedef struct callback {
|
||||
event event;
|
||||
void (*hook)(struct callback *);
|
||||
struct birdloop *target;
|
||||
} callback;
|
||||
|
||||
static inline void callback_run(void *_c)
|
||||
{
|
||||
struct callback *c = _c;
|
||||
c->hook(c);
|
||||
}
|
||||
|
||||
#define callback_init(_c, _h, _t) \
|
||||
({ \
|
||||
struct callback *_cc = (_c); \
|
||||
*_cc = (struct callback) { \
|
||||
.hook = _h, \
|
||||
.event = (event) { \
|
||||
.hook = callback_run, \
|
||||
.data = _cc, \
|
||||
}, \
|
||||
.target = _t, \
|
||||
}; \
|
||||
})
|
||||
|
||||
#define callback_activate(_c) ev_send_loop(((_c)->target), &((_c)->event))
|
||||
#define callback_is_active(_c) ev_active(&((_c)->event))
|
||||
#define callback_cancel(_c) ev_postpone(&((_c)->event))
|
||||
|
||||
#endif
|
||||
|
@ -40,9 +40,6 @@ void birdloop_stop(struct birdloop *loop, void (*stopped)(void *data), void *dat
|
||||
void birdloop_stop_self(struct birdloop *loop, void (*stopped)(void *data), void *data);
|
||||
void birdloop_free(struct birdloop *loop);
|
||||
|
||||
/* Get birdloop's event list */
|
||||
event_list *birdloop_event_list(struct birdloop *loop);
|
||||
|
||||
/* Run this event in this thread's priority event list */
|
||||
void ev_send_this_thread(event *e);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user