… | |
… | |
21 | | TRANSFER_SAVE_DEFSV \ |
21 | | TRANSFER_SAVE_DEFSV \ |
22 | | TRANSFER_SAVE_ERRSV ) |
22 | | TRANSFER_SAVE_ERRSV ) |
23 | |
23 | |
24 | /*struct coro;*/ /* opaque */ |
24 | /*struct coro;*/ /* opaque */ |
25 | |
25 | |
|
|
26 | /* private structure, always use the provided macros below */ |
26 | struct CoroAPI { |
27 | struct CoroAPI { |
27 | I32 ver; |
28 | I32 ver; |
28 | #define CORO_API_VERSION 2 |
29 | #define CORO_API_VERSION 2 |
29 | #define CORO_API_REVISION 0 |
30 | #define CORO_API_REVISION 0 |
30 | |
31 | |
31 | /* internal */ |
32 | /* internal */ |
32 | /*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/ |
33 | /*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/ |
33 | |
34 | |
34 | /* public, state */ |
35 | /* public API, Coro::State */ |
35 | void (*transfer) (SV *prev, SV *next, int flags); |
36 | void (*transfer) (SV *prev, SV *next, int flags); |
36 | |
37 | |
37 | /* public, coro */ |
38 | /* public API, Coro */ |
38 | void (*schedule) (void); |
39 | void (*schedule) (void); |
39 | void (*cede) (void); |
40 | void (*cede) (void); |
40 | int (*ready) (SV *coro_sv); |
41 | int (*ready) (SV *coro_sv); |
41 | int (*is_ready) (SV *coro_sv); |
42 | int (*is_ready) (SV *coro_sv); |
42 | int *nready; |
43 | int *nready; |
43 | GV *current; |
44 | SV *current; |
44 | }; |
45 | }; |
45 | |
46 | |
46 | static struct CoroAPI *GCoroAPI; |
47 | static struct CoroAPI *GCoroAPI; |
47 | |
48 | |
48 | #define CORO_TRANSFER(prev,next,flags) GCoroAPI->transfer (aTHX_ (prev), (next), (flags)) |
49 | #define CORO_TRANSFER(prev,next,flags) GCoroAPI->transfer (aTHX_ (prev), (next), (flags)) |
49 | #define CORO_SCHEDULE GCoroAPI->schedule () |
50 | #define CORO_SCHEDULE GCoroAPI->schedule () |
50 | #define CORO_CEDE GCoroAPI->cede () |
51 | #define CORO_CEDE GCoroAPI->cede () |
51 | #define CORO_READY(coro) GCoroAPI->ready (coro) |
52 | #define CORO_READY(coro) GCoroAPI->ready (coro) |
52 | #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
53 | #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
53 | #define CORO_NREADY (*GCoroAPI->nready) |
54 | #define CORO_NREADY (*GCoroAPI->nready) |
54 | #define CORO_CURRENT SvRV (GvSV (GCoroAPI->current)) |
55 | #define CORO_CURRENT SvRV (GCoroAPI->current) |
55 | |
56 | |
56 | #define I_CORO_API(YourName) \ |
57 | #define I_CORO_API(YourName) \ |
57 | STMT_START { \ |
58 | STMT_START { \ |
58 | SV *sv = perl_get_sv("Coro::API",0); \ |
59 | SV *sv = perl_get_sv("Coro::API",0); \ |
59 | if (!sv) croak("Coro::API not found"); \ |
60 | if (!sv) croak("Coro::API not found"); \ |