… | |
… | |
133 | #else |
133 | #else |
134 | # define dSTACKLEVEL volatile void *stacklevel |
134 | # define dSTACKLEVEL volatile void *stacklevel |
135 | # define STACKLEVEL ((void *)&stacklevel) |
135 | # define STACKLEVEL ((void *)&stacklevel) |
136 | #endif |
136 | #endif |
137 | |
137 | |
138 | #define IN_DESTRUCT (PL_main_cv == Nullcv) |
138 | #define IN_DESTRUCT PL_dirty |
139 | |
139 | |
140 | #if __GNUC__ >= 3 |
140 | #if __GNUC__ >= 3 |
141 | # define attribute(x) __attribute__(x) |
141 | # define attribute(x) __attribute__(x) |
142 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
142 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
143 | # define INLINE static inline |
143 | # define INLINE static inline |
… | |
… | |
247 | { |
247 | { |
248 | SV *defsv; |
248 | SV *defsv; |
249 | AV *defav; |
249 | AV *defav; |
250 | SV *errsv; |
250 | SV *errsv; |
251 | SV *irsgv; |
251 | SV *irsgv; |
|
|
252 | HV *hinthv; |
252 | #define VAR(name,type) type name; |
253 | #define VAR(name,type) type name; |
253 | # include "state.h" |
254 | # include "state.h" |
254 | #undef VAR |
255 | #undef VAR |
255 | } perl_slots; |
256 | } perl_slots; |
256 | |
257 | |
… | |
… | |
354 | HV *st; |
355 | HV *st; |
355 | GV *gvp; |
356 | GV *gvp; |
356 | return sv_2cv (sv, &st, &gvp, 0); |
357 | return sv_2cv (sv, &st, &gvp, 0); |
357 | } |
358 | } |
358 | |
359 | |
|
|
360 | /*****************************************************************************/ |
|
|
361 | /* magic glue */ |
|
|
362 | |
|
|
363 | #define CORO_MAGIC_type_cv 26 |
|
|
364 | #define CORO_MAGIC_type_state PERL_MAGIC_ext |
|
|
365 | |
|
|
366 | #define CORO_MAGIC_NN(sv, type) \ |
|
|
367 | (expect_true (SvMAGIC (sv)->mg_type == type) \ |
|
|
368 | ? SvMAGIC (sv) \ |
|
|
369 | : mg_find (sv, type)) |
|
|
370 | |
|
|
371 | #define CORO_MAGIC(sv, type) \ |
|
|
372 | (expect_true (SvMAGIC (sv)) \ |
|
|
373 | ? CORO_MAGIC_NN (sv, type) \ |
|
|
374 | : 0) |
|
|
375 | |
|
|
376 | #define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) |
|
|
377 | #define CORO_MAGIC_state(sv) CORO_MAGIC_NN (((SV *)(sv)), CORO_MAGIC_type_state) |
|
|
378 | |
|
|
379 | INLINE struct coro * |
|
|
380 | SvSTATE_ (pTHX_ SV *coro) |
|
|
381 | { |
|
|
382 | HV *stash; |
|
|
383 | MAGIC *mg; |
|
|
384 | |
|
|
385 | if (SvROK (coro)) |
|
|
386 | coro = SvRV (coro); |
|
|
387 | |
|
|
388 | if (expect_false (SvTYPE (coro) != SVt_PVHV)) |
|
|
389 | croak ("Coro::State object required"); |
|
|
390 | |
|
|
391 | stash = SvSTASH (coro); |
|
|
392 | if (expect_false (stash != coro_stash && stash != coro_state_stash)) |
|
|
393 | { |
|
|
394 | /* very slow, but rare, check */ |
|
|
395 | if (!sv_derived_from (sv_2mortal (newRV_inc (coro)), "Coro::State")) |
|
|
396 | croak ("Coro::State object required"); |
|
|
397 | } |
|
|
398 | |
|
|
399 | mg = CORO_MAGIC_state (coro); |
|
|
400 | return (struct coro *)mg->mg_ptr; |
|
|
401 | } |
|
|
402 | |
|
|
403 | #define SvSTATE(sv) SvSTATE_ (aTHX_ (sv)) |
|
|
404 | |
|
|
405 | /* faster than SvSTATE, but expects a coroutine hv */ |
|
|
406 | #define SvSTATE_hv(hv) ((struct coro *)CORO_MAGIC_NN ((SV *)hv, CORO_MAGIC_type_state)->mg_ptr) |
|
|
407 | #define SvSTATE_current SvSTATE_hv (SvRV (coro_current)) |
|
|
408 | |
|
|
409 | /*****************************************************************************/ |
|
|
410 | /* padlist management and caching */ |
|
|
411 | |
359 | static AV * |
412 | static AV * |
360 | coro_derive_padlist (pTHX_ CV *cv) |
413 | coro_derive_padlist (pTHX_ CV *cv) |
361 | { |
414 | { |
362 | AV *padlist = CvPADLIST (cv); |
415 | AV *padlist = CvPADLIST (cv); |
363 | AV *newpadlist, *newpad; |
416 | AV *newpadlist, *newpad; |
… | |
… | |
370 | Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); |
423 | Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); |
371 | #endif |
424 | #endif |
372 | newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; |
425 | newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; |
373 | --AvFILLp (padlist); |
426 | --AvFILLp (padlist); |
374 | |
427 | |
375 | av_store (newpadlist, 0, SvREFCNT_inc_NN (*av_fetch (padlist, 0, FALSE))); |
428 | av_store (newpadlist, 0, SvREFCNT_inc_NN (AvARRAY (padlist)[0])); |
376 | av_store (newpadlist, 1, (SV *)newpad); |
429 | av_store (newpadlist, 1, (SV *)newpad); |
377 | |
430 | |
378 | return newpadlist; |
431 | return newpadlist; |
379 | } |
432 | } |
380 | |
433 | |
381 | static void |
434 | static void |
382 | free_padlist (pTHX_ AV *padlist) |
435 | free_padlist (pTHX_ AV *padlist) |
383 | { |
436 | { |
384 | /* may be during global destruction */ |
437 | /* may be during global destruction */ |
385 | if (SvREFCNT (padlist)) |
438 | if (!IN_DESTRUCT) |
386 | { |
439 | { |
387 | I32 i = AvFILLp (padlist); |
440 | I32 i = AvFILLp (padlist); |
388 | while (i >= 0) |
441 | |
|
|
442 | while (i > 0) /* special-case index 0 */ |
389 | { |
443 | { |
390 | SV **svp = av_fetch (padlist, i--, FALSE); |
444 | /* we try to be extra-careful here */ |
391 | if (svp) |
445 | AV *av = (AV *)AvARRAY (padlist)[i--]; |
392 | { |
446 | I32 j = AvFILLp (av); |
393 | SV *sv; |
447 | |
394 | while (&PL_sv_undef != (sv = av_pop ((AV *)*svp))) |
448 | while (j >= 0) |
|
|
449 | SvREFCNT_dec (AvARRAY (av)[j--]); |
|
|
450 | |
|
|
451 | AvFILLp (av) = -1; |
395 | SvREFCNT_dec (sv); |
452 | SvREFCNT_dec (av); |
396 | |
|
|
397 | SvREFCNT_dec (*svp); |
|
|
398 | } |
|
|
399 | } |
453 | } |
400 | |
454 | |
|
|
455 | SvREFCNT_dec (AvARRAY (padlist)[0]); |
|
|
456 | |
|
|
457 | AvFILLp (padlist) = -1; |
401 | SvREFCNT_dec ((SV*)padlist); |
458 | SvREFCNT_dec ((SV*)padlist); |
402 | } |
459 | } |
403 | } |
460 | } |
404 | |
461 | |
405 | static int |
462 | static int |
… | |
… | |
414 | |
471 | |
415 | SvREFCNT_dec (av); /* sv_magicext increased the refcount */ |
472 | SvREFCNT_dec (av); /* sv_magicext increased the refcount */ |
416 | |
473 | |
417 | return 0; |
474 | return 0; |
418 | } |
475 | } |
419 | |
|
|
420 | #define CORO_MAGIC_type_cv 26 |
|
|
421 | #define CORO_MAGIC_type_state PERL_MAGIC_ext |
|
|
422 | |
476 | |
423 | static MGVTBL coro_cv_vtbl = { |
477 | static MGVTBL coro_cv_vtbl = { |
424 | 0, 0, 0, 0, |
478 | 0, 0, 0, 0, |
425 | coro_cv_free |
479 | coro_cv_free |
426 | }; |
480 | }; |
427 | |
|
|
428 | #define CORO_MAGIC_NN(sv, type) \ |
|
|
429 | (expect_true (SvMAGIC (sv)->mg_type == type) \ |
|
|
430 | ? SvMAGIC (sv) \ |
|
|
431 | : mg_find (sv, type)) |
|
|
432 | |
|
|
433 | #define CORO_MAGIC(sv, type) \ |
|
|
434 | (expect_true (SvMAGIC (sv)) \ |
|
|
435 | ? CORO_MAGIC_NN (sv, type) \ |
|
|
436 | : 0) |
|
|
437 | |
|
|
438 | #define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) |
|
|
439 | #define CORO_MAGIC_state(sv) CORO_MAGIC_NN (((SV *)(sv)), CORO_MAGIC_type_state) |
|
|
440 | |
|
|
441 | INLINE struct coro * |
|
|
442 | SvSTATE_ (pTHX_ SV *coro) |
|
|
443 | { |
|
|
444 | HV *stash; |
|
|
445 | MAGIC *mg; |
|
|
446 | |
|
|
447 | if (SvROK (coro)) |
|
|
448 | coro = SvRV (coro); |
|
|
449 | |
|
|
450 | if (expect_false (SvTYPE (coro) != SVt_PVHV)) |
|
|
451 | croak ("Coro::State object required"); |
|
|
452 | |
|
|
453 | stash = SvSTASH (coro); |
|
|
454 | if (expect_false (stash != coro_stash && stash != coro_state_stash)) |
|
|
455 | { |
|
|
456 | /* very slow, but rare, check */ |
|
|
457 | if (!sv_derived_from (sv_2mortal (newRV_inc (coro)), "Coro::State")) |
|
|
458 | croak ("Coro::State object required"); |
|
|
459 | } |
|
|
460 | |
|
|
461 | mg = CORO_MAGIC_state (coro); |
|
|
462 | return (struct coro *)mg->mg_ptr; |
|
|
463 | } |
|
|
464 | |
|
|
465 | #define SvSTATE(sv) SvSTATE_ (aTHX_ (sv)) |
|
|
466 | |
|
|
467 | /* faster than SvSTATE, but expects a coroutine hv */ |
|
|
468 | #define SvSTATE_hv(hv) ((struct coro *)CORO_MAGIC_NN ((SV *)hv, CORO_MAGIC_type_state)->mg_ptr) |
|
|
469 | #define SvSTATE_current SvSTATE_hv (SvRV (coro_current)) |
|
|
470 | |
481 | |
471 | /* the next two functions merely cache the padlists */ |
482 | /* the next two functions merely cache the padlists */ |
472 | static void |
483 | static void |
473 | get_padlist (pTHX_ CV *cv) |
484 | get_padlist (pTHX_ CV *cv) |
474 | { |
485 | { |
… | |
… | |
502 | mg = sv_magicext ((SV *)cv, (SV *)newAV (), CORO_MAGIC_type_cv, &coro_cv_vtbl, 0, 0); |
513 | mg = sv_magicext ((SV *)cv, (SV *)newAV (), CORO_MAGIC_type_cv, &coro_cv_vtbl, 0, 0); |
503 | |
514 | |
504 | av = (AV *)mg->mg_obj; |
515 | av = (AV *)mg->mg_obj; |
505 | |
516 | |
506 | if (expect_false (AvFILLp (av) >= AvMAX (av))) |
517 | if (expect_false (AvFILLp (av) >= AvMAX (av))) |
507 | av_extend (av, AvMAX (av) + 1); |
518 | av_extend (av, AvFILLp (av) + 1); |
508 | |
519 | |
509 | AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv); |
520 | AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv); |
510 | } |
521 | } |
511 | |
522 | |
512 | /** load & save, init *******************************************************/ |
523 | /** load & save, init *******************************************************/ |
… | |
… | |
517 | perl_slots *slot = c->slot; |
528 | perl_slots *slot = c->slot; |
518 | c->slot = 0; |
529 | c->slot = 0; |
519 | |
530 | |
520 | PL_mainstack = c->mainstack; |
531 | PL_mainstack = c->mainstack; |
521 | |
532 | |
522 | GvSV (PL_defgv) = slot->defsv; |
533 | GvSV (PL_defgv) = slot->defsv; |
523 | GvAV (PL_defgv) = slot->defav; |
534 | GvAV (PL_defgv) = slot->defav; |
524 | GvSV (PL_errgv) = slot->errsv; |
535 | GvSV (PL_errgv) = slot->errsv; |
525 | GvSV (irsgv) = slot->irsgv; |
536 | GvSV (irsgv) = slot->irsgv; |
|
|
537 | GvHV (PL_hintgv) = slot->hinthv; |
526 | |
538 | |
527 | #define VAR(name,type) PL_ ## name = slot->name; |
539 | #define VAR(name,type) PL_ ## name = slot->name; |
528 | # include "state.h" |
540 | # include "state.h" |
529 | #undef VAR |
541 | #undef VAR |
530 | |
542 | |
… | |
… | |
616 | c->mainstack = PL_mainstack; |
628 | c->mainstack = PL_mainstack; |
617 | |
629 | |
618 | { |
630 | { |
619 | perl_slots *slot = c->slot = (perl_slots *)(cxstack + cxstack_ix + 1); |
631 | perl_slots *slot = c->slot = (perl_slots *)(cxstack + cxstack_ix + 1); |
620 | |
632 | |
621 | slot->defav = GvAV (PL_defgv); |
633 | slot->defav = GvAV (PL_defgv); |
622 | slot->defsv = DEFSV; |
634 | slot->defsv = DEFSV; |
623 | slot->errsv = ERRSV; |
635 | slot->errsv = ERRSV; |
624 | slot->irsgv = GvSV (irsgv); |
636 | slot->irsgv = GvSV (irsgv); |
|
|
637 | slot->hinthv = GvHV (PL_hintgv); |
625 | |
638 | |
626 | #define VAR(name,type) slot->name = PL_ ## name; |
639 | #define VAR(name,type) slot->name = PL_ ## name; |
627 | # include "state.h" |
640 | # include "state.h" |
628 | #undef VAR |
641 | #undef VAR |
629 | } |
642 | } |
… | |
… | |
865 | |
878 | |
866 | PL_runops = RUNOPS_DEFAULT; |
879 | PL_runops = RUNOPS_DEFAULT; |
867 | PL_curcop = &PL_compiling; |
880 | PL_curcop = &PL_compiling; |
868 | PL_in_eval = EVAL_NULL; |
881 | PL_in_eval = EVAL_NULL; |
869 | PL_comppad = 0; |
882 | PL_comppad = 0; |
|
|
883 | PL_comppad_name = 0; |
|
|
884 | PL_comppad_name_fill = 0; |
|
|
885 | PL_comppad_name_floor = 0; |
870 | PL_curpm = 0; |
886 | PL_curpm = 0; |
871 | PL_curpad = 0; |
887 | PL_curpad = 0; |
872 | PL_localizing = 0; |
888 | PL_localizing = 0; |
873 | PL_dirty = 0; |
889 | PL_dirty = 0; |
874 | PL_restartop = 0; |
890 | PL_restartop = 0; |
875 | #if PERL_VERSION_ATLEAST (5,10,0) |
891 | #if PERL_VERSION_ATLEAST (5,10,0) |
876 | PL_parser = 0; |
892 | PL_parser = 0; |
877 | #endif |
893 | #endif |
|
|
894 | PL_hints = 0; |
878 | |
895 | |
879 | /* recreate the die/warn hooks */ |
896 | /* recreate the die/warn hooks */ |
880 | PL_diehook = 0; SvSetMagicSV (*hv_fetch (hv_sig, "__DIE__" , sizeof ("__DIE__" ) - 1, 1), rv_diehook ); |
897 | PL_diehook = 0; SvSetMagicSV (*hv_fetch (hv_sig, "__DIE__" , sizeof ("__DIE__" ) - 1, 1), rv_diehook ); |
881 | PL_warnhook = 0; SvSetMagicSV (*hv_fetch (hv_sig, "__WARN__", sizeof ("__WARN__") - 1, 1), rv_warnhook); |
898 | PL_warnhook = 0; SvSetMagicSV (*hv_fetch (hv_sig, "__WARN__", sizeof ("__WARN__") - 1, 1), rv_warnhook); |
882 | |
899 | |
883 | GvSV (PL_defgv) = newSV (0); |
900 | GvSV (PL_defgv) = newSV (0); |
884 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
901 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
885 | GvSV (PL_errgv) = newSV (0); |
902 | GvSV (PL_errgv) = newSV (0); |
886 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
903 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
|
|
904 | GvHV (PL_hintgv) = 0; |
887 | PL_rs = newSVsv (GvSV (irsgv)); |
905 | PL_rs = newSVsv (GvSV (irsgv)); |
888 | PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); |
906 | PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); |
889 | |
907 | |
890 | { |
908 | { |
891 | dSP; |
909 | dSP; |
… | |
… | |
920 | /* copy throw, in case it was set before coro_setup */ |
938 | /* copy throw, in case it was set before coro_setup */ |
921 | CORO_THROW = coro->except; |
939 | CORO_THROW = coro->except; |
922 | } |
940 | } |
923 | |
941 | |
924 | static void |
942 | static void |
925 | coro_destruct (pTHX_ struct coro *coro) |
943 | coro_unwind_stacks (pTHX) |
926 | { |
944 | { |
927 | if (!IN_DESTRUCT) |
945 | if (!IN_DESTRUCT) |
928 | { |
946 | { |
929 | /* restore all saved variables and stuff */ |
947 | /* restore all saved variables and stuff */ |
930 | LEAVE_SCOPE (0); |
948 | LEAVE_SCOPE (0); |
… | |
… | |
938 | POPSTACK_TO (PL_mainstack); |
956 | POPSTACK_TO (PL_mainstack); |
939 | |
957 | |
940 | /* unwind main stack */ |
958 | /* unwind main stack */ |
941 | dounwind (-1); |
959 | dounwind (-1); |
942 | } |
960 | } |
|
|
961 | } |
|
|
962 | |
|
|
963 | static void |
|
|
964 | coro_destruct_perl (pTHX_ struct coro *coro) |
|
|
965 | { |
|
|
966 | coro_unwind_stacks (aTHX); |
943 | |
967 | |
944 | SvREFCNT_dec (GvSV (PL_defgv)); |
968 | SvREFCNT_dec (GvSV (PL_defgv)); |
945 | SvREFCNT_dec (GvAV (PL_defgv)); |
969 | SvREFCNT_dec (GvAV (PL_defgv)); |
946 | SvREFCNT_dec (GvSV (PL_errgv)); |
970 | SvREFCNT_dec (GvSV (PL_errgv)); |
947 | SvREFCNT_dec (PL_defoutgv); |
971 | SvREFCNT_dec (PL_defoutgv); |
948 | SvREFCNT_dec (PL_rs); |
972 | SvREFCNT_dec (PL_rs); |
949 | SvREFCNT_dec (GvSV (irsgv)); |
973 | SvREFCNT_dec (GvSV (irsgv)); |
|
|
974 | SvREFCNT_dec (GvHV (PL_hintgv)); |
950 | |
975 | |
951 | SvREFCNT_dec (PL_diehook); |
976 | SvREFCNT_dec (PL_diehook); |
952 | SvREFCNT_dec (PL_warnhook); |
977 | SvREFCNT_dec (PL_warnhook); |
953 | |
978 | |
954 | SvREFCNT_dec (coro->saved_deffh); |
979 | SvREFCNT_dec (coro->saved_deffh); |
… | |
… | |
1169 | /* |
1194 | /* |
1170 | * If perl-run returns we assume exit() was being called or the coro |
1195 | * If perl-run returns we assume exit() was being called or the coro |
1171 | * fell off the end, which seems to be the only valid (non-bug) |
1196 | * fell off the end, which seems to be the only valid (non-bug) |
1172 | * reason for perl_run to return. We try to exit by jumping to the |
1197 | * reason for perl_run to return. We try to exit by jumping to the |
1173 | * bootstrap-time "top" top_env, as we cannot restore the "main" |
1198 | * bootstrap-time "top" top_env, as we cannot restore the "main" |
1174 | * coroutine as Coro has no such concept |
1199 | * coroutine as Coro has no such concept. |
|
|
1200 | * This actually isn't valid with the pthread backend, but OSes requiring |
|
|
1201 | * that backend are too broken to do it in a standards-compliant way. |
1175 | */ |
1202 | */ |
1176 | PL_top_env = main_top_env; |
1203 | PL_top_env = main_top_env; |
1177 | JMPENV_JUMP (2); /* I do not feel well about the hardcoded 2 at all */ |
1204 | JMPENV_JUMP (2); /* I do not feel well about the hardcoded 2 at all */ |
1178 | } |
1205 | } |
1179 | } |
1206 | } |
… | |
… | |
1256 | cctx_destroy (coro_cctx *cctx) |
1283 | cctx_destroy (coro_cctx *cctx) |
1257 | { |
1284 | { |
1258 | if (!cctx) |
1285 | if (!cctx) |
1259 | return; |
1286 | return; |
1260 | |
1287 | |
1261 | assert (cctx != cctx_current);//D temporary |
1288 | assert (("FATAL: tried to destroy current cctx", cctx != cctx_current));//D temporary? |
1262 | |
1289 | |
1263 | --cctx_count; |
1290 | --cctx_count; |
1264 | coro_destroy (&cctx->cctx); |
1291 | coro_destroy (&cctx->cctx); |
1265 | |
1292 | |
1266 | /* coro_transfer creates new, empty cctx's */ |
1293 | /* coro_transfer creates new, empty cctx's */ |
… | |
… | |
1384 | coro_setup (aTHX_ next); |
1411 | coro_setup (aTHX_ next); |
1385 | } |
1412 | } |
1386 | else |
1413 | else |
1387 | load_perl (aTHX_ next); |
1414 | load_perl (aTHX_ next); |
1388 | |
1415 | |
1389 | assert (!prev->cctx);//D temporary |
|
|
1390 | |
|
|
1391 | /* possibly untie and reuse the cctx */ |
1416 | /* possibly untie and reuse the cctx */ |
1392 | if (expect_true ( |
1417 | if (expect_true ( |
1393 | cctx_current->idle_sp == STACKLEVEL |
1418 | cctx_current->idle_sp == STACKLEVEL |
1394 | && !(cctx_current->flags & CC_TRACE) |
1419 | && !(cctx_current->flags & CC_TRACE) |
1395 | && !force_cctx |
1420 | && !force_cctx |
… | |
… | |
1450 | --coro_nready; |
1475 | --coro_nready; |
1451 | } |
1476 | } |
1452 | else |
1477 | else |
1453 | coro->flags |= CF_READY; /* make sure it is NOT put into the readyqueue */ |
1478 | coro->flags |= CF_READY; /* make sure it is NOT put into the readyqueue */ |
1454 | |
1479 | |
1455 | if (coro->mainstack && coro->mainstack != main_mainstack) |
1480 | if (coro->mainstack |
|
|
1481 | && coro->mainstack != main_mainstack |
|
|
1482 | && coro->slot |
|
|
1483 | && !PL_dirty) |
1456 | { |
1484 | { |
1457 | struct coro temp; |
1485 | struct coro temp; |
1458 | |
1486 | |
1459 | assert (("FATAL: tried to destroy currently running coroutine (please report)", !(coro->flags & CF_RUNNING))); |
1487 | assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack)); |
1460 | |
1488 | |
1461 | save_perl (aTHX_ &temp); |
1489 | save_perl (aTHX_ &temp); |
1462 | load_perl (aTHX_ coro); |
1490 | load_perl (aTHX_ coro); |
1463 | |
1491 | |
1464 | coro_destruct (aTHX_ coro); |
1492 | coro_destruct_perl (aTHX_ coro); |
1465 | |
1493 | |
1466 | load_perl (aTHX_ &temp); |
1494 | load_perl (aTHX_ &temp); |
1467 | |
1495 | |
1468 | coro->slot = 0; |
1496 | coro->slot = 0; |
1469 | } |
1497 | } |
… | |
… | |
1670 | /* nothing to schedule: call the idle handler */ |
1698 | /* nothing to schedule: call the idle handler */ |
1671 | if (SvROK (sv_idle) |
1699 | if (SvROK (sv_idle) |
1672 | && SvOBJECT (SvRV (sv_idle))) |
1700 | && SvOBJECT (SvRV (sv_idle))) |
1673 | { |
1701 | { |
1674 | ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ |
1702 | ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ |
1675 | api_ready (SvRV (sv_idle)); |
1703 | api_ready (aTHX_ SvRV (sv_idle)); |
1676 | --coro_nready; |
1704 | --coro_nready; |
1677 | } |
1705 | } |
1678 | else |
1706 | else |
1679 | { |
1707 | { |
1680 | dSP; |
1708 | dSP; |
… | |
… | |
1841 | av_push (av_destroy, (SV *)newRV_inc ((SV *)hv)); /* RVinc for perl */ |
1869 | av_push (av_destroy, (SV *)newRV_inc ((SV *)hv)); /* RVinc for perl */ |
1842 | api_ready (aTHX_ sv_manager); |
1870 | api_ready (aTHX_ sv_manager); |
1843 | |
1871 | |
1844 | frame->prepare = prepare_schedule; |
1872 | frame->prepare = prepare_schedule; |
1845 | frame->check = slf_check_repeat; |
1873 | frame->check = slf_check_repeat; |
|
|
1874 | |
|
|
1875 | /* as a minor optimisation, we could unwind all stacks here */ |
|
|
1876 | /* but that puts extra pressure on pp_slf, and is not worth much */ |
|
|
1877 | /*coro_unwind_stacks (aTHX);*/ |
1846 | } |
1878 | } |
1847 | |
1879 | |
1848 | /*****************************************************************************/ |
1880 | /*****************************************************************************/ |
1849 | /* async pool handler */ |
1881 | /* async pool handler */ |
1850 | |
1882 | |
… | |
… | |
2359 | SV **ary; |
2391 | SV **ary; |
2360 | |
2392 | |
2361 | /* unfortunately, building manually saves memory */ |
2393 | /* unfortunately, building manually saves memory */ |
2362 | Newx (ary, 2, SV *); |
2394 | Newx (ary, 2, SV *); |
2363 | AvALLOC (av) = ary; |
2395 | AvALLOC (av) = ary; |
|
|
2396 | #if PERL_VERSION_ATLEAST (5,10,0) |
2364 | /*AvARRAY (av) = ary;*/ |
2397 | AvARRAY (av) = ary; |
|
|
2398 | #else |
2365 | SvPVX ((SV *)av) = (char *)ary; /* 5.8.8 needs this syntax instead of AvARRAY = ary */ |
2399 | /* 5.8.8 needs this syntax instead of AvARRAY = ary, yet */ |
|
|
2400 | /* -DDEBUGGING flags this as a bug, despite it perfectly working */ |
|
|
2401 | SvPVX ((SV *)av) = (char *)ary; |
|
|
2402 | #endif |
2366 | AvMAX (av) = 1; |
2403 | AvMAX (av) = 1; |
2367 | AvFILLp (av) = 0; |
2404 | AvFILLp (av) = 0; |
2368 | ary [0] = newSViv (count); |
2405 | ary [0] = newSViv (count); |
2369 | |
2406 | |
2370 | return newRV_noinc ((SV *)av); |
2407 | return newRV_noinc ((SV *)av); |
… | |
… | |
2899 | SV * |
2936 | SV * |
2900 | clone (Coro::State coro) |
2937 | clone (Coro::State coro) |
2901 | CODE: |
2938 | CODE: |
2902 | { |
2939 | { |
2903 | #if CORO_CLONE |
2940 | #if CORO_CLONE |
2904 | struct coro *ncoro = coro_clone (coro); |
2941 | struct coro *ncoro = coro_clone (aTHX_ coro); |
2905 | MAGIC *mg; |
2942 | MAGIC *mg; |
2906 | /* TODO: too much duplication */ |
2943 | /* TODO: too much duplication */ |
2907 | ncoro->hv = newHV (); |
2944 | ncoro->hv = newHV (); |
2908 | mg = sv_magicext ((SV *)ncoro->hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)ncoro, 0); |
2945 | mg = sv_magicext ((SV *)ncoro->hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)ncoro, 0); |
2909 | mg->mg_flags |= MGf_DUP; |
2946 | mg->mg_flags |= MGf_DUP; |
… | |
… | |
3100 | { |
3137 | { |
3101 | int i; |
3138 | int i; |
3102 | |
3139 | |
3103 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
3140 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
3104 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
3141 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
3105 | cv_coro_run = get_cv ( "Coro::_terminate", GV_ADD); |
3142 | cv_coro_run = get_cv ( "Coro::_coro_run" , GV_ADD); |
3106 | cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); |
3143 | cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); |
3107 | coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); |
3144 | coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); |
3108 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
3145 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
3109 | av_destroy = coro_get_av (aTHX_ "Coro::destroy" , TRUE); |
3146 | av_destroy = coro_get_av (aTHX_ "Coro::destroy" , TRUE); |
3110 | sv_manager = coro_get_sv (aTHX_ "Coro::manager" , TRUE); |
3147 | sv_manager = coro_get_sv (aTHX_ "Coro::manager" , TRUE); |