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.304 by root, Wed Nov 19 08:22:48 2008 UTC vs.
Revision 1.306 by root, Wed Nov 19 11:11:10 2008 UTC

449 else 449 else
450 { 450 {
451#if CORO_PREFER_PERL_FUNCTIONS 451#if CORO_PREFER_PERL_FUNCTIONS
452 /* this is probably cleaner? but also slower! */ 452 /* this is probably cleaner? but also slower! */
453 /* in practise, it seems to be less stable */ 453 /* in practise, it seems to be less stable */
454 CV *cp = Perl_cv_clone (cv); 454 CV *cp = Perl_cv_clone (aTHX_ cv);
455 CvPADLIST (cv) = CvPADLIST (cp); 455 CvPADLIST (cv) = CvPADLIST (cp);
456 CvPADLIST (cp) = 0; 456 CvPADLIST (cp) = 0;
457 SvREFCNT_dec (cp); 457 SvREFCNT_dec (cp);
458#else 458#else
459 CvPADLIST (cv) = coro_clone_padlist (aTHX_ cv); 459 CvPADLIST (cv) = coro_clone_padlist (aTHX_ cv);
603 * of perl.c:init_stacks, except that it uses less memory 603 * of perl.c:init_stacks, except that it uses less memory
604 * on the (sometimes correct) assumption that coroutines do 604 * on the (sometimes correct) assumption that coroutines do
605 * not usually need a lot of stackspace. 605 * not usually need a lot of stackspace.
606 */ 606 */
607#if CORO_PREFER_PERL_FUNCTIONS 607#if CORO_PREFER_PERL_FUNCTIONS
608# define coro_init_stacks init_stacks 608# define coro_init_stacks(thx) init_stacks ()
609#else 609#else
610static void 610static void
611coro_init_stacks (pTHX) 611coro_init_stacks (pTHX)
612{ 612{
613 PL_curstackinfo = new_stackinfo(32, 8); 613 PL_curstackinfo = new_stackinfo(32, 8);
2143 SV **ary; 2143 SV **ary;
2144 2144
2145 /* unfortunately, building manually saves memory */ 2145 /* unfortunately, building manually saves memory */
2146 Newx (ary, 2, SV *); 2146 Newx (ary, 2, SV *);
2147 AvALLOC (av) = ary; 2147 AvALLOC (av) = ary;
2148 /*AvARRAY (av) = ary;*/
2148 SvPV_set ((SV *)av, (char *)ary); /* 5.8.8 needs this syntax instead of AvARRAY = ary */ 2149 SvPVX ((SV *)av) = (char *)ary; /* 5.8.8 needs this syntax instead of AvARRAY = ary */
2149 AvMAX (av) = 1; 2150 AvMAX (av) = 1;
2150 AvFILLp (av) = 0; 2151 AvFILLp (av) = 0;
2151 ary [0] = newSViv (count); 2152 ary [0] = newSViv (count);
2152 2153
2153 return newRV_noinc ((SV *)av); 2154 return newRV_noinc ((SV *)av);
2173 AvARRAY (av)[0] = AvARRAY (av)[1]; 2174 AvARRAY (av)[0] = AvARRAY (av)[1];
2174 AvARRAY (av)[1] = count_sv; 2175 AvARRAY (av)[1] = count_sv;
2175 cb = av_shift (av); 2176 cb = av_shift (av);
2176 2177
2177 if (SvOBJECT (cb)) 2178 if (SvOBJECT (cb))
2179 {
2178 api_ready (aTHX_ cb); 2180 api_ready (aTHX_ cb);
2179 else 2181 --count;
2180 croak ("callbacks not yet supported"); 2182 }
2183 else if (SvTYPE (cb) == SVt_PVCV)
2184 {
2185 dSP;
2186 PUSHMARK (SP);
2187 XPUSHs (sv_2mortal (newRV_inc ((SV *)av)));
2188 PUTBACK;
2189 call_sv (cb, G_VOID | G_DISCARD | G_EVAL | G_KEEPERR);
2190 }
2181 2191
2182 SvREFCNT_dec (cb); 2192 SvREFCNT_dec (cb);
2183
2184 --count;
2185 } 2193 }
2186} 2194}
2187 2195
2188static void 2196static void
2189coro_semaphore_on_destroy (pTHX_ struct coro *coro) 2197coro_semaphore_on_destroy (pTHX_ struct coro *coro)
2271} 2279}
2272 2280
2273static void 2281static void
2274slf_init_semaphore_wait (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items) 2282slf_init_semaphore_wait (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items)
2275{ 2283{
2284 if (items >= 2)
2285 {
2286 /* callback form */
2287 AV *av = (AV *)SvRV (arg [0]);
2288 HV *st;
2289 GV *gvp;
2290 CV *cb_cv = sv_2cv (arg [1], &st, &gvp, 0);
2291
2292 av_push (av, (SV *)SvREFCNT_inc_NN (cb_cv));
2293
2294 if (SvIVX (AvARRAY (av)[0]) > 0)
2295 coro_semaphore_adjust (aTHX_ av, 0);
2296
2297 frame->prepare = prepare_nop;
2298 frame->check = slf_check_nop;
2299 }
2300 else
2301 {
2276 slf_init_semaphore_down_or_wait (aTHX_ frame, cv, arg, items); 2302 slf_init_semaphore_down_or_wait (aTHX_ frame, cv, arg, items);
2277 frame->check = slf_check_semaphore_wait; 2303 frame->check = slf_check_semaphore_wait;
2304 }
2278} 2305}
2279 2306
2280/* signal */ 2307/* signal */
2281 2308
2282static void 2309static void
2989 RETVAL = coro_new_rouse_cb (aTHX); 3016 RETVAL = coro_new_rouse_cb (aTHX);
2990 OUTPUT: 3017 OUTPUT:
2991 RETVAL 3018 RETVAL
2992 3019
2993void 3020void
2994rouse_wait (SV *cb = 0) 3021rouse_wait (...)
2995 PROTOTYPE: ;$ 3022 PROTOTYPE: ;$
2996 PPCODE: 3023 PPCODE:
2997 CORO_EXECUTE_SLF_XS (slf_init_rouse_wait); 3024 CORO_EXECUTE_SLF_XS (slf_init_rouse_wait);
2998 3025
2999 3026
3036 adjust = 1 3063 adjust = 1
3037 CODE: 3064 CODE:
3038 coro_semaphore_adjust (aTHX_ (AV *)SvRV (self), ix ? adjust : 1); 3065 coro_semaphore_adjust (aTHX_ (AV *)SvRV (self), ix ? adjust : 1);
3039 3066
3040void 3067void
3041down (SV *self) 3068down (...)
3042 CODE: 3069 CODE:
3043 CORO_EXECUTE_SLF_XS (slf_init_semaphore_down); 3070 CORO_EXECUTE_SLF_XS (slf_init_semaphore_down);
3044 3071
3045void 3072void
3046wait (SV *self) 3073wait (...)
3047 CODE: 3074 CODE:
3048 CORO_EXECUTE_SLF_XS (slf_init_semaphore_wait); 3075 CORO_EXECUTE_SLF_XS (slf_init_semaphore_wait);
3049 3076
3050void 3077void
3051try (SV *self) 3078try (SV *self)
3094 ); 3121 );
3095 OUTPUT: 3122 OUTPUT:
3096 RETVAL 3123 RETVAL
3097 3124
3098void 3125void
3099wait (SV *self) 3126wait (...)
3100 CODE: 3127 CODE:
3101 CORO_EXECUTE_SLF_XS (slf_init_signal_wait); 3128 CORO_EXECUTE_SLF_XS (slf_init_signal_wait);
3102 3129
3103void 3130void
3104broadcast (SV *self) 3131broadcast (SV *self)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines