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.351 by root, Sat Jun 20 08:58:25 2009 UTC vs.
Revision 1.355 by root, Wed Jun 24 02:52:38 2009 UTC

137 137
138#define IN_DESTRUCT PL_dirty 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
144#else 144#else
145# define attribute(x) 145# define attribute(x)
146# define expect(expr,value) (expr) 146# define expect(expr,value) (expr)
147# define INLINE static 147# define INLINE static
615 { 615 {
616 while (expect_true (cxix >= 0)) 616 while (expect_true (cxix >= 0))
617 { 617 {
618 PERL_CONTEXT *cx = &ccstk[cxix--]; 618 PERL_CONTEXT *cx = &ccstk[cxix--];
619 619
620 if (expect_true (CxTYPE (cx) == CXt_SUB || CxTYPE (cx) == CXt_FORMAT)) 620 if (expect_true (CxTYPE (cx) == CXt_SUB) || expect_false (CxTYPE (cx) == CXt_FORMAT))
621 { 621 {
622 CV *cv = cx->blk_sub.cv; 622 CV *cv = cx->blk_sub.cv;
623 623
624 if (expect_true (CvDEPTH (cv))) 624 if (expect_true (CvDEPTH (cv)))
625 { 625 {
999 999
1000 assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack)); 1000 assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack));
1001 1001
1002 save_perl (aTHX_ current); 1002 save_perl (aTHX_ current);
1003 load_perl (aTHX_ coro); 1003 load_perl (aTHX_ coro);
1004
1004 coro_unwind_stacks (aTHX); 1005 coro_unwind_stacks (aTHX);
1005 coro_destruct_stacks (aTHX); 1006 coro_destruct_stacks (aTHX);
1006 1007
1007 // now save some sv's to be free'd later 1008 // now save some sv's to be free'd later
1008 svf [0] = GvSV (PL_defgv); 1009 svf [0] = GvSV (PL_defgv);
2476/* Coro::Semaphore & Coro::Signal */ 2477/* Coro::Semaphore & Coro::Signal */
2477 2478
2478static SV * 2479static SV *
2479coro_waitarray_new (pTHX_ int count) 2480coro_waitarray_new (pTHX_ int count)
2480{ 2481{
2481 /* a semaphore contains a counter IV in $sem->[0] and any waiters after that */ 2482 /* a waitarray=semaphore contains a counter IV in $sem->[0] and any waiters after that */
2482 AV *av = newAV (); 2483 AV *av = newAV ();
2483 SV **ary; 2484 SV **ary;
2484 2485
2485 /* unfortunately, building manually saves memory */ 2486 /* unfortunately, building manually saves memory */
2486 Newx (ary, 2, SV *); 2487 Newx (ary, 2, SV *);
2630 { 2631 {
2631 /* callback form */ 2632 /* callback form */
2632 AV *av = (AV *)SvRV (arg [0]); 2633 AV *av = (AV *)SvRV (arg [0]);
2633 CV *cb_cv = coro_sv_2cv (aTHX_ arg [1]); 2634 CV *cb_cv = coro_sv_2cv (aTHX_ arg [1]);
2634 2635
2635 av_push (av, (SV *)SvREFCNT_inc_NN (cb_cv)); 2636 av_push (av, SvREFCNT_inc_NN (cb_cv));
2636 2637
2637 if (SvIVX (AvARRAY (av)[0]) > 0) 2638 if (SvIVX (AvARRAY (av)[0]) > 0)
2638 coro_semaphore_adjust (aTHX_ av, 0); 2639 coro_semaphore_adjust (aTHX_ av, 0);
2639 2640
2640 frame->prepare = prepare_nop; 2641 frame->prepare = prepare_nop;
2664 AvARRAY (av)[0] = AvARRAY (av)[1]; 2665 AvARRAY (av)[0] = AvARRAY (av)[1];
2665 AvARRAY (av)[1] = cb; 2666 AvARRAY (av)[1] = cb;
2666 2667
2667 cb = av_shift (av); 2668 cb = av_shift (av);
2668 2669
2670 if (SvTYPE (cb) == SVt_PVCV)
2671 {
2672 dSP;
2673 PUSHMARK (SP);
2674 XPUSHs (sv_2mortal (newRV_inc ((SV *)av)));
2675 PUTBACK;
2676 call_sv (cb, G_VOID | G_DISCARD | G_EVAL | G_KEEPERR);
2677 }
2678 else
2679 {
2669 api_ready (aTHX_ cb); 2680 api_ready (aTHX_ cb);
2670 sv_setiv (cb, 0); /* signal waiter */ 2681 sv_setiv (cb, 0); /* signal waiter */
2682 }
2683
2671 SvREFCNT_dec (cb); 2684 SvREFCNT_dec (cb);
2672 2685
2673 --count; 2686 --count;
2674 } 2687 }
2675} 2688}
2684static void 2697static void
2685slf_init_signal_wait (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items) 2698slf_init_signal_wait (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items)
2686{ 2699{
2687 AV *av = (AV *)SvRV (arg [0]); 2700 AV *av = (AV *)SvRV (arg [0]);
2688 2701
2702 if (items >= 2)
2703 {
2704 CV *cb_cv = coro_sv_2cv (aTHX_ arg [1]);
2705 av_push (av, SvREFCNT_inc_NN (cb_cv));
2706
2689 if (SvIVX (AvARRAY (av)[0])) 2707 if (SvIVX (AvARRAY (av)[0]))
2708 coro_signal_wake (aTHX_ av, 1); /* ust be the only waiter */
2709
2710 frame->prepare = prepare_nop;
2711 frame->check = slf_check_nop;
2712 }
2713 else if (SvIVX (AvARRAY (av)[0]))
2690 { 2714 {
2691 SvIVX (AvARRAY (av)[0]) = 0; 2715 SvIVX (AvARRAY (av)[0]) = 0;
2692 frame->prepare = prepare_nop; 2716 frame->prepare = prepare_nop;
2693 frame->check = slf_check_nop; 2717 frame->check = slf_check_nop;
2694 } 2718 }
2695 else 2719 else
2696 { 2720 {
2697 SV *waiter = newRV_inc (SvRV (coro_current)); /* owned by signal av */ 2721 SV *waiter = newSVsv (coro_current); /* owned by signal av */
2698 2722
2699 av_push (av, waiter); 2723 av_push (av, waiter);
2700 2724
2701 frame->data = (void *)sv_2mortal (SvREFCNT_inc_NN (waiter)); /* owned by process */ 2725 frame->data = (void *)sv_2mortal (SvREFCNT_inc_NN (waiter)); /* owned by process */
2702 frame->prepare = prepare_schedule; 2726 frame->prepare = prepare_schedule;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines