-
Notifications
You must be signed in to change notification settings - Fork 12
/
coroutine.h
45 lines (30 loc) · 877 Bytes
/
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
#ifndef H_COROUTINE_H_
#define H_COROUTINE_H_
#include <stdint.h>
class CoroutineScheduler // non copyable
{
public:
typedef uintptr_t (*CoFunc)(void* arg);
enum Status
{
CO_READY,
CO_SUSPENDED,
CO_RUNNING,
CO_FINISHED
};
public:
explicit CoroutineScheduler(int stacksize = 1024);
~CoroutineScheduler();
int DestroyCoroutine(int id);
int CreateCoroutine(CoFunc func, void* arg);
uintptr_t Yield(uintptr_t y = 0);
uintptr_t ResumeCoroutine(int id, uintptr_t y = 0);
bool IsCoroutineAlive(int id) const;
private:
CoroutineScheduler(const CoroutineScheduler&);
CoroutineScheduler& operator=(const CoroutineScheduler&);
private:
class SchedulerImpl;
SchedulerImpl* impl_;
};
#endif