-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdco.h
42 lines (32 loc) · 951 Bytes
/
pdco.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
#pragma once
#include <ctype.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#define PDCO_CPPONLY(x) x
#else
#define PDCO_CPPONLY(x)
#endif
#define PDCO_MAIN_ID 1
typedef int pdco_handle_t;
typedef pdco_handle_t(*pdco_fn_t)(pdco_handle_t caller);
// Please note that none of these functions are thread-safe.
// (They are, of course, coroutine-safe.)
// returns handle of current coroutine. In the main coroutine (i.e. thread),
// returns PDCO_MAIN_ID.
pdco_handle_t pdco_current(void);
pdco_handle_t pdco_create(
pdco_fn_t fn,
size_t stacksize PDCO_CPPONLY(=0),
void* ud PDCO_CPPONLY(=NULL)
);
int pdco_exists(pdco_handle_t h);
// pauses execution on this thread and resumes execution on h
// crashes if h is invalid or ended
// returns thread that yields to this thread
pdco_handle_t pdco_yield(pdco_handle_t h);
// gets user-defined local value
void** pdco_ud(pdco_handle_t h);
#ifdef __cplusplus
}
#endif