forked from 4coder-archive/4coder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4ed_coroutine.h
67 lines (56 loc) · 1.15 KB
/
4ed_coroutine.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
57
58
59
60
61
62
63
64
65
66
67
/*
* Mr. 4th Dimention - Allen Webster
*
* 03.08.2019
*
* Coroutine implementation from thread+mutex+cv
*
*/
// TOP
#if !defined(FRED_COROUTINE_H)
#define FRED_COROUTINE_H
typedef void Coroutine_Function(struct Coroutine *head);
typedef u32 Coroutine_State;
enum{
CoroutineState_Dead,
CoroutineState_Active,
CoroutineState_Inactive,
CoroutineState_Waiting,
};
typedef u32 Coroutine_Type;
enum{
CoroutineType_Uninitialized,
CoroutineType_Root,
CoroutineType_Sub,
};
struct Coroutine{
Coroutine *next;
Thread_Context *tctx;
void *in;
void *out;
System_Thread thread;
System_Condition_Variable cv;
struct Coroutine_Group *sys;
Coroutine_Function *func;
Coroutine *yield_ctx;
Coroutine_State state;
Coroutine_Type type;
void *user_data;
};
struct Coroutine_Group{
Arena arena;
System_Mutex lock;
System_Condition_Variable init_cv;
b32 did_init;
Coroutine *active;
Coroutine *unused;
Coroutine root;
};
////////////////////////////////
typedef i32 Coroutine_Pass_Control;
enum{
CoroutinePassControl_ExitMe,
CoroutinePassControl_BlockMe,
};
#endif
// BOTTOM