… | |
… | |
101 | # define CvISXSUB_on(cv) (void)cv |
101 | # define CvISXSUB_on(cv) (void)cv |
102 | #endif |
102 | #endif |
103 | #ifndef CvISXSUB |
103 | #ifndef CvISXSUB |
104 | # define CvISXSUB(cv) (CvXSUB (cv) ? TRUE : FALSE) |
104 | # define CvISXSUB(cv) (CvXSUB (cv) ? TRUE : FALSE) |
105 | #endif |
105 | #endif |
|
|
106 | #ifndef Newx |
|
|
107 | # define Newx(ptr,nitems,type) New (0,ptr,nitems,type) |
|
|
108 | #endif |
106 | |
109 | |
107 | /* 5.8.7 */ |
110 | /* 5.8.7 */ |
108 | #ifndef SvRV_set |
111 | #ifndef SvRV_set |
109 | # define SvRV_set(s,v) SvRV(s) = (v) |
112 | # define SvRV_set(s,v) SvRV(s) = (v) |
110 | #endif |
113 | #endif |
… | |
… | |
225 | int valgrind_id; |
228 | int valgrind_id; |
226 | #endif |
229 | #endif |
227 | unsigned char flags; |
230 | unsigned char flags; |
228 | } coro_cctx; |
231 | } coro_cctx; |
229 | |
232 | |
|
|
233 | coro_cctx *cctx_current; /* the currently running cctx */ |
|
|
234 | |
|
|
235 | /*****************************************************************************/ |
|
|
236 | |
230 | enum { |
237 | enum { |
231 | CF_RUNNING = 0x0001, /* coroutine is running */ |
238 | CF_RUNNING = 0x0001, /* coroutine is running */ |
232 | CF_READY = 0x0002, /* coroutine is ready */ |
239 | CF_READY = 0x0002, /* coroutine is ready */ |
233 | CF_NEW = 0x0004, /* has never been switched to */ |
240 | CF_NEW = 0x0004, /* has never been switched to */ |
234 | CF_DESTROYED = 0x0008, /* coroutine data has been freed */ |
241 | CF_DESTROYED = 0x0008, /* coroutine data has been freed */ |
… | |
… | |
347 | GV *gvp; |
354 | GV *gvp; |
348 | return sv_2cv (sv, &st, &gvp, 0); |
355 | return sv_2cv (sv, &st, &gvp, 0); |
349 | } |
356 | } |
350 | |
357 | |
351 | static AV * |
358 | static AV * |
352 | coro_clone_padlist (pTHX_ CV *cv) |
359 | coro_derive_padlist (pTHX_ CV *cv) |
353 | { |
360 | { |
354 | AV *padlist = CvPADLIST (cv); |
361 | AV *padlist = CvPADLIST (cv); |
355 | AV *newpadlist, *newpad; |
362 | AV *newpadlist, *newpad; |
356 | |
363 | |
357 | newpadlist = newAV (); |
364 | newpadlist = newAV (); |
… | |
… | |
477 | CV *cp = Perl_cv_clone (aTHX_ cv); |
484 | CV *cp = Perl_cv_clone (aTHX_ cv); |
478 | CvPADLIST (cv) = CvPADLIST (cp); |
485 | CvPADLIST (cv) = CvPADLIST (cp); |
479 | CvPADLIST (cp) = 0; |
486 | CvPADLIST (cp) = 0; |
480 | SvREFCNT_dec (cp); |
487 | SvREFCNT_dec (cp); |
481 | #else |
488 | #else |
482 | CvPADLIST (cv) = coro_clone_padlist (aTHX_ cv); |
489 | CvPADLIST (cv) = coro_derive_padlist (aTHX_ cv); |
483 | #endif |
490 | #endif |
484 | } |
491 | } |
485 | } |
492 | } |
486 | |
493 | |
487 | static void |
494 | static void |
… | |
… | |
901 | slf_frame.prepare = prepare_nop; /* provide a nop function for an eventual pp_slf */ |
908 | slf_frame.prepare = prepare_nop; /* provide a nop function for an eventual pp_slf */ |
902 | slf_frame.check = slf_check_nop; /* signal pp_slf to not repeat */ |
909 | slf_frame.check = slf_check_nop; /* signal pp_slf to not repeat */ |
903 | |
910 | |
904 | /* and we have to provide the pp_slf op in any case, so pp_slf can skip it */ |
911 | /* and we have to provide the pp_slf op in any case, so pp_slf can skip it */ |
905 | coro_setup_op.op_next = PL_op; |
912 | coro_setup_op.op_next = PL_op; |
906 | coro_setup_op.op_type = OP_CUSTOM; |
913 | coro_setup_op.op_type = OP_ENTERSUB; |
907 | coro_setup_op.op_ppaddr = pp_slf; |
914 | coro_setup_op.op_ppaddr = pp_slf; |
908 | /* no flags etc. required, as an init function won't be called */ |
915 | /* no flags etc. required, as an init function won't be called */ |
909 | |
916 | |
910 | PL_op = (OP *)&coro_setup_op; |
917 | PL_op = (OP *)&coro_setup_op; |
911 | |
918 | |
… | |
… | |
964 | static int |
971 | static int |
965 | runops_trace (pTHX) |
972 | runops_trace (pTHX) |
966 | { |
973 | { |
967 | COP *oldcop = 0; |
974 | COP *oldcop = 0; |
968 | int oldcxix = -2; |
975 | int oldcxix = -2; |
969 | struct coro *coro = SvSTATE_current; /* trace cctx is tied to specific coro */ |
|
|
970 | coro_cctx *cctx = coro->cctx; |
|
|
971 | |
976 | |
972 | while ((PL_op = CALL_FPTR (PL_op->op_ppaddr) (aTHX))) |
977 | while ((PL_op = CALL_FPTR (PL_op->op_ppaddr) (aTHX))) |
973 | { |
978 | { |
974 | PERL_ASYNC_CHECK (); |
979 | PERL_ASYNC_CHECK (); |
975 | |
980 | |
976 | if (cctx->flags & CC_TRACE_ALL) |
981 | if (cctx_current->flags & CC_TRACE_ALL) |
977 | { |
982 | { |
978 | if (PL_op->op_type == OP_LEAVESUB && cctx->flags & CC_TRACE_SUB) |
983 | if (PL_op->op_type == OP_LEAVESUB && cctx_current->flags & CC_TRACE_SUB) |
979 | { |
984 | { |
980 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
985 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
981 | SV **bot, **top; |
986 | SV **bot, **top; |
982 | AV *av = newAV (); /* return values */ |
987 | AV *av = newAV (); /* return values */ |
983 | SV **cb; |
988 | SV **cb; |
… | |
… | |
1020 | |
1025 | |
1021 | if (PL_curcop != &PL_compiling) |
1026 | if (PL_curcop != &PL_compiling) |
1022 | { |
1027 | { |
1023 | SV **cb; |
1028 | SV **cb; |
1024 | |
1029 | |
1025 | if (oldcxix != cxstack_ix && cctx->flags & CC_TRACE_SUB) |
1030 | if (oldcxix != cxstack_ix && cctx_current->flags & CC_TRACE_SUB) |
1026 | { |
1031 | { |
1027 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
1032 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
1028 | |
1033 | |
1029 | if (CxTYPE (cx) == CXt_SUB && oldcxix < cxstack_ix) |
1034 | if (CxTYPE (cx) == CXt_SUB && oldcxix < cxstack_ix) |
1030 | { |
1035 | { |
1031 | runops_proc_t old_runops = PL_runops; |
|
|
1032 | dSP; |
1036 | dSP; |
1033 | GV *gv = CvGV (cx->blk_sub.cv); |
1037 | GV *gv = CvGV (cx->blk_sub.cv); |
1034 | SV *fullname = sv_2mortal (newSV (0)); |
1038 | SV *fullname = sv_2mortal (newSV (0)); |
1035 | |
1039 | |
1036 | if (isGV (gv)) |
1040 | if (isGV (gv)) |
… | |
… | |
1054 | } |
1058 | } |
1055 | |
1059 | |
1056 | oldcxix = cxstack_ix; |
1060 | oldcxix = cxstack_ix; |
1057 | } |
1061 | } |
1058 | |
1062 | |
1059 | if (cctx->flags & CC_TRACE_LINE) |
1063 | if (cctx_current->flags & CC_TRACE_LINE) |
1060 | { |
1064 | { |
1061 | dSP; |
1065 | dSP; |
1062 | |
1066 | |
1063 | PL_runops = RUNOPS_DEFAULT; |
1067 | PL_runops = RUNOPS_DEFAULT; |
1064 | ENTER; |
1068 | ENTER; |
… | |
… | |
1083 | |
1087 | |
1084 | TAINT_NOT; |
1088 | TAINT_NOT; |
1085 | return 0; |
1089 | return 0; |
1086 | } |
1090 | } |
1087 | |
1091 | |
1088 | static struct coro_cctx *cctx_ssl_cctx; |
|
|
1089 | static struct CoroSLF cctx_ssl_frame; |
1092 | static struct CoroSLF cctx_ssl_frame; |
1090 | |
1093 | |
1091 | static void |
1094 | static void |
1092 | slf_prepare_set_stacklevel (pTHX_ struct coro_transfer_args *ta) |
1095 | slf_prepare_set_stacklevel (pTHX_ struct coro_transfer_args *ta) |
1093 | { |
1096 | { |
1094 | ta->prev = (struct coro *)cctx_ssl_cctx; |
|
|
1095 | ta->next = 0; |
1097 | ta->prev = 0; |
1096 | } |
1098 | } |
1097 | |
1099 | |
1098 | static int |
1100 | static int |
1099 | slf_check_set_stacklevel (pTHX_ struct CoroSLF *frame) |
1101 | slf_check_set_stacklevel (pTHX_ struct CoroSLF *frame) |
1100 | { |
1102 | { |
… | |
… | |
1103 | return frame->check (aTHX_ frame); /* execute the restored frame - there must be one */ |
1105 | return frame->check (aTHX_ frame); /* execute the restored frame - there must be one */ |
1104 | } |
1106 | } |
1105 | |
1107 | |
1106 | /* initialises PL_top_env and injects a pseudo-slf-call to set the stacklevel */ |
1108 | /* initialises PL_top_env and injects a pseudo-slf-call to set the stacklevel */ |
1107 | static void NOINLINE |
1109 | static void NOINLINE |
1108 | cctx_prepare (pTHX_ coro_cctx *cctx) |
1110 | cctx_prepare (pTHX) |
1109 | { |
1111 | { |
1110 | PL_top_env = &PL_start_env; |
1112 | PL_top_env = &PL_start_env; |
1111 | |
1113 | |
1112 | if (cctx->flags & CC_TRACE) |
1114 | if (cctx_current->flags & CC_TRACE) |
1113 | PL_runops = runops_trace; |
1115 | PL_runops = runops_trace; |
1114 | |
1116 | |
1115 | /* we already must be executing an SLF op, there is no other valid way |
1117 | /* we already must be executing an SLF op, there is no other valid way |
1116 | * that can lead to creation of a new cctx */ |
1118 | * that can lead to creation of a new cctx */ |
1117 | assert (("FATAL: can't prepare slf-less cctx in Coro module (please report)", |
1119 | assert (("FATAL: can't prepare slf-less cctx in Coro module (please report)", |
1118 | slf_frame.prepare && PL_op->op_ppaddr == pp_slf)); |
1120 | slf_frame.prepare && PL_op->op_ppaddr == pp_slf)); |
1119 | |
1121 | |
1120 | /* we must emulate leaving pp_slf, which is done inside slf_check_set_stacklevel */ |
1122 | /* we must emulate leaving pp_slf, which is done inside slf_check_set_stacklevel */ |
1121 | cctx_ssl_cctx = cctx; |
|
|
1122 | cctx_ssl_frame = slf_frame; |
1123 | cctx_ssl_frame = slf_frame; |
1123 | |
1124 | |
1124 | slf_frame.prepare = slf_prepare_set_stacklevel; |
1125 | slf_frame.prepare = slf_prepare_set_stacklevel; |
1125 | slf_frame.check = slf_check_set_stacklevel; |
1126 | slf_frame.check = slf_check_set_stacklevel; |
1126 | } |
1127 | } |
… | |
… | |
1149 | /* normally we would need to skip the entersub here */ |
1150 | /* normally we would need to skip the entersub here */ |
1150 | /* not doing so will re-execute it, which is exactly what we want */ |
1151 | /* not doing so will re-execute it, which is exactly what we want */ |
1151 | /* PL_nop = PL_nop->op_next */ |
1152 | /* PL_nop = PL_nop->op_next */ |
1152 | |
1153 | |
1153 | /* inject a fake subroutine call to cctx_init */ |
1154 | /* inject a fake subroutine call to cctx_init */ |
1154 | cctx_prepare (aTHX_ (coro_cctx *)arg); |
1155 | cctx_prepare (aTHX); |
1155 | |
1156 | |
1156 | /* cctx_run is the alternative tail of transfer() */ |
1157 | /* cctx_run is the alternative tail of transfer() */ |
1157 | transfer_tail (aTHX); |
1158 | transfer_tail (aTHX); |
1158 | |
1159 | |
1159 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
1160 | /* somebody or something will hit me for both perl_run and PL_restartop */ |
… | |
… | |
1254 | cctx_destroy (coro_cctx *cctx) |
1255 | cctx_destroy (coro_cctx *cctx) |
1255 | { |
1256 | { |
1256 | if (!cctx) |
1257 | if (!cctx) |
1257 | return; |
1258 | return; |
1258 | |
1259 | |
|
|
1260 | assert (cctx != cctx_current);//D temporary |
|
|
1261 | |
1259 | --cctx_count; |
1262 | --cctx_count; |
1260 | coro_destroy (&cctx->cctx); |
1263 | coro_destroy (&cctx->cctx); |
1261 | |
1264 | |
1262 | /* coro_transfer creates new, empty cctx's */ |
1265 | /* coro_transfer creates new, empty cctx's */ |
1263 | if (cctx->sptr) |
1266 | if (cctx->sptr) |
… | |
… | |
1348 | transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) |
1351 | transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) |
1349 | { |
1352 | { |
1350 | dSTACKLEVEL; |
1353 | dSTACKLEVEL; |
1351 | |
1354 | |
1352 | /* sometimes transfer is only called to set idle_sp */ |
1355 | /* sometimes transfer is only called to set idle_sp */ |
1353 | if (expect_false (!next)) |
1356 | if (expect_false (!prev)) |
1354 | { |
1357 | { |
1355 | ((coro_cctx *)prev)->idle_sp = STACKLEVEL; |
1358 | cctx_current->idle_sp = STACKLEVEL; |
1356 | assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ |
1359 | assert (cctx_current->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ |
1357 | } |
1360 | } |
1358 | else if (expect_true (prev != next)) |
1361 | else if (expect_true (prev != next)) |
1359 | { |
1362 | { |
1360 | coro_cctx *prev__cctx; |
1363 | coro_cctx *cctx_prev; |
1361 | |
1364 | |
1362 | if (expect_false (prev->flags & CF_NEW)) |
1365 | if (expect_false (prev->flags & CF_NEW)) |
1363 | { |
1366 | { |
1364 | /* create a new empty/source context */ |
1367 | /* create a new empty/source context */ |
1365 | prev->cctx = cctx_new_empty (); |
|
|
1366 | prev->flags &= ~CF_NEW; |
1368 | prev->flags &= ~CF_NEW; |
1367 | prev->flags |= CF_RUNNING; |
1369 | prev->flags |= CF_RUNNING; |
1368 | } |
1370 | } |
1369 | |
1371 | |
1370 | prev->flags &= ~CF_RUNNING; |
1372 | prev->flags &= ~CF_RUNNING; |
… | |
… | |
1381 | coro_setup (aTHX_ next); |
1383 | coro_setup (aTHX_ next); |
1382 | } |
1384 | } |
1383 | else |
1385 | else |
1384 | load_perl (aTHX_ next); |
1386 | load_perl (aTHX_ next); |
1385 | |
1387 | |
1386 | prev__cctx = prev->cctx; |
1388 | assert (!prev->cctx);//D temporary |
1387 | |
1389 | |
1388 | /* possibly untie and reuse the cctx */ |
1390 | /* possibly untie and reuse the cctx */ |
1389 | if (expect_true ( |
1391 | if (expect_true ( |
1390 | prev__cctx->idle_sp == STACKLEVEL |
1392 | cctx_current->idle_sp == STACKLEVEL |
1391 | && !(prev__cctx->flags & CC_TRACE) |
1393 | && !(cctx_current->flags & CC_TRACE) |
1392 | && !force_cctx |
1394 | && !force_cctx |
1393 | )) |
1395 | )) |
1394 | { |
1396 | { |
1395 | /* I assume that stacklevel is a stronger indicator than PL_top_env changes */ |
1397 | /* I assume that stacklevel is a stronger indicator than PL_top_env changes */ |
1396 | assert (("FATAL: current top_env must equal previous top_env in Coro (please report)", PL_top_env == prev__cctx->idle_te)); |
1398 | assert (("FATAL: current top_env must equal previous top_env in Coro (please report)", PL_top_env == cctx_current->idle_te)); |
1397 | |
1399 | |
1398 | prev->cctx = 0; |
|
|
1399 | |
|
|
1400 | /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */ |
1400 | /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get. */ |
1401 | /* without this the next cctx_get might destroy the prev__cctx while still in use */ |
1401 | /* without this the next cctx_get might destroy the running cctx while still in use */ |
1402 | if (expect_false (CCTX_EXPIRED (prev__cctx))) |
1402 | if (expect_false (CCTX_EXPIRED (cctx_current))) |
1403 | if (!next->cctx) |
1403 | if (expect_true (!next->cctx)) |
1404 | next->cctx = cctx_get (aTHX); |
1404 | next->cctx = cctx_get (aTHX); |
1405 | |
1405 | |
1406 | cctx_put (prev__cctx); |
1406 | cctx_put (cctx_current); |
1407 | } |
1407 | } |
|
|
1408 | else |
|
|
1409 | prev->cctx = cctx_current; |
1408 | |
1410 | |
1409 | ++next->usecount; |
1411 | ++next->usecount; |
1410 | |
1412 | |
1411 | if (expect_true (!next->cctx)) |
1413 | cctx_prev = cctx_current; |
1412 | next->cctx = cctx_get (aTHX); |
1414 | cctx_current = expect_false (next->cctx) ? next->cctx : cctx_get (aTHX); |
1413 | |
1415 | |
1414 | if (expect_false (prev__cctx != next->cctx)) |
1416 | next->cctx = 0; |
|
|
1417 | |
|
|
1418 | if (expect_false (cctx_prev != cctx_current)) |
1415 | { |
1419 | { |
1416 | prev__cctx->top_env = PL_top_env; |
1420 | cctx_prev->top_env = PL_top_env; |
1417 | PL_top_env = next->cctx->top_env; |
1421 | PL_top_env = cctx_current->top_env; |
1418 | coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); |
1422 | coro_transfer (&cctx_prev->cctx, &cctx_current->cctx); |
1419 | } |
1423 | } |
1420 | |
1424 | |
1421 | transfer_tail (aTHX); |
1425 | transfer_tail (aTHX); |
1422 | } |
1426 | } |
1423 | } |
1427 | } |
… | |
… | |
1657 | else |
1661 | else |
1658 | { |
1662 | { |
1659 | next->flags &= ~CF_READY; |
1663 | next->flags &= ~CF_READY; |
1660 | --coro_nready; |
1664 | --coro_nready; |
1661 | |
1665 | |
1662 | return prepare_schedule_to (aTHX_ ta, next); |
1666 | prepare_schedule_to (aTHX_ ta, next); |
|
|
1667 | break; |
1663 | } |
1668 | } |
1664 | } |
1669 | } |
1665 | else |
1670 | else |
1666 | { |
1671 | { |
1667 | /* nothing to schedule: call the idle handler */ |
1672 | /* nothing to schedule: call the idle handler */ |
… | |
… | |
1754 | static void |
1759 | static void |
1755 | api_trace (pTHX_ SV *coro_sv, int flags) |
1760 | api_trace (pTHX_ SV *coro_sv, int flags) |
1756 | { |
1761 | { |
1757 | struct coro *coro = SvSTATE (coro_sv); |
1762 | struct coro *coro = SvSTATE (coro_sv); |
1758 | |
1763 | |
|
|
1764 | if (coro->flags & CF_RUNNING) |
|
|
1765 | croak ("cannot enable tracing on a running coroutine, caught"); |
|
|
1766 | |
1759 | if (flags & CC_TRACE) |
1767 | if (flags & CC_TRACE) |
1760 | { |
1768 | { |
1761 | if (!coro->cctx) |
1769 | if (!coro->cctx) |
1762 | coro->cctx = cctx_new_run (); |
1770 | coro->cctx = cctx_new_run (); |
1763 | else if (!(coro->cctx->flags & CC_TRACE)) |
1771 | else if (!(coro->cctx->flags & CC_TRACE)) |
1764 | croak ("cannot enable tracing on coroutine with custom stack,"); |
1772 | croak ("cannot enable tracing on coroutine with custom stack, caught"); |
1765 | |
1773 | |
1766 | coro->cctx->flags |= CC_NOREUSE | (flags & (CC_TRACE | CC_TRACE_ALL)); |
1774 | coro->cctx->flags |= CC_NOREUSE | (flags & (CC_TRACE | CC_TRACE_ALL)); |
1767 | } |
1775 | } |
1768 | else if (coro->cctx && coro->cctx->flags & CC_TRACE) |
1776 | else if (coro->cctx && coro->cctx->flags & CC_TRACE) |
1769 | { |
1777 | { |
… | |
… | |
2250 | } |
2258 | } |
2251 | else |
2259 | else |
2252 | slf_argc = 0; |
2260 | slf_argc = 0; |
2253 | |
2261 | |
2254 | PL_op->op_ppaddr = pp_slf; |
2262 | PL_op->op_ppaddr = pp_slf; |
2255 | PL_op->op_type = OP_CUSTOM; /* maybe we should leave it at entersub? */ |
2263 | /*PL_op->op_type = OP_CUSTOM; /* we do behave like entersub still */ |
2256 | |
2264 | |
2257 | PL_op = (OP *)&slf_restore; |
2265 | PL_op = (OP *)&slf_restore; |
2258 | } |
2266 | } |
2259 | |
2267 | |
2260 | /*****************************************************************************/ |
2268 | /*****************************************************************************/ |
… | |
… | |
2724 | XSRETURN_EMPTY; |
2732 | XSRETURN_EMPTY; |
2725 | } |
2733 | } |
2726 | |
2734 | |
2727 | /*****************************************************************************/ |
2735 | /*****************************************************************************/ |
2728 | |
2736 | |
|
|
2737 | #if CORO_CLONE |
|
|
2738 | # include "clone.c" |
|
|
2739 | #endif |
|
|
2740 | |
2729 | MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ |
2741 | MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ |
2730 | |
2742 | |
2731 | PROTOTYPES: DISABLE |
2743 | PROTOTYPES: DISABLE |
2732 | |
2744 | |
2733 | BOOT: |
2745 | BOOT: |
… | |
… | |
2737 | coro_thx = PERL_GET_CONTEXT; |
2749 | coro_thx = PERL_GET_CONTEXT; |
2738 | # endif |
2750 | # endif |
2739 | #endif |
2751 | #endif |
2740 | BOOT_PAGESIZE; |
2752 | BOOT_PAGESIZE; |
2741 | |
2753 | |
|
|
2754 | cctx_current = cctx_new_empty (); |
|
|
2755 | |
2742 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
2756 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
2743 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
2757 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
2744 | |
2758 | |
2745 | orig_sigelem_get = PL_vtbl_sigelem.svt_get; PL_vtbl_sigelem.svt_get = coro_sigelem_get; |
2759 | orig_sigelem_get = PL_vtbl_sigelem.svt_get; PL_vtbl_sigelem.svt_get = coro_sigelem_get; |
2746 | orig_sigelem_set = PL_vtbl_sigelem.svt_set; PL_vtbl_sigelem.svt_set = coro_sigelem_set; |
2760 | orig_sigelem_set = PL_vtbl_sigelem.svt_set; PL_vtbl_sigelem.svt_set = coro_sigelem_set; |
… | |
… | |
2765 | |
2779 | |
2766 | { |
2780 | { |
2767 | SV *slf = sv_2mortal (newSViv (PTR2IV (pp_slf))); |
2781 | SV *slf = sv_2mortal (newSViv (PTR2IV (pp_slf))); |
2768 | |
2782 | |
2769 | if (!PL_custom_op_names) PL_custom_op_names = newHV (); |
2783 | if (!PL_custom_op_names) PL_custom_op_names = newHV (); |
2770 | hv_store_ent (PL_custom_op_names, slf, |
2784 | hv_store_ent (PL_custom_op_names, slf, newSVpv ("coro_slf", 0), 0); |
2771 | newSVpv ("coro_slf", 0), 0); |
|
|
2772 | |
2785 | |
2773 | if (!PL_custom_op_descs) PL_custom_op_descs = newHV (); |
2786 | if (!PL_custom_op_descs) PL_custom_op_descs = newHV (); |
2774 | hv_store_ent (PL_custom_op_descs, slf, |
2787 | hv_store_ent (PL_custom_op_descs, slf, newSVpv ("coro schedule like function", 0), 0); |
2775 | newSVpv ("coro schedule like function", 0), 0); |
|
|
2776 | } |
2788 | } |
2777 | |
2789 | |
2778 | coroapi.ver = CORO_API_VERSION; |
2790 | coroapi.ver = CORO_API_VERSION; |
2779 | coroapi.rev = CORO_API_REVISION; |
2791 | coroapi.rev = CORO_API_REVISION; |
2780 | |
2792 | |
… | |
… | |
2873 | void |
2885 | void |
2874 | _exit (int code) |
2886 | _exit (int code) |
2875 | PROTOTYPE: $ |
2887 | PROTOTYPE: $ |
2876 | CODE: |
2888 | CODE: |
2877 | _exit (code); |
2889 | _exit (code); |
|
|
2890 | |
|
|
2891 | SV * |
|
|
2892 | clone (Coro::State coro) |
|
|
2893 | CODE: |
|
|
2894 | { |
|
|
2895 | #if CORO_CLONE |
|
|
2896 | struct coro *ncoro = coro_clone (coro); |
|
|
2897 | MAGIC *mg; |
|
|
2898 | /* TODO: too much duplication */ |
|
|
2899 | ncoro->hv = newHV (); |
|
|
2900 | mg = sv_magicext ((SV *)ncoro->hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)ncoro, 0); |
|
|
2901 | mg->mg_flags |= MGf_DUP; |
|
|
2902 | RETVAL = sv_bless (newRV_noinc ((SV *)ncoro->hv), SvSTASH (coro->hv)); |
|
|
2903 | #else |
|
|
2904 | croak ("Coro::State->clone has not been configured into this installation of Coro, realised"); |
|
|
2905 | #endif |
|
|
2906 | } |
|
|
2907 | OUTPUT: |
|
|
2908 | RETVAL |
2878 | |
2909 | |
2879 | int |
2910 | int |
2880 | cctx_stacksize (int new_stacksize = 0) |
2911 | cctx_stacksize (int new_stacksize = 0) |
2881 | PROTOTYPE: ;$ |
2912 | PROTOTYPE: ;$ |
2882 | CODE: |
2913 | CODE: |
… | |
… | |
3003 | |
3034 | |
3004 | SV * |
3035 | SV * |
3005 | has_cctx (Coro::State coro) |
3036 | has_cctx (Coro::State coro) |
3006 | PROTOTYPE: $ |
3037 | PROTOTYPE: $ |
3007 | CODE: |
3038 | CODE: |
3008 | RETVAL = boolSV (!!coro->cctx); |
3039 | /* maybe manage the running flag differently */ |
|
|
3040 | RETVAL = boolSV (!!coro->cctx || (coro->flags & CF_RUNNING)); |
3009 | OUTPUT: |
3041 | OUTPUT: |
3010 | RETVAL |
3042 | RETVAL |
3011 | |
3043 | |
3012 | int |
3044 | int |
3013 | is_traced (Coro::State coro) |
3045 | is_traced (Coro::State coro) |
… | |
… | |
3033 | |
3065 | |
3034 | void |
3066 | void |
3035 | force_cctx () |
3067 | force_cctx () |
3036 | PROTOTYPE: |
3068 | PROTOTYPE: |
3037 | CODE: |
3069 | CODE: |
3038 | SvSTATE_current->cctx->idle_sp = 0; |
3070 | cctx_current->idle_sp = 0; |
3039 | |
3071 | |
3040 | void |
3072 | void |
3041 | swap_defsv (Coro::State self) |
3073 | swap_defsv (Coro::State self) |
3042 | PROTOTYPE: $ |
3074 | PROTOTYPE: $ |
3043 | ALIAS: |
3075 | ALIAS: |