ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.xs
(Generate patch)

Comparing Coro/Coro/State.xs (file contents):
Revision 1.374 by root, Fri Oct 2 19:55:59 2009 UTC vs.
Revision 1.382 by root, Thu Feb 10 08:06:27 2011 UTC

1/* this works around a bug in mingw32 providing a non-working setjmp */
2#define USE_NO_MINGW_SETJMP_TWO_ARGS
3
1#define NDEBUG 1 4#define NDEBUG 1
2 5
3#include "libcoro/coro.c" 6#include "libcoro/coro.c"
4 7
5#define PERL_NO_GET_CONTEXT 8#define PERL_NO_GET_CONTEXT
718 { 721 {
719 CV *cv = cx->blk_sub.cv; 722 CV *cv = cx->blk_sub.cv;
720 723
721 if (expect_true (CvDEPTH (cv))) 724 if (expect_true (CvDEPTH (cv)))
722 { 725 {
726 EXTEND (SP, 3);
723 PUSHs ((SV *)CvPADLIST (cv)); 727 PUSHs ((SV *)CvPADLIST (cv));
724 PUSHs (INT2PTR (SV *, (IV)CvDEPTH (cv))); 728 PUSHs (INT2PTR (SV *, (IV)CvDEPTH (cv)));
725 PUSHs ((SV *)cv); 729 PUSHs ((SV *)cv);
726 730
727 CvDEPTH (cv) = 0; 731 CvDEPTH (cv) = 0;
1135 1139
1136 SvREFCNT_dec (coro->saved_deffh); 1140 SvREFCNT_dec (coro->saved_deffh);
1137 SvREFCNT_dec (coro->rouse_cb); 1141 SvREFCNT_dec (coro->rouse_cb);
1138 SvREFCNT_dec (coro->invoke_cb); 1142 SvREFCNT_dec (coro->invoke_cb);
1139 SvREFCNT_dec (coro->invoke_av); 1143 SvREFCNT_dec (coro->invoke_av);
1140 SvREFCNT_dec (coro->swap_sv);
1141 } 1144 }
1142} 1145}
1143 1146
1144INLINE void 1147INLINE void
1145free_coro_mortal (pTHX) 1148free_coro_mortal (pTHX)
1636 && coro->mainstack != main_mainstack 1639 && coro->mainstack != main_mainstack
1637 && coro->slot 1640 && coro->slot
1638 && !PL_dirty) 1641 && !PL_dirty)
1639 destroy_perl (aTHX_ coro); 1642 destroy_perl (aTHX_ coro);
1640 1643
1644 if (coro->next) coro->next->prev = coro->prev;
1645 if (coro->prev) coro->prev->next = coro->next;
1646 if (coro == coro_first) coro_first = coro->next;
1647
1641 cctx_destroy (coro->cctx); 1648 cctx_destroy (coro->cctx);
1642 SvREFCNT_dec (coro->startcv); 1649 SvREFCNT_dec (coro->startcv);
1643 SvREFCNT_dec (coro->args); 1650 SvREFCNT_dec (coro->args);
1651 SvREFCNT_dec (coro->swap_sv);
1644 SvREFCNT_dec (CORO_THROW); 1652 SvREFCNT_dec (CORO_THROW);
1645
1646 if (coro->next) coro->next->prev = coro->prev;
1647 if (coro->prev) coro->prev->next = coro->next;
1648 if (coro == coro_first) coro_first = coro->next;
1649 1653
1650 return 1; 1654 return 1;
1651} 1655}
1652 1656
1653static int 1657static int
1823 { 1827 {
1824 /* nothing to schedule: call the idle handler */ 1828 /* nothing to schedule: call the idle handler */
1825 if (SvROK (sv_idle) 1829 if (SvROK (sv_idle)
1826 && SvOBJECT (SvRV (sv_idle))) 1830 && SvOBJECT (SvRV (sv_idle)))
1827 { 1831 {
1832 if (SvRV (sv_idle) == SvRV (coro_current))
1833 croak ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught");
1834
1828 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ 1835 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */
1829 api_ready (aTHX_ SvRV (sv_idle)); 1836 api_ready (aTHX_ SvRV (sv_idle));
1830 --coro_nready; 1837 --coro_nready;
1831 } 1838 }
1832 else 1839 else
2418 if (PL_op->op_flags & OPf_STACKED) 2425 if (PL_op->op_flags & OPf_STACKED)
2419 { 2426 {
2420 if (items > slf_arga) 2427 if (items > slf_arga)
2421 { 2428 {
2422 slf_arga = items; 2429 slf_arga = items;
2423 free (slf_argv); 2430 Safefree (slf_argv);
2424 slf_argv = malloc (slf_arga * sizeof (SV *)); 2431 New (0, slf_argv, slf_arga, SV *);
2425 } 2432 }
2426 2433
2427 slf_argc = items; 2434 slf_argc = items;
2428 2435
2429 for (i = 0; i < items; ++i) 2436 for (i = 0; i < items; ++i)
2790 { 2797 {
2791 SV *cb_cv = s_get_cv_croak (arg [1]); 2798 SV *cb_cv = s_get_cv_croak (arg [1]);
2792 av_push (av, SvREFCNT_inc_NN (cb_cv)); 2799 av_push (av, SvREFCNT_inc_NN (cb_cv));
2793 2800
2794 if (SvIVX (AvARRAY (av)[0])) 2801 if (SvIVX (AvARRAY (av)[0]))
2795 coro_signal_wake (aTHX_ av, 1); /* ust be the only waiter */ 2802 coro_signal_wake (aTHX_ av, 1); /* must be the only waiter */
2796 2803
2797 frame->prepare = prepare_nop; 2804 frame->prepare = prepare_nop;
2798 frame->check = slf_check_nop; 2805 frame->check = slf_check_nop;
2799 } 2806 }
2800 else if (SvIVX (AvARRAY (av)[0])) 2807 else if (SvIVX (AvARRAY (av)[0]))
2962 /* now call the AIO function - we assume our request is uncancelable */ 2969 /* now call the AIO function - we assume our request is uncancelable */
2963 PUTBACK; 2970 PUTBACK;
2964 call_sv ((SV *)req, G_VOID | G_DISCARD); 2971 call_sv ((SV *)req, G_VOID | G_DISCARD);
2965 } 2972 }
2966 2973
2967 /* now that the requets is going, we loop toll we have a result */ 2974 /* now that the request is going, we loop till we have a result */
2968 frame->data = (void *)state; 2975 frame->data = (void *)state;
2969 frame->prepare = prepare_schedule; 2976 frame->prepare = prepare_schedule;
2970 frame->check = slf_check_aio_req; 2977 frame->check = slf_check_aio_req;
2971} 2978}
2972 2979
3271 RETVAL = boolSV (coro->flags & ix); 3278 RETVAL = boolSV (coro->flags & ix);
3272 OUTPUT: 3279 OUTPUT:
3273 RETVAL 3280 RETVAL
3274 3281
3275void 3282void
3276throw (Coro::State self, SV *throw = &PL_sv_undef) 3283throw (Coro::State self, SV *exception = &PL_sv_undef)
3277 PROTOTYPE: $;$ 3284 PROTOTYPE: $;$
3278 CODE: 3285 CODE:
3279{ 3286{
3280 struct coro *current = SvSTATE_current; 3287 struct coro *current = SvSTATE_current;
3281 SV **throwp = self == current ? &CORO_THROW : &self->except; 3288 SV **exceptionp = self == current ? &CORO_THROW : &self->except;
3282 SvREFCNT_dec (*throwp); 3289 SvREFCNT_dec (*exceptionp);
3283 SvGETMAGIC (throw); 3290 SvGETMAGIC (exception);
3284 *throwp = SvOK (throw) ? newSVsv (throw) : 0; 3291 *exceptionp = SvOK (exception) ? newSVsv (exception) : 0;
3285} 3292}
3286 3293
3287void 3294void
3288api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB) 3295api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB)
3289 PROTOTYPE: $;$ 3296 PROTOTYPE: $;$
3396 SWAP_SVS (current); 3403 SWAP_SVS (current);
3397 3404
3398 if (!coro->swap_sv) 3405 if (!coro->swap_sv)
3399 coro->swap_sv = newAV (); 3406 coro->swap_sv = newAV ();
3400 3407
3401 av_push (coro->swap_sv, SvREFCNT_inc_NN (sv)); 3408 av_push (coro->swap_sv, SvREFCNT_inc_NN (SvRV (sv )));
3402 av_push (coro->swap_sv, SvREFCNT_inc_NN (swapsv)); 3409 av_push (coro->swap_sv, SvREFCNT_inc_NN (SvRV (swapsv)));
3403 3410
3404 if (current == coro) 3411 if (current == coro)
3405 SWAP_SVS (current); 3412 SWAP_SVS (current);
3406} 3413}
3407 3414
3869 { 3876 {
3870 PL_ppaddr [OP_SSELECT] = coro_old_pp_sselect; 3877 PL_ppaddr [OP_SSELECT] = coro_old_pp_sselect;
3871 coro_old_pp_sselect = 0; 3878 coro_old_pp_sselect = 0;
3872 } 3879 }
3873 3880
3874

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines