… | |
… | |
31 | |
31 | |
32 | /* public, state */ |
32 | /* public, state */ |
33 | void (*transfer)(pTHX_ SV *prev, SV *next, int flags); |
33 | void (*transfer)(pTHX_ SV *prev, SV *next, int flags); |
34 | |
34 | |
35 | /* public, coro */ |
35 | /* public, coro */ |
36 | void (*schedule)(int cede); |
36 | void (*schedule)(void); |
|
|
37 | void (*cede)(void); |
37 | void (*ready)(SV *sv); |
38 | void (*ready)(SV *sv); |
38 | int *nready; |
39 | int *nready; |
39 | GV *current; |
40 | GV *current; |
40 | }; |
41 | }; |
41 | |
42 | |
42 | static struct CoroAPI *GCoroAPI; |
43 | static struct CoroAPI *GCoroAPI; |
43 | |
44 | |
44 | #define CORO_TRANSFER(prev,next) GCoroAPI->transfer(aTHX_ (prev),(next)) |
45 | #define CORO_TRANSFER(prev,next) GCoroAPI->transfer(aTHX_ (prev),(next)) |
45 | #define CORO_SCHEDULE GCoroAPI->schedule(0) |
46 | #define CORO_SCHEDULE GCoroAPI->schedule() |
46 | #define CORO_CEDE GCoroAPI->schedule(1) |
47 | #define CORO_CEDE GCoroAPI->cede() |
47 | #define CORO_READY(coro) GCoroAPI->ready(coro) |
48 | #define CORO_READY(coro) GCoroAPI->ready(coro) |
48 | #define CORO_NREADY (*GCoroAPI->nready) |
49 | #define CORO_NREADY (*GCoroAPI->nready) |
49 | #define CORO_CURRENT GvSV(GCoroAPI->current) |
50 | #define CORO_CURRENT SvRV(GvSV(GCoroAPI->current)) |
50 | |
51 | |
51 | #define I_CORO_API(YourName) \ |
52 | #define I_CORO_API(YourName) \ |
52 | STMT_START { \ |
53 | STMT_START { \ |
53 | SV *sv = perl_get_sv("Coro::API",0); \ |
54 | SV *sv = perl_get_sv("Coro::API",0); \ |
54 | if (!sv) croak("Coro::API not found"); \ |
55 | if (!sv) croak("Coro::API not found"); \ |