-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_source.h
42 lines (34 loc) · 1.12 KB
/
event_source.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef EVENT_SOURCE_H
#define EVENT_SOURCE_H
/* CC0 (Public domain) - see LICENSE file for details */
#include <stdint.h>
#include <stdbool.h>
#include "dl_list.h"
struct event_source {
bool (*check) (struct event_source* event_source);
bool (*dispatch) (struct event_source* event_source);
void (*destructor) (struct event_source* event_source);
int16_t priority;
uint64_t ready_time;
struct dl_list list;
};
typedef struct event_source* event_source;
struct event_source* event_source_new(
bool (*check) (struct event_source* event_source),
bool (*dispatch) (struct event_source* event_source),
uint16_t priority
);
void event_source_init(struct event_source*,
bool (*check) (struct event_source* event_source),
bool (*dispatch) (struct event_source* event_source),
uint16_t priority
);
// void event_source_destroy(struct event_source*);
#define event_source_destroy(this) ({ \
if((this)->destructor) \
(this)->destructor(this); \
})
// event_source event_source_from_list(struct dl_list* list)
#define event_source_from_list(list_entry) \
dl_list_entry((list_entry), struct event_source, list)
#endif