/
poller_event.h
52 lines (42 loc) · 1.2 KB
/
poller_event.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
43
44
45
46
47
48
49
50
51
52
#ifndef __H_POLLER_EVENT_
#define __H_POLLER_EVENT_
#include <sys/time.h>
/**
* poller_event describes an event that should happen in the future.
* ms is the number of ms after which the event should occur.
* ctx is the context in which
* action should happen.
*/
struct poller_event {
struct timespec ts;
void *ctx;
void (*action)(void *ctx);
};
struct poller_events {
int max;
int n;
struct poller_event events[];
};
struct poller_events *poller_events_new(int size);
void poller_events_delete(struct poller_events *list);
/**
* poller_events_add adds an event to the event list
*/
void poller_events_add(struct poller_events *list, struct poller_event evt);
/**
* poller_event_pop returns the event with earliest schedule time, and removes it from queue.
*/
struct poller_event poller_events_pop(struct poller_events *list);
/**
* poller_event_pop returns the event with earliest schedule time.
*/
struct poller_event poller_events_peek(struct poller_events *list);
/**
* timespec_cmp compares two struct timespec
*/
int timespec_cmp(struct timespec rhs, struct timespec lhs);
/**
* poller_event_do executes the event
*/
void poller_event_do(struct poller_event evt);
#endif