… | |
… | |
69 | static struct CoroAPI coroapi; |
69 | static struct CoroAPI coroapi; |
70 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
70 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
71 | static HV *coro_state_stash; |
71 | static HV *coro_state_stash; |
72 | static SV *ucoro_state_sv; |
72 | static SV *ucoro_state_sv; |
73 | static U32 ucoro_state_hash; |
73 | static U32 ucoro_state_hash; |
74 | static __thread SV *coro_mortal; /* will be freed after next transfer */ |
74 | static SV *coro_mortal; /* will be freed after next transfer */ |
75 | |
75 | |
76 | /* this is actually not only the c stack but also c registers etc... */ |
76 | /* this is actually not only the c stack but also c registers etc... */ |
77 | typedef struct { |
77 | typedef struct { |
78 | int refcnt; /* pointer reference counter */ |
78 | int refcnt; /* pointer reference counter */ |
79 | int usecnt; /* shared by how many coroutines */ |
79 | int usecnt; /* shared by how many coroutines */ |
… | |
… | |
979 | croak ("Coro::State::_newprocess expects an arrayref"); |
979 | croak ("Coro::State::_newprocess expects an arrayref"); |
980 | |
980 | |
981 | Newz (0, coro, 1, struct coro); |
981 | Newz (0, coro, 1, struct coro); |
982 | |
982 | |
983 | coro->args = (AV *)SvREFCNT_inc (SvRV (args)); |
983 | coro->args = (AV *)SvREFCNT_inc (SvRV (args)); |
984 | coro->mainstack = 0; /* actual work is done inside transfer */ |
984 | /*coro->mainstack = 0; *//*actual work is done inside transfer */ |
985 | coro->stack = 0; |
985 | /*coro->stack = 0;*/ |
986 | |
986 | |
987 | /* same as JMPENV_BOOTSTRAP */ |
987 | /* same as JMPENV_BOOTSTRAP */ |
988 | /* we might be able to recycle start_env, but safe is safe */ |
988 | /* we might be able to recycle start_env, but safe is safe */ |
989 | //Zero(&coro->start_env, 1, JMPENV); |
989 | /*Zero(&coro->start_env, 1, JMPENV);*/ |
990 | coro->start_env.je_ret = -1; |
990 | coro->start_env.je_ret = -1; |
991 | coro->start_env.je_mustcatch = TRUE; |
991 | coro->start_env.je_mustcatch = TRUE; |
992 | |
992 | |
993 | RETVAL = coro; |
993 | RETVAL = coro; |
994 | OUTPUT: |
994 | OUTPUT: |
… | |
… | |
1015 | if (coro->mainstack && coro->mainstack != main_mainstack) |
1015 | if (coro->mainstack && coro->mainstack != main_mainstack) |
1016 | { |
1016 | { |
1017 | struct coro temp; |
1017 | struct coro temp; |
1018 | |
1018 | |
1019 | PUTBACK; |
1019 | PUTBACK; |
1020 | SAVE(aTHX_ (&temp), TRANSFER_SAVE_ALL); |
1020 | SAVE (aTHX_ (&temp), TRANSFER_SAVE_ALL); |
1021 | LOAD(aTHX_ coro); |
1021 | LOAD (aTHX_ coro); |
1022 | SPAGAIN; |
1022 | SPAGAIN; |
1023 | |
1023 | |
1024 | destroy_stacks (aTHX); |
1024 | destroy_stacks (aTHX); |
1025 | |
1025 | |
1026 | LOAD((&temp)); /* this will get rid of defsv etc.. */ |
1026 | LOAD ((&temp)); /* this will get rid of defsv etc.. */ |
1027 | SPAGAIN; |
1027 | SPAGAIN; |
1028 | |
1028 | |
1029 | coro->mainstack = 0; |
1029 | coro->mainstack = 0; |
1030 | } |
1030 | } |
1031 | |
1031 | |
… | |
… | |
1060 | av_clear (defav); |
1060 | av_clear (defav); |
1061 | av_fill (defav, items - 1); |
1061 | av_fill (defav, items - 1); |
1062 | while (items--) |
1062 | while (items--) |
1063 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
1063 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
1064 | |
1064 | |
1065 | mg_get (returnstk); /* isn't documentation wrong for mg_get? */ |
1065 | SvGETMAGIC (returnstk); /* isn't documentation wrong for mg_get? */ |
1066 | sv = av_pop ((AV *)SvRV (returnstk)); |
1066 | sv = av_pop ((AV *)SvRV (returnstk)); |
1067 | prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); |
1067 | prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); |
1068 | next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); |
1068 | next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); |
1069 | SvREFCNT_dec (sv); |
1069 | SvREFCNT_dec (sv); |
1070 | |
1070 | |
1071 | transfer(aTHX_ prev, next, 0); |
1071 | transfer (aTHX_ prev, next, 0); |
1072 | |
1072 | |
1073 | MODULE = Coro::State PACKAGE = Coro |
1073 | MODULE = Coro::State PACKAGE = Coro |
1074 | |
1074 | |
1075 | # this is slightly dirty (should expose a c-level api) |
1075 | # this is slightly dirty (should expose a c-level api) |
1076 | |
1076 | |