… | |
… | |
12 | # define aTHX |
12 | # define aTHX |
13 | #endif |
13 | #endif |
14 | |
14 | |
15 | /*struct coro;*/ /* opaque */ |
15 | /*struct coro;*/ /* opaque */ |
16 | |
16 | |
|
|
17 | enum { |
|
|
18 | CORO_SLF_SCHEDULE = 3, |
|
|
19 | CORO_SLF_CEDE = 4, |
|
|
20 | CORO_SLF_CEDE_NOTSELF = 5 |
|
|
21 | }; |
|
|
22 | |
|
|
23 | struct CoroSLF |
|
|
24 | { |
|
|
25 | int (*prepare) (pTHX_ SV **arg, int items); /* returns CORO_SLF_* */ |
|
|
26 | int (*check) (pTHX); /* returns repeat-flag */ |
|
|
27 | }; |
|
|
28 | |
17 | /* private structure, always use the provided macros below */ |
29 | /* private structure, always use the provided macros below */ |
18 | struct CoroAPI { |
30 | struct CoroAPI |
|
|
31 | { |
19 | I32 ver; |
32 | I32 ver; |
20 | I32 rev; |
33 | I32 rev; |
21 | #define CORO_API_VERSION 6 |
34 | #define CORO_API_VERSION 7 |
22 | #define CORO_API_REVISION 1 |
35 | #define CORO_API_REVISION 0 |
23 | void (*transfer) (SV *prev_sv, SV *next_sv); /* Coro::State */ |
36 | void (*transfer) (pTHX_ SV *prev_sv, SV *next_sv); /* Coro::State */ |
24 | |
37 | |
25 | void (*schedule) (void); /* Coro */ |
38 | void (*schedule) (pTHX); /* Coro */ |
26 | int (*cede) (void); |
39 | int (*cede) (pTHX); |
27 | int (*cede_notself) (void); |
40 | int (*cede_notself) (pTHX); |
28 | int (*ready) (SV *coro_sv); |
41 | int (*ready) (pTHX_ SV *coro_sv); |
29 | int (*is_ready) (SV *coro_sv); |
42 | int (*is_ready) (pTHX_ SV *coro_sv); |
30 | int *nready; |
43 | int nready; |
31 | SV *current; |
44 | SV *current; |
32 | |
45 | |
33 | void (*readyhook) (void); |
46 | void (*readyhook) (void); |
|
|
47 | void (*execute_slf) (pTHX_ struct CoroSLF *slf); |
34 | }; |
48 | }; |
35 | |
49 | |
36 | static struct CoroAPI *GCoroAPI; |
50 | static struct CoroAPI *GCoroAPI; |
37 | |
51 | |
38 | /* public API macros */ |
52 | /* public API macros */ |
39 | #define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next)) |
53 | #define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next)) |
40 | #define CORO_SCHEDULE GCoroAPI->schedule () |
54 | #define CORO_SCHEDULE GCoroAPI->schedule (aTHX) |
41 | #define CORO_CEDE GCoroAPI->cede () |
55 | #define CORO_CEDE GCoroAPI->cede (aTHX) |
42 | #define CORO_CEDE_NOTSELF GCoroAPI->cede_notself () |
56 | #define CORO_CEDE_NOTSELF GCoroAPI->cede_notself (aTHX) |
43 | #define CORO_READY(coro) GCoroAPI->ready (coro) |
57 | #define CORO_READY(coro) GCoroAPI->ready (aTHX_ coro) |
44 | #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
58 | #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
45 | #define CORO_NREADY (*GCoroAPI->nready) |
59 | #define CORO_NREADY GCoroAPI->nready |
46 | #define CORO_CURRENT SvRV (GCoroAPI->current) |
60 | #define CORO_CURRENT SvRV (GCoroAPI->current) |
47 | #define CORO_READYHOOK (GCoroAPI->readyhook) |
61 | #define CORO_READYHOOK GCoroAPI->readyhook |
|
|
62 | #define CORO_EXECUTE_SLF(slf) GCoroAPI->execute_slf (aTHX_ &(slf)) |
48 | |
63 | |
49 | #define I_CORO_API(YourName) \ |
64 | #define I_CORO_API(YourName) \ |
50 | STMT_START { \ |
65 | STMT_START { \ |
51 | SV *sv = perl_get_sv ("Coro::API", 0); \ |
66 | SV *sv = perl_get_sv ("Coro::API", 0); \ |
52 | if (!sv) croak ("Coro::API not found"); \ |
67 | if (!sv) croak ("Coro::API not found"); \ |