… | |
… | |
14 | #include "perliol.h" |
14 | #include "perliol.h" |
15 | |
15 | |
16 | #include "schmorp.h" |
16 | #include "schmorp.h" |
17 | |
17 | |
18 | #define ECB_NO_THREADS 1 |
18 | #define ECB_NO_THREADS 1 |
|
|
19 | #define ECB_NO_LIBM 1 |
19 | #include "ecb.h" |
20 | #include "ecb.h" |
20 | |
21 | |
21 | #include <stddef.h> |
22 | #include <stddef.h> |
22 | #include <stdio.h> |
23 | #include <stdio.h> |
23 | #include <errno.h> |
24 | #include <errno.h> |
… | |
… | |
42 | # define PadARRAY AvARRAY |
43 | # define PadARRAY AvARRAY |
43 | # define PadMAX AvFILLp |
44 | # define PadMAX AvFILLp |
44 | # define newPADLIST(var) ((var) = newAV (), av_extend (var, 1)) |
45 | # define newPADLIST(var) ((var) = newAV (), av_extend (var, 1)) |
45 | #endif |
46 | #endif |
46 | |
47 | |
|
|
48 | /* 5.19.something has replaced SVt_BIND by SVt_INVLIST */ |
|
|
49 | /* we just alias it to SVt_IV, as that is sufficient for swap_sv for now */ |
|
|
50 | #if PERL_VERSION_ATLEAST(5,19,0) |
|
|
51 | # define SVt_BIND SVt_IV |
|
|
52 | #endif |
|
|
53 | |
47 | #if defined(_WIN32) |
54 | #if defined(_WIN32) |
48 | # undef HAS_GETTIMEOFDAY |
55 | # undef HAS_GETTIMEOFDAY |
49 | # undef setjmp |
56 | # undef setjmp |
50 | # undef longjmp |
57 | # undef longjmp |
51 | # undef _exit |
58 | # undef _exit |
… | |
… | |
515 | PAD *newpad; |
522 | PAD *newpad; |
516 | PADOFFSET off = PadlistMAX (padlist) + 1; |
523 | PADOFFSET off = PadlistMAX (padlist) + 1; |
517 | |
524 | |
518 | #if NEWPADAPI |
525 | #if NEWPADAPI |
519 | |
526 | |
|
|
527 | /* if we had the original CvDEPTH, we might be able to steal the CvDEPTH+1 entry instead */ |
|
|
528 | /* 20131102194744.GA6705@schmorp.de, 20131102195825.2013.qmail@lists-nntp.develooper.com */ |
520 | while (!PadlistARRAY (padlist)[off - 1]) |
529 | while (!PadlistARRAY (padlist)[off - 1]) |
521 | --off; |
530 | --off; |
522 | |
531 | |
523 | Perl_pad_push (aTHX_ padlist, off); |
532 | Perl_pad_push (aTHX_ padlist, off); |
524 | |
533 | |
… | |
… | |
562 | |
571 | |
563 | while (i > 0) /* special-case index 0 */ |
572 | while (i > 0) /* special-case index 0 */ |
564 | { |
573 | { |
565 | /* we try to be extra-careful here */ |
574 | /* we try to be extra-careful here */ |
566 | PAD *pad = PadlistARRAY (padlist)[i--]; |
575 | PAD *pad = PadlistARRAY (padlist)[i--]; |
|
|
576 | |
|
|
577 | if (pad) |
|
|
578 | { |
567 | I32 j = PadMAX (pad); |
579 | I32 j = PadMAX (pad); |
568 | |
580 | |
569 | while (j >= 0) |
581 | while (j >= 0) |
570 | SvREFCNT_dec (PadARRAY (pad)[j--]); |
582 | SvREFCNT_dec (PadARRAY (pad)[j--]); |
571 | |
583 | |
572 | PadMAX (pad) = -1; |
584 | PadMAX (pad) = -1; |
573 | SvREFCNT_dec (pad); |
585 | SvREFCNT_dec (pad); |
|
|
586 | } |
574 | } |
587 | } |
575 | |
588 | |
576 | SvREFCNT_dec (PadlistNAMES (padlist)); |
589 | SvREFCNT_dec (PadlistNAMES (padlist)); |
577 | |
590 | |
578 | #if NEWPADAPI |
591 | #if NEWPADAPI |
… | |
… | |
1904 | /* nothing to schedule: call the idle handler */ |
1917 | /* nothing to schedule: call the idle handler */ |
1905 | if (SvROK (sv_idle) |
1918 | if (SvROK (sv_idle) |
1906 | && SvOBJECT (SvRV (sv_idle))) |
1919 | && SvOBJECT (SvRV (sv_idle))) |
1907 | { |
1920 | { |
1908 | if (SvRV (sv_idle) == SvRV (coro_current)) |
1921 | if (SvRV (sv_idle) == SvRV (coro_current)) |
|
|
1922 | { |
|
|
1923 | require_pv ("Carp"); |
|
|
1924 | |
|
|
1925 | { |
|
|
1926 | dSP; |
|
|
1927 | |
|
|
1928 | ENTER; |
|
|
1929 | SAVETMPS; |
|
|
1930 | |
|
|
1931 | PUSHMARK (SP); |
1909 | croak ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught"); |
1932 | XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught", 0))); |
|
|
1933 | PUTBACK; |
|
|
1934 | call_pv ("Carp::confess", G_VOID | G_DISCARD); |
|
|
1935 | |
|
|
1936 | FREETMPS; |
|
|
1937 | LEAVE; |
|
|
1938 | } |
|
|
1939 | } |
1910 | |
1940 | |
1911 | ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ |
1941 | ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ |
1912 | api_ready (aTHX_ SvRV (sv_idle)); |
1942 | api_ready (aTHX_ SvRV (sv_idle)); |
1913 | --coro_nready; |
1943 | --coro_nready; |
1914 | } |
1944 | } |
… | |
… | |
2218 | slf_init_terminate_cancel_common (aTHX_ frame, coro_hv); |
2248 | slf_init_terminate_cancel_common (aTHX_ frame, coro_hv); |
2219 | } |
2249 | } |
2220 | else |
2250 | else |
2221 | { |
2251 | { |
2222 | struct coro *self = SvSTATE_current; |
2252 | struct coro *self = SvSTATE_current; |
|
|
2253 | |
|
|
2254 | if (!self) |
|
|
2255 | croak ("Coro::cancel called outside of thread content,"); |
2223 | |
2256 | |
2224 | /* otherwise we cancel directly, purely for speed reasons |
2257 | /* otherwise we cancel directly, purely for speed reasons |
2225 | * unfortunately, this requires some magic trickery, as |
2258 | * unfortunately, this requires some magic trickery, as |
2226 | * somebody else could cancel us, so we have to fight the cancellation. |
2259 | * somebody else could cancel us, so we have to fight the cancellation. |
2227 | * this is ugly, and hopefully fully worth the extra speed. |
2260 | * this is ugly, and hopefully fully worth the extra speed. |
… | |
… | |
2569 | |
2602 | |
2570 | /* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ |
2603 | /* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ |
2571 | static void |
2604 | static void |
2572 | slf_destroy (pTHX_ struct coro *coro) |
2605 | slf_destroy (pTHX_ struct coro *coro) |
2573 | { |
2606 | { |
2574 | /* this callback is reserved for slf functions needing to do cleanup */ |
2607 | struct CoroSLF frame = coro->slf_frame; |
2575 | if (coro->slf_frame.destroy && coro->slf_frame.prepare && !PL_dirty) |
|
|
2576 | coro->slf_frame.destroy (aTHX_ &coro->slf_frame); |
|
|
2577 | |
2608 | |
2578 | /* |
2609 | /* |
2579 | * The on_destroy above most likely is from an SLF call. |
2610 | * The on_destroy below most likely is from an SLF call. |
2580 | * Since by definition the SLF call will not finish when we destroy |
2611 | * Since by definition the SLF call will not finish when we destroy |
2581 | * the coro, we will have to force-finish it here, otherwise |
2612 | * the coro, we will have to force-finish it here, otherwise |
2582 | * cleanup functions cannot call SLF functions. |
2613 | * cleanup functions cannot call SLF functions. |
2583 | */ |
2614 | */ |
2584 | coro->slf_frame.prepare = 0; |
2615 | coro->slf_frame.prepare = 0; |
|
|
2616 | |
|
|
2617 | /* this callback is reserved for slf functions needing to do cleanup */ |
|
|
2618 | if (frame.destroy && frame.prepare && !PL_dirty) |
|
|
2619 | frame.destroy (aTHX_ &frame); |
2585 | } |
2620 | } |
2586 | |
2621 | |
2587 | /* |
2622 | /* |
2588 | * these not obviously related functions are all rolled into one |
2623 | * these not obviously related functions are all rolled into one |
2589 | * function to increase chances that they all will call transfer with the same |
2624 | * function to increase chances that they all will call transfer with the same |
… | |
… | |
2929 | { |
2964 | { |
2930 | AV *av = (AV *)frame->data; |
2965 | AV *av = (AV *)frame->data; |
2931 | SV *count_sv = AvARRAY (av)[0]; |
2966 | SV *count_sv = AvARRAY (av)[0]; |
2932 | SV *coro_hv = SvRV (coro_current); |
2967 | SV *coro_hv = SvRV (coro_current); |
2933 | |
2968 | |
|
|
2969 | frame->destroy = 0; |
|
|
2970 | |
2934 | /* if we are about to throw, don't actually acquire the lock, just throw */ |
2971 | /* if we are about to throw, don't actually acquire the lock, just throw */ |
2935 | if (CORO_THROW) |
2972 | if (ecb_expect_false (CORO_THROW)) |
|
|
2973 | { |
|
|
2974 | /* we still might be responsible for the semaphore, so wake up others */ |
|
|
2975 | coro_semaphore_adjust (aTHX_ av, 0); |
|
|
2976 | |
2936 | return 0; |
2977 | return 0; |
|
|
2978 | } |
2937 | else if (SvIVX (count_sv) > 0) |
2979 | else if (SvIVX (count_sv) > 0) |
2938 | { |
2980 | { |
2939 | frame->destroy = 0; |
|
|
2940 | |
|
|
2941 | if (acquire) |
2981 | if (acquire) |
2942 | SvIVX (count_sv) = SvIVX (count_sv) - 1; |
2982 | SvIVX (count_sv) = SvIVX (count_sv) - 1; |
2943 | else |
2983 | else |
2944 | coro_semaphore_adjust (aTHX_ av, 0); |
2984 | coro_semaphore_adjust (aTHX_ av, 0); |
2945 | |
2985 | |
… | |
… | |
3405 | |
3445 | |
3406 | PROTOTYPES: DISABLE |
3446 | PROTOTYPES: DISABLE |
3407 | |
3447 | |
3408 | BOOT: |
3448 | BOOT: |
3409 | { |
3449 | { |
|
|
3450 | #define VARx(name,expr,type) if (sizeof (type) < sizeof (expr)) croak ("FATAL: Coro thread context slot '" # name "' too small for this version of perl."); |
|
|
3451 | #include "state.h" |
3410 | #ifdef USE_ITHREADS |
3452 | #ifdef USE_ITHREADS |
3411 | # if CORO_PTHREAD |
3453 | # if CORO_PTHREAD |
3412 | coro_thx = PERL_GET_CONTEXT; |
3454 | coro_thx = PERL_GET_CONTEXT; |
3413 | # endif |
3455 | # endif |
3414 | #endif |
3456 | #endif |