-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_loop.h
More file actions
39 lines (29 loc) · 736 Bytes
/
event_loop.h
File metadata and controls
39 lines (29 loc) · 736 Bytes
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
#ifndef __EVENT_LOOP_H__
#define __EVENT_LOOP_H__
#include <pthread.h>
typedef enum EL_RES_ {
EL_CONTINUE,
EL_FINISH
} EL_RES_T;
typedef EL_RES_T (*event_cbk)(void*);
typedef struct task_{
event_cbk cbk;
void *arg;
struct task_ *left, *right;
}task_t;
typedef enum{
EV_LOOP_IDLE,
EV_LOOP_BUSY
}EV_LOOP_STATE;
typedef struct event_loop{
struct task_ *task_array_head;
pthread_mutex_t ev_loop_mutex;
EV_LOOP_STATE ev_loop_state;
pthread_cond_t ev_loop_cv;
pthread_t *thread;
struct task_ *current_task;
}event_loop_t;
void event_loop_init(event_loop_t *el);
void event_loop_run(event_loop_t *el);
task_t *task_create_new_job(event_loop_t *el, event_cbk cbk, void *arg);
#endif