forked from hymanyx/coroutine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coroutine.h
22 lines (16 loc) · 1.01 KB
/
coroutine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef C_COROUTINE_H
#define C_COROUTINE_H
#define COROUTINE_DEAD 0
#define COROUTINE_READY 1
#define COROUTINE_RUNNING 2
#define COROUTINE_SUSPEND 3
struct schedule; // 前置声明协程调度器struct schedule类型
typedef void (*coroutine_func)(struct schedule *, void *ud); // 声明一个函数指针类型
struct schedule * coroutine_open(void); // 创建协程调度器
void coroutine_close(struct schedule *); // 关闭协程调度器
int coroutine_new(struct schedule *, coroutine_func, void *ud); // 创建协程任务,将其加入调度器中
void coroutine_resume(struct schedule *, int id); // 恢复协程号为id的协程任务
int coroutine_status(struct schedule *, int id); // 根据协程任务id返回协程的当前状态
int coroutine_running(struct schedule *); // 返回调度器S中正在running的协程任务id
void coroutine_yield(struct schedule *); // 保存当前上下文后中断当前协程的执行
#endif