… | |
… | |
3 | |
3 | |
4 | #include "EXTERN.h" |
4 | #include "EXTERN.h" |
5 | #include "perl.h" |
5 | #include "perl.h" |
6 | #include "XSUB.h" |
6 | #include "XSUB.h" |
7 | |
7 | |
|
|
8 | #ifndef pTHX_ |
|
|
9 | # define pTHX_ |
|
|
10 | # define aTHX_ |
|
|
11 | # define pTHX |
|
|
12 | # define aTHX |
|
|
13 | #endif |
|
|
14 | |
8 | /* perl-related */ |
15 | /* perl-related */ |
9 | #define TRANSFER_SAVE_DEFAV 0x00000001 |
16 | #define TRANSFER_SAVE_DEFAV 0x00000001 /* @_ */ |
10 | #define TRANSFER_SAVE_DEFSV 0x00000002 |
17 | #define TRANSFER_SAVE_DEFSV 0x00000002 /* $_ */ |
11 | #define TRANSFER_SAVE_ERRSV 0x00000004 |
18 | #define TRANSFER_SAVE_ERRSV 0x00000004 /* $@ */ |
12 | /* c-related */ |
19 | /* c-related */ |
13 | #define TRANSFER_SAVE_CCTXT 0x00000008 |
20 | #define TRANSFER_SAVE_CCTXT 0x00000100 |
14 | #ifdef CORO_LAZY_STACK |
21 | #ifdef CORO_LAZY_STACK |
15 | # define TRANSFER_LAZY_STACK 0x00000010 |
22 | # define TRANSFER_LAZY_STACK 0x00000200 |
16 | #else |
23 | #else |
17 | # define TRANSFER_LAZY_STACK 0x00000000 |
24 | # define TRANSFER_LAZY_STACK 0x00000000 |
18 | #endif |
25 | #endif |
19 | |
26 | |
20 | #define TRANSFER_SAVE_ALL (TRANSFER_SAVE_DEFAV|TRANSFER_SAVE_DEFSV \ |
27 | #define TRANSFER_SAVE_ALL (TRANSFER_SAVE_DEFAV|TRANSFER_SAVE_DEFSV \ |
… | |
… | |
31 | |
38 | |
32 | /* public, state */ |
39 | /* public, state */ |
33 | void (*transfer)(pTHX_ SV *prev, SV *next, int flags); |
40 | void (*transfer)(pTHX_ SV *prev, SV *next, int flags); |
34 | |
41 | |
35 | /* public, coro */ |
42 | /* public, coro */ |
36 | void (*schedule)(int cede); |
43 | void (*schedule)(void); |
|
|
44 | void (*cede)(void); |
37 | void (*ready)(SV *sv); |
45 | void (*ready)(SV *sv); |
38 | int *nready; |
46 | int *nready; |
39 | GV *current; |
47 | GV *current; |
40 | }; |
48 | }; |
41 | |
49 | |
42 | static struct CoroAPI *GCoroAPI; |
50 | static struct CoroAPI *GCoroAPI; |
43 | |
51 | |
44 | #define CORO_TRANSFER(prev,next) GCoroAPI->transfer(aTHX_ (prev),(next)) |
52 | #define CORO_TRANSFER(prev,next,flags) GCoroAPI->transfer(aTHX_ (prev), (next), (flags)) |
45 | #define CORO_SCHEDULE GCoroAPI->schedule(0) |
53 | #define CORO_SCHEDULE GCoroAPI->schedule () |
46 | #define CORO_CEDE GCoroAPI->schedule(1) |
54 | #define CORO_CEDE GCoroAPI->cede () |
47 | #define CORO_READY(coro) GCoroAPI->ready(coro) |
55 | #define CORO_READY(coro) GCoroAPI->ready (coro) |
48 | #define CORO_NREADY (*GCoroAPI->nready) |
56 | #define CORO_NREADY (*GCoroAPI->nready) |
49 | #define CORO_CURRENT GvSV(GCoroAPI->current) |
57 | #define CORO_CURRENT SvRV(GvSV(GCoroAPI->current)) |
50 | |
58 | |
51 | #define I_CORO_API(YourName) \ |
59 | #define I_CORO_API(YourName) \ |
52 | STMT_START { \ |
60 | STMT_START { \ |
53 | SV *sv = perl_get_sv("Coro::API",0); \ |
61 | SV *sv = perl_get_sv("Coro::API",0); \ |
54 | if (!sv) croak("Coro::API not found"); \ |
62 | if (!sv) croak("Coro::API not found"); \ |