… | |
… | |
12 | #include "perl.h" |
12 | #include "perl.h" |
13 | #include "XSUB.h" |
13 | #include "XSUB.h" |
14 | #include "perliol.h" |
14 | #include "perliol.h" |
15 | |
15 | |
16 | #include "schmorp.h" |
16 | #include "schmorp.h" |
|
|
17 | |
|
|
18 | #define ECB_NO_THREADS 1 |
17 | #include "ecb.h" |
19 | #include "ecb.h" |
18 | |
20 | |
19 | #include <stddef.h> |
21 | #include <stddef.h> |
20 | #include <stdio.h> |
22 | #include <stdio.h> |
21 | #include <errno.h> |
23 | #include <errno.h> |
22 | #include <assert.h> |
24 | #include <assert.h> |
23 | |
25 | |
24 | #ifndef SVs_PADSTALE |
26 | #ifndef SVs_PADSTALE |
25 | # define SVs_PADSTALE 0 |
27 | # define SVs_PADSTALE 0 |
|
|
28 | #endif |
|
|
29 | |
|
|
30 | #ifdef PadARRAY |
|
|
31 | # define NEWPADAPI |
|
|
32 | # define newPADLIST(var) (Newz (0, var, 1, PADLIST), Newx (PadlistARRAY (var), 2, PAD *)) |
|
|
33 | #else |
|
|
34 | typedef AV PADNAMELIST; |
|
|
35 | # if !PERL_VERSION_ATLEAST(5,8,0) |
|
|
36 | typedef AV PADLIST; |
|
|
37 | typedef AV PAD; |
|
|
38 | # endif |
|
|
39 | # define PadlistARRAY(pl) ((PAD **)AvARRAY (pl)) |
|
|
40 | # define PadlistMAX(pl) AvFILLp (pl) |
|
|
41 | # define PadlistNAMES(pl) (*PadlistARRAY (pl)) |
|
|
42 | # define PadARRAY AvARRAY |
|
|
43 | # define PadMAX AvFILLp |
|
|
44 | # define newPADLIST(var) ((var) = newAV (), av_extend (var, 1)) |
26 | #endif |
45 | #endif |
27 | |
46 | |
28 | #if defined(_WIN32) |
47 | #if defined(_WIN32) |
29 | # undef HAS_GETTIMEOFDAY |
48 | # undef HAS_GETTIMEOFDAY |
30 | # undef setjmp |
49 | # undef setjmp |
… | |
… | |
101 | # if CORO_PTHREAD |
120 | # if CORO_PTHREAD |
102 | static void *coro_thx; |
121 | static void *coro_thx; |
103 | # endif |
122 | # endif |
104 | #endif |
123 | #endif |
105 | |
124 | |
106 | /* used in state.h */ |
|
|
107 | #define VAR(name,type) VARx(name, PL_ ## name, type) |
|
|
108 | |
|
|
109 | #ifdef __linux |
125 | #ifdef __linux |
110 | # include <time.h> /* for timespec */ |
126 | # include <time.h> /* for timespec */ |
111 | # include <syscall.h> /* for SYS_* */ |
127 | # include <syscall.h> /* for SYS_* */ |
112 | # ifdef SYS_clock_gettime |
128 | # ifdef SYS_clock_gettime |
113 | # define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
129 | # define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
… | |
… | |
213 | }; |
229 | }; |
214 | |
230 | |
215 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
231 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
216 | typedef struct |
232 | typedef struct |
217 | { |
233 | { |
218 | #define VARx(name,expr,type) type name; |
234 | #define VARx(name,expr,type) type name; |
219 | # include "state.h" |
235 | #include "state.h" |
220 | #undef VARx |
|
|
221 | } perl_slots; |
236 | } perl_slots; |
222 | |
237 | |
223 | /* how many context stack entries do we need for perl_slots */ |
238 | /* how many context stack entries do we need for perl_slots */ |
224 | #define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT)) |
239 | #define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT)) |
225 | |
240 | |
… | |
… | |
375 | time_init (pTHX) |
390 | time_init (pTHX) |
376 | { |
391 | { |
377 | SV **svp; |
392 | SV **svp; |
378 | |
393 | |
379 | require_pv ("Time/HiRes.pm"); |
394 | require_pv ("Time/HiRes.pm"); |
380 | |
395 | |
381 | svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
396 | svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
382 | |
397 | |
383 | if (!svp) croak ("Time::HiRes is required, but missing. Caught"); |
398 | if (!svp) croak ("Time::HiRes is required, but missing. Caught"); |
384 | if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer. Caught"); |
399 | if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer. Caught"); |
385 | |
400 | |
… | |
… | |
526 | #define SvSTATE_current SvSTATE_hv (SvRV (coro_current)) |
541 | #define SvSTATE_current SvSTATE_hv (SvRV (coro_current)) |
527 | |
542 | |
528 | /*****************************************************************************/ |
543 | /*****************************************************************************/ |
529 | /* padlist management and caching */ |
544 | /* padlist management and caching */ |
530 | |
545 | |
531 | ecb_inline AV * |
546 | ecb_inline PADLIST * |
532 | coro_derive_padlist (pTHX_ CV *cv) |
547 | coro_derive_padlist (pTHX_ CV *cv) |
533 | { |
548 | { |
534 | AV *padlist = CvPADLIST (cv); |
549 | PADLIST *padlist = CvPADLIST (cv); |
535 | AV *newpadlist, *newpad; |
550 | PADLIST *newpadlist; |
|
|
551 | PAD *newpad; |
|
|
552 | PADOFFSET const off = PadlistMAX (padlist) + 1; |
536 | |
553 | |
537 | newpadlist = newAV (); |
554 | newPADLIST(newpadlist); |
|
|
555 | #if !PERL_VERSION_ATLEAST(5,15,3) |
|
|
556 | /* Padlists are AvREAL as of 5.15.3. See perl bug #98092 and perl commit 7d953ba. */ |
538 | AvREAL_off (newpadlist); |
557 | AvREAL_off (newpadlist); |
|
|
558 | #endif |
539 | #if PERL_VERSION_ATLEAST (5,10,0) |
559 | #if PERL_VERSION_ATLEAST (5,10,0) |
540 | Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1); |
560 | Perl_pad_push (aTHX_ padlist, off); |
541 | #else |
561 | #else |
542 | Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); |
562 | Perl_pad_push (aTHX_ padlist, off, 1); |
543 | #endif |
563 | #endif |
544 | newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; |
564 | newpad = PadlistARRAY (padlist)[off]; |
545 | --AvFILLp (padlist); |
565 | PadlistMAX (padlist) = off - 1; |
546 | |
566 | |
547 | av_store (newpadlist, 0, SvREFCNT_inc_NN (AvARRAY (padlist)[0])); |
567 | /* Already extended to 2 elements by newPADLIST. */ |
548 | av_store (newpadlist, 1, (SV *)newpad); |
568 | PadlistMAX (newpadlist) = 1; |
|
|
569 | PadlistNAMES (newpadlist) = (PADNAMELIST *)SvREFCNT_inc_NN (PadlistNAMES (padlist)); |
|
|
570 | PadlistARRAY (newpadlist)[1] = newpad; |
549 | |
571 | |
550 | return newpadlist; |
572 | return newpadlist; |
551 | } |
573 | } |
552 | |
574 | |
553 | ecb_inline void |
575 | ecb_inline void |
554 | free_padlist (pTHX_ AV *padlist) |
576 | free_padlist (pTHX_ PADLIST *padlist) |
555 | { |
577 | { |
556 | /* may be during global destruction */ |
578 | /* may be during global destruction */ |
557 | if (!IN_DESTRUCT) |
579 | if (!IN_DESTRUCT) |
558 | { |
580 | { |
559 | I32 i = AvFILLp (padlist); |
581 | I32 i = PadlistMAX (padlist); |
560 | |
582 | |
561 | while (i > 0) /* special-case index 0 */ |
583 | while (i > 0) /* special-case index 0 */ |
562 | { |
584 | { |
563 | /* we try to be extra-careful here */ |
585 | /* we try to be extra-careful here */ |
564 | AV *av = (AV *)AvARRAY (padlist)[i--]; |
586 | PAD *pad = PadlistARRAY (padlist)[i--]; |
565 | I32 j = AvFILLp (av); |
587 | I32 j = PadMAX (pad); |
566 | |
588 | |
567 | while (j >= 0) |
589 | while (j >= 0) |
568 | SvREFCNT_dec (AvARRAY (av)[j--]); |
590 | SvREFCNT_dec (PadARRAY (pad)[j--]); |
569 | |
591 | |
570 | AvFILLp (av) = -1; |
592 | PadMAX (pad) = -1; |
571 | SvREFCNT_dec (av); |
593 | SvREFCNT_dec (pad); |
572 | } |
594 | } |
573 | |
595 | |
574 | SvREFCNT_dec (AvARRAY (padlist)[0]); |
596 | SvREFCNT_dec (PadlistNAMES (padlist)); |
575 | |
597 | |
|
|
598 | #ifdef NEWPADAPI |
|
|
599 | Safefree (PadlistARRAY (padlist)); |
|
|
600 | Safefree (padlist); |
|
|
601 | #else |
576 | AvFILLp (padlist) = -1; |
602 | AvFILLp (padlist) = -1; |
|
|
603 | AvREAL_off (padlist); |
577 | SvREFCNT_dec ((SV*)padlist); |
604 | SvREFCNT_dec ((SV*)padlist); |
|
|
605 | #endif |
578 | } |
606 | } |
579 | } |
607 | } |
580 | |
608 | |
581 | static int |
609 | static int |
582 | coro_cv_free (pTHX_ SV *sv, MAGIC *mg) |
610 | coro_cv_free (pTHX_ SV *sv, MAGIC *mg) |
583 | { |
611 | { |
584 | AV *padlist; |
612 | PADLIST *padlist; |
585 | AV *av = (AV *)mg->mg_obj; |
613 | PADLIST **padlists = (PADLIST **)(mg->mg_ptr + sizeof(size_t)); |
|
|
614 | size_t len = *(size_t *)mg->mg_ptr; |
586 | |
615 | |
587 | /* perl manages to free our internal AV and _then_ call us */ |
616 | /* perl manages to free our internal AV and _then_ call us */ |
588 | if (IN_DESTRUCT) |
617 | if (IN_DESTRUCT) |
589 | return 0; |
618 | return 0; |
590 | |
619 | |
591 | /* casting is fun. */ |
620 | while (len--) |
592 | while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) |
|
|
593 | free_padlist (aTHX_ padlist); |
621 | free_padlist (aTHX_ padlists[len]); |
594 | |
|
|
595 | SvREFCNT_dec (av); /* sv_magicext increased the refcount */ |
|
|
596 | |
622 | |
597 | return 0; |
623 | return 0; |
598 | } |
624 | } |
599 | |
625 | |
600 | static MGVTBL coro_cv_vtbl = { |
626 | static MGVTBL coro_cv_vtbl = { |
… | |
… | |
605 | /* the next two functions merely cache the padlists */ |
631 | /* the next two functions merely cache the padlists */ |
606 | ecb_inline void |
632 | ecb_inline void |
607 | get_padlist (pTHX_ CV *cv) |
633 | get_padlist (pTHX_ CV *cv) |
608 | { |
634 | { |
609 | MAGIC *mg = CORO_MAGIC_cv (cv); |
635 | MAGIC *mg = CORO_MAGIC_cv (cv); |
610 | AV *av; |
636 | size_t *lenp; |
611 | |
637 | |
612 | if (ecb_expect_true (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)) |
638 | if (ecb_expect_true (mg && *(lenp = (size_t *)mg->mg_ptr))) |
613 | CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; |
639 | CvPADLIST (cv) = ((PADLIST **)(mg->mg_ptr + sizeof(size_t)))[--*lenp]; |
614 | else |
640 | else |
615 | { |
641 | { |
616 | #if CORO_PREFER_PERL_FUNCTIONS |
642 | #if CORO_PREFER_PERL_FUNCTIONS |
617 | /* this is probably cleaner? but also slower! */ |
643 | /* this is probably cleaner? but also slower! */ |
618 | /* in practise, it seems to be less stable */ |
644 | /* in practise, it seems to be less stable */ |
… | |
… | |
628 | |
654 | |
629 | ecb_inline void |
655 | ecb_inline void |
630 | put_padlist (pTHX_ CV *cv) |
656 | put_padlist (pTHX_ CV *cv) |
631 | { |
657 | { |
632 | MAGIC *mg = CORO_MAGIC_cv (cv); |
658 | MAGIC *mg = CORO_MAGIC_cv (cv); |
633 | AV *av; |
|
|
634 | |
659 | |
635 | if (ecb_expect_false (!mg)) |
660 | if (ecb_expect_false (!mg)) |
|
|
661 | { |
636 | mg = sv_magicext ((SV *)cv, (SV *)newAV (), CORO_MAGIC_type_cv, &coro_cv_vtbl, 0, 0); |
662 | mg = sv_magicext ((SV *)cv, 0, CORO_MAGIC_type_cv, &coro_cv_vtbl, 0, 0); |
|
|
663 | Newz (0, mg->mg_ptr ,sizeof (size_t) + sizeof (PADLIST *), char); |
|
|
664 | mg->mg_len = 1; /* so mg_free frees mg_ptr */ |
|
|
665 | } |
|
|
666 | else |
|
|
667 | Renew (mg->mg_ptr, |
|
|
668 | sizeof(size_t) + (*(size_t *)mg->mg_ptr + 1) * sizeof(PADLIST *), |
|
|
669 | char); |
637 | |
670 | |
638 | av = (AV *)mg->mg_obj; |
671 | ((PADLIST **)(mg->mg_ptr + sizeof (size_t))) [(*(size_t *)mg->mg_ptr)++] = CvPADLIST (cv); |
639 | |
|
|
640 | if (ecb_expect_false (AvFILLp (av) >= AvMAX (av))) |
|
|
641 | av_extend (av, AvFILLp (av) + 1); |
|
|
642 | |
|
|
643 | AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv); |
|
|
644 | } |
672 | } |
645 | |
673 | |
646 | /** load & save, init *******************************************************/ |
674 | /** load & save, init *******************************************************/ |
647 | |
675 | |
648 | ecb_inline void |
676 | ecb_inline void |
… | |
… | |
710 | |
738 | |
711 | #if CORO_JIT |
739 | #if CORO_JIT |
712 | load_perl_slots (slot); |
740 | load_perl_slots (slot); |
713 | #else |
741 | #else |
714 | #define VARx(name,expr,type) expr = slot->name; |
742 | #define VARx(name,expr,type) expr = slot->name; |
715 | # include "state.h" |
743 | #include "state.h" |
716 | #undef VARx |
|
|
717 | #endif |
744 | #endif |
718 | |
745 | |
719 | { |
746 | { |
720 | dSP; |
747 | dSP; |
721 | |
748 | |
… | |
… | |
724 | /* now do the ugly restore mess */ |
751 | /* now do the ugly restore mess */ |
725 | while (ecb_expect_true (cv = (CV *)POPs)) |
752 | while (ecb_expect_true (cv = (CV *)POPs)) |
726 | { |
753 | { |
727 | put_padlist (aTHX_ cv); /* mark this padlist as available */ |
754 | put_padlist (aTHX_ cv); /* mark this padlist as available */ |
728 | CvDEPTH (cv) = PTR2IV (POPs); |
755 | CvDEPTH (cv) = PTR2IV (POPs); |
729 | CvPADLIST (cv) = (AV *)POPs; |
756 | CvPADLIST (cv) = (PADLIST *)POPs; |
730 | } |
757 | } |
731 | |
758 | |
732 | PUTBACK; |
759 | PUTBACK; |
733 | } |
760 | } |
734 | |
761 | |
… | |
… | |
843 | |
870 | |
844 | #if CORO_JIT |
871 | #if CORO_JIT |
845 | save_perl_slots (slot); |
872 | save_perl_slots (slot); |
846 | #else |
873 | #else |
847 | #define VARx(name,expr,type) slot->name = expr; |
874 | #define VARx(name,expr,type) slot->name = expr; |
848 | # include "state.h" |
875 | #include "state.h" |
849 | #undef VARx |
|
|
850 | #endif |
876 | #endif |
851 | } |
877 | } |
852 | } |
878 | } |
853 | |
879 | |
854 | /* |
880 | /* |
… | |
… | |
998 | { |
1024 | { |
999 | SV **svp = 0; |
1025 | SV **svp = 0; |
1000 | |
1026 | |
1001 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
1027 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
1002 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
1028 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
1003 | |
1029 | |
1004 | if (svp) |
1030 | if (svp) |
1005 | { |
1031 | { |
1006 | SV *ssv; |
1032 | SV *ssv; |
1007 | |
1033 | |
1008 | if (!*svp) |
1034 | if (!*svp) |
… | |
… | |
1114 | PL_hints = 0; |
1140 | PL_hints = 0; |
1115 | |
1141 | |
1116 | /* recreate the die/warn hooks */ |
1142 | /* recreate the die/warn hooks */ |
1117 | PL_diehook = SvREFCNT_inc (rv_diehook); |
1143 | PL_diehook = SvREFCNT_inc (rv_diehook); |
1118 | PL_warnhook = SvREFCNT_inc (rv_warnhook); |
1144 | PL_warnhook = SvREFCNT_inc (rv_warnhook); |
1119 | |
1145 | |
1120 | GvSV (PL_defgv) = newSV (0); |
1146 | GvSV (PL_defgv) = newSV (0); |
1121 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
1147 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
1122 | GvSV (PL_errgv) = newSV (0); |
1148 | GvSV (PL_errgv) = newSV (0); |
1123 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
1149 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
1124 | GvHV (PL_hintgv) = 0; |
1150 | GvHV (PL_hintgv) = 0; |
… | |
… | |
1422 | /* try to exit the same way perl's main function would do */ |
1448 | /* try to exit the same way perl's main function would do */ |
1423 | /* we do not bother resetting the environment or other things *7 |
1449 | /* we do not bother resetting the environment or other things *7 |
1424 | /* that are not, uhm, essential */ |
1450 | /* that are not, uhm, essential */ |
1425 | /* this obviously also doesn't work when perl is embedded */ |
1451 | /* this obviously also doesn't work when perl is embedded */ |
1426 | static void ecb_noinline ecb_cold |
1452 | static void ecb_noinline ecb_cold |
1427 | perlish_exit (void) |
1453 | perlish_exit (pTHX) |
1428 | { |
1454 | { |
1429 | int exitstatus = perl_destruct (PL_curinterp); |
1455 | int exitstatus = perl_destruct (PL_curinterp); |
1430 | perl_free (PL_curinterp); |
1456 | perl_free (PL_curinterp); |
1431 | exit (exitstatus); |
1457 | exit (exitstatus); |
1432 | } |
1458 | } |
… | |
… | |
1468 | * If perl-run returns we assume exit() was being called or the coro |
1494 | * If perl-run returns we assume exit() was being called or the coro |
1469 | * fell off the end, which seems to be the only valid (non-bug) |
1495 | * fell off the end, which seems to be the only valid (non-bug) |
1470 | * reason for perl_run to return. We try to mimic whatever perl is normally |
1496 | * reason for perl_run to return. We try to mimic whatever perl is normally |
1471 | * doing in that case. YMMV. |
1497 | * doing in that case. YMMV. |
1472 | */ |
1498 | */ |
1473 | perlish_exit (); |
1499 | perlish_exit (aTHX); |
1474 | } |
1500 | } |
1475 | } |
1501 | } |
1476 | |
1502 | |
1477 | static coro_cctx * |
1503 | static coro_cctx * |
1478 | cctx_new (void) |
1504 | cctx_new (void) |
… | |
… | |
1510 | size_t stack_size; |
1536 | size_t stack_size; |
1511 | |
1537 | |
1512 | #if HAVE_MMAP |
1538 | #if HAVE_MMAP |
1513 | cctx->ssize = ((cctx_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; |
1539 | cctx->ssize = ((cctx_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; |
1514 | /* mmap supposedly does allocate-on-write for us */ |
1540 | /* mmap supposedly does allocate-on-write for us */ |
1515 | cctx->sptr = mmap (0, cctx->ssize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, 0, 0); |
1541 | cctx->sptr = mmap (0, cctx->ssize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, -1, 0); |
1516 | |
1542 | |
1517 | if (cctx->sptr != (void *)-1) |
1543 | if (cctx->sptr != (void *)-1) |
1518 | { |
1544 | { |
1519 | #if CORO_STACKGUARD |
1545 | #if CORO_STACKGUARD |
1520 | mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); |
1546 | mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); |
… | |
… | |
1735 | return; |
1761 | return; |
1736 | |
1762 | |
1737 | slf_destroy (aTHX_ coro); |
1763 | slf_destroy (aTHX_ coro); |
1738 | |
1764 | |
1739 | coro->flags |= CF_ZOMBIE; |
1765 | coro->flags |= CF_ZOMBIE; |
1740 | |
1766 | |
1741 | if (coro->flags & CF_READY) |
1767 | if (coro->flags & CF_READY) |
1742 | { |
1768 | { |
1743 | /* reduce nready, as destroying a ready coro effectively unreadies it */ |
1769 | /* reduce nready, as destroying a ready coro effectively unreadies it */ |
1744 | /* alternative: look through all ready queues and remove the coro */ |
1770 | /* alternative: look through all ready queues and remove the coro */ |
1745 | --coro_nready; |
1771 | --coro_nready; |
… | |
… | |
2178 | |
2204 | |
2179 | static void |
2205 | static void |
2180 | coro_set_status (pTHX_ struct coro *coro, SV **arg, int items) |
2206 | coro_set_status (pTHX_ struct coro *coro, SV **arg, int items) |
2181 | { |
2207 | { |
2182 | AV *av; |
2208 | AV *av; |
2183 | |
2209 | |
2184 | if (coro->status) |
2210 | if (coro->status) |
2185 | { |
2211 | { |
2186 | av = coro->status; |
2212 | av = coro->status; |
2187 | av_clear (av); |
2213 | av_clear (av); |
2188 | } |
2214 | } |
… | |
… | |
2235 | |
2261 | |
2236 | coro = SvSTATE (arg [0]); |
2262 | coro = SvSTATE (arg [0]); |
2237 | coro_hv = coro->hv; |
2263 | coro_hv = coro->hv; |
2238 | |
2264 | |
2239 | coro_set_status (aTHX_ coro, arg + 1, items - 1); |
2265 | coro_set_status (aTHX_ coro, arg + 1, items - 1); |
2240 | |
2266 | |
2241 | if (ecb_expect_false (coro->flags & CF_NOCANCEL)) |
2267 | if (ecb_expect_false (coro->flags & CF_NOCANCEL)) |
2242 | { |
2268 | { |
2243 | /* coro currently busy cancelling something, so just notify it */ |
2269 | /* coro currently busy cancelling something, so just notify it */ |
2244 | coro->slf_frame.data = (void *)coro; |
2270 | coro->slf_frame.data = (void *)coro; |
2245 | |
2271 | |
… | |
… | |
2424 | |
2450 | |
2425 | static int |
2451 | static int |
2426 | slf_check_rouse_wait (pTHX_ struct CoroSLF *frame) |
2452 | slf_check_rouse_wait (pTHX_ struct CoroSLF *frame) |
2427 | { |
2453 | { |
2428 | SV *data = (SV *)frame->data; |
2454 | SV *data = (SV *)frame->data; |
2429 | |
2455 | |
2430 | if (CORO_THROW) |
2456 | if (CORO_THROW) |
2431 | return 0; |
2457 | return 0; |
2432 | |
2458 | |
2433 | if (SvTYPE (SvRV (data)) != SVt_PVAV) |
2459 | if (SvTYPE (SvRV (data)) != SVt_PVAV) |
2434 | return 1; |
2460 | return 1; |
… | |
… | |
2470 | cb = sv_2mortal (coro->rouse_cb); |
2496 | cb = sv_2mortal (coro->rouse_cb); |
2471 | coro->rouse_cb = 0; |
2497 | coro->rouse_cb = 0; |
2472 | } |
2498 | } |
2473 | |
2499 | |
2474 | if (!SvROK (cb) |
2500 | if (!SvROK (cb) |
2475 | || SvTYPE (SvRV (cb)) != SVt_PVCV |
2501 | || SvTYPE (SvRV (cb)) != SVt_PVCV |
2476 | || CvXSUB ((CV *)SvRV (cb)) != coro_rouse_callback) |
2502 | || CvXSUB ((CV *)SvRV (cb)) != coro_rouse_callback) |
2477 | croak ("Coro::rouse_wait called with illegal callback argument,"); |
2503 | croak ("Coro::rouse_wait called with illegal callback argument,"); |
2478 | |
2504 | |
2479 | { |
2505 | { |
2480 | CV *cv = (CV *)SvRV (cb); /* for S_GENSUB_ARG */ |
2506 | CV *cv = (CV *)SvRV (cb); /* for S_GENSUB_ARG */ |
… | |
… | |
3401 | int count; |
3427 | int count; |
3402 | |
3428 | |
3403 | eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1); |
3429 | eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1); |
3404 | |
3430 | |
3405 | PUSHMARK (SP); |
3431 | PUSHMARK (SP); |
3406 | #define VARx(name,expr,type) pushav_4uv (aTHX_ (UV)&(expr), sizeof (expr), offsetof (perl_slots, name), sizeof (type)); |
3432 | #define VARx(name,expr,type) pushav_4uv (aTHX_ (UV)&(expr), sizeof (expr), offsetof (perl_slots, name), sizeof (type)); |
3407 | # include "state.h" |
3433 | #include "state.h" |
3408 | #undef VARx |
|
|
3409 | count = call_pv ("Coro::State::_jit", G_ARRAY); |
3434 | count = call_pv ("Coro::State::_jit", G_ARRAY); |
3410 | SPAGAIN; |
3435 | SPAGAIN; |
3411 | |
3436 | |
3412 | save = POPs; save_ptr = SvPVbyte (save, save_len); |
3437 | save = POPs; save_ptr = SvPVbyte (save, save_len); |
3413 | load = POPs; load_ptr = SvPVbyte (load, load_len); |
3438 | load = POPs; load_ptr = SvPVbyte (load, load_len); |
… | |
… | |
3670 | RETVAL = boolSV (coro->flags & ix); |
3695 | RETVAL = boolSV (coro->flags & ix); |
3671 | OUTPUT: |
3696 | OUTPUT: |
3672 | RETVAL |
3697 | RETVAL |
3673 | |
3698 | |
3674 | void |
3699 | void |
3675 | throw (Coro::State self, SV *exception = &PL_sv_undef) |
3700 | throw (SV *self, SV *exception = &PL_sv_undef) |
3676 | PROTOTYPE: $;$ |
3701 | PROTOTYPE: $;$ |
3677 | CODE: |
3702 | CODE: |
3678 | { |
3703 | { |
|
|
3704 | struct coro *coro = SvSTATE (self); |
3679 | struct coro *current = SvSTATE_current; |
3705 | struct coro *current = SvSTATE_current; |
3680 | SV **exceptionp = self == current ? &CORO_THROW : &self->except; |
3706 | SV **exceptionp = coro == current ? &CORO_THROW : &coro->except; |
3681 | SvREFCNT_dec (*exceptionp); |
3707 | SvREFCNT_dec (*exceptionp); |
3682 | SvGETMAGIC (exception); |
3708 | SvGETMAGIC (exception); |
3683 | *exceptionp = SvOK (exception) ? newSVsv (exception) : 0; |
3709 | *exceptionp = SvOK (exception) ? newSVsv (exception) : 0; |
|
|
3710 | |
|
|
3711 | api_ready (aTHX_ self); |
3684 | } |
3712 | } |
3685 | |
3713 | |
3686 | void |
3714 | void |
3687 | api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB) |
3715 | api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB) |
3688 | PROTOTYPE: $;$ |
3716 | PROTOTYPE: $;$ |
… | |
… | |
3818 | |
3846 | |
3819 | sv_async_pool_idle = newSVpv ("[async pool idle]", 0); SvREADONLY_on (sv_async_pool_idle); |
3847 | sv_async_pool_idle = newSVpv ("[async pool idle]", 0); SvREADONLY_on (sv_async_pool_idle); |
3820 | sv_Coro = newSVpv ("Coro", 0); SvREADONLY_on (sv_Coro); |
3848 | sv_Coro = newSVpv ("Coro", 0); SvREADONLY_on (sv_Coro); |
3821 | cv_pool_handler = get_cv ("Coro::pool_handler", GV_ADD); SvREADONLY_on (cv_pool_handler); |
3849 | cv_pool_handler = get_cv ("Coro::pool_handler", GV_ADD); SvREADONLY_on (cv_pool_handler); |
3822 | CvNODEBUG_on (get_cv ("Coro::_pool_handler", 0)); /* work around a debugger bug */ |
3850 | CvNODEBUG_on (get_cv ("Coro::_pool_handler", 0)); /* work around a debugger bug */ |
3823 | |
3851 | |
3824 | coro_stash = gv_stashpv ("Coro", TRUE); |
3852 | coro_stash = gv_stashpv ("Coro", TRUE); |
3825 | |
3853 | |
3826 | newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (CORO_PRIO_MAX)); |
3854 | newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (CORO_PRIO_MAX)); |
3827 | newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (CORO_PRIO_HIGH)); |
3855 | newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (CORO_PRIO_HIGH)); |
3828 | newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (CORO_PRIO_NORMAL)); |
3856 | newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (CORO_PRIO_NORMAL)); |