-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-queue.h
56 lines (44 loc) · 912 Bytes
/
event-queue.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
53
54
55
56
/**
* Copyright (c) 2018, Tiny Mesh AS - https://tiny-mesh.com
* All rights reserved.
*/
#ifndef EVENT_QUEUE_H_
#define EVENT_QUEUE_H_
#define send_event(ev) queue_insert(ev)
#define event_invalid (event_type) 0
#define event_tick (event_type) 1
#define event_quit (event_type) 2
#define event_input (event_type) 3
#define MAX_EVENT_SIZE 256
#define QUEUE_SIZE 64
typedef int event_type;
typedef struct event {
int type;
void *data;
int size;
} event;
typedef struct queue {
event buffer[QUEUE_SIZE];
// the position for inserting
int pos;
// the position for reading
int head;
int max_size;
} queue;
/**
* Initialize queue
*/
void queue_init();
/**
* Insert item `ev` to end of queue
*/
void queue_insert(event ev);
/**
* Pop the head of the queue
*/
event queue_pop();
/**
* Peek into the head of the queue
*/
event queue_peek();
#endif /* EVENT_QUEUE_H_ */