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.330 by root, Wed Nov 26 09:29:06 2008 UTC vs.
Revision 1.339 by root, Mon Dec 15 00:28:30 2008 UTC

133#else 133#else
134# define dSTACKLEVEL volatile void *stacklevel 134# define dSTACKLEVEL volatile void *stacklevel
135# define STACKLEVEL ((void *)&stacklevel) 135# define STACKLEVEL ((void *)&stacklevel)
136#endif 136#endif
137 137
138#define IN_DESTRUCT (PL_main_cv == Nullcv) 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
285 /* async_pool */ 285 /* async_pool */
286 SV *saved_deffh; 286 SV *saved_deffh;
287 SV *invoke_cb; 287 SV *invoke_cb;
288 AV *invoke_av; 288 AV *invoke_av;
289 289
290 /* on_enter/on_leave */
291 AV *on_enter;
292 AV *on_leave;
293
290 /* linked list */ 294 /* linked list */
291 struct coro *next, *prev; 295 struct coro *next, *prev;
292}; 296};
293 297
294typedef struct coro *Coro__State; 298typedef struct coro *Coro__State;
352INLINE CV * 356INLINE CV *
353coro_sv_2cv (pTHX_ SV *sv) 357coro_sv_2cv (pTHX_ SV *sv)
354{ 358{
355 HV *st; 359 HV *st;
356 GV *gvp; 360 GV *gvp;
357 return sv_2cv (sv, &st, &gvp, 0); 361 CV *cv = sv_2cv (sv, &st, &gvp, 0);
362
363 if (!cv)
364 croak ("code reference expected");
365
366 return cv;
358} 367}
368
369/*****************************************************************************/
370/* magic glue */
371
372#define CORO_MAGIC_type_cv 26
373#define CORO_MAGIC_type_state PERL_MAGIC_ext
374
375#define CORO_MAGIC_NN(sv, type) \
376 (expect_true (SvMAGIC (sv)->mg_type == type) \
377 ? SvMAGIC (sv) \
378 : mg_find (sv, type))
379
380#define CORO_MAGIC(sv, type) \
381 (expect_true (SvMAGIC (sv)) \
382 ? CORO_MAGIC_NN (sv, type) \
383 : 0)
384
385#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv)
386#define CORO_MAGIC_state(sv) CORO_MAGIC_NN (((SV *)(sv)), CORO_MAGIC_type_state)
387
388INLINE struct coro *
389SvSTATE_ (pTHX_ SV *coro)
390{
391 HV *stash;
392 MAGIC *mg;
393
394 if (SvROK (coro))
395 coro = SvRV (coro);
396
397 if (expect_false (SvTYPE (coro) != SVt_PVHV))
398 croak ("Coro::State object required");
399
400 stash = SvSTASH (coro);
401 if (expect_false (stash != coro_stash && stash != coro_state_stash))
402 {
403 /* very slow, but rare, check */
404 if (!sv_derived_from (sv_2mortal (newRV_inc (coro)), "Coro::State"))
405 croak ("Coro::State object required");
406 }
407
408 mg = CORO_MAGIC_state (coro);
409 return (struct coro *)mg->mg_ptr;
410}
411
412#define SvSTATE(sv) SvSTATE_ (aTHX_ (sv))
413
414/* faster than SvSTATE, but expects a coroutine hv */
415#define SvSTATE_hv(hv) ((struct coro *)CORO_MAGIC_NN ((SV *)hv, CORO_MAGIC_type_state)->mg_ptr)
416#define SvSTATE_current SvSTATE_hv (SvRV (coro_current))
417
418/*****************************************************************************/
419/* padlist management and caching */
359 420
360static AV * 421static AV *
361coro_derive_padlist (pTHX_ CV *cv) 422coro_derive_padlist (pTHX_ CV *cv)
362{ 423{
363 AV *padlist = CvPADLIST (cv); 424 AV *padlist = CvPADLIST (cv);
371 Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); 432 Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1);
372#endif 433#endif
373 newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; 434 newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)];
374 --AvFILLp (padlist); 435 --AvFILLp (padlist);
375 436
376 av_store (newpadlist, 0, SvREFCNT_inc_NN (*av_fetch (padlist, 0, FALSE))); 437 av_store (newpadlist, 0, SvREFCNT_inc_NN (AvARRAY (padlist)[0]));
377 av_store (newpadlist, 1, (SV *)newpad); 438 av_store (newpadlist, 1, (SV *)newpad);
378 439
379 return newpadlist; 440 return newpadlist;
380} 441}
381 442
382static void 443static void
383free_padlist (pTHX_ AV *padlist) 444free_padlist (pTHX_ AV *padlist)
384{ 445{
385 /* may be during global destruction */ 446 /* may be during global destruction */
386 if (SvREFCNT (padlist)) 447 if (!IN_DESTRUCT)
387 { 448 {
388 I32 i = AvFILLp (padlist); 449 I32 i = AvFILLp (padlist);
389 while (i >= 0) 450
451 while (i > 0) /* special-case index 0 */
390 { 452 {
453 /* we try to be extra-careful here */
391 SV **svp = AvARRAY (padlist)[i--]; 454 AV *av = (AV *)AvARRAY (padlist)[i--];
392 if (svp) 455 I32 j = AvFILLp (av);
393 { 456
394 AvREAL_on (*svp); 457 while (j >= 0)
395 av_undef (*svp); 458 SvREFCNT_dec (AvARRAY (av)[j--]);
459
460 AvFILLp (av) = -1;
396 SvREFCNT_dec (*svp); 461 SvREFCNT_dec (av);
397 }
398 } 462 }
399 463
464 SvREFCNT_dec (AvARRAY (padlist)[0]);
465
466 AvFILLp (padlist) = -1;
400 SvREFCNT_dec ((SV*)padlist); 467 SvREFCNT_dec ((SV*)padlist);
401 } 468 }
402} 469}
403 470
404static int 471static int
413 480
414 SvREFCNT_dec (av); /* sv_magicext increased the refcount */ 481 SvREFCNT_dec (av); /* sv_magicext increased the refcount */
415 482
416 return 0; 483 return 0;
417} 484}
418
419#define CORO_MAGIC_type_cv 26
420#define CORO_MAGIC_type_state PERL_MAGIC_ext
421 485
422static MGVTBL coro_cv_vtbl = { 486static MGVTBL coro_cv_vtbl = {
423 0, 0, 0, 0, 487 0, 0, 0, 0,
424 coro_cv_free 488 coro_cv_free
425}; 489};
426
427#define CORO_MAGIC_NN(sv, type) \
428 (expect_true (SvMAGIC (sv)->mg_type == type) \
429 ? SvMAGIC (sv) \
430 : mg_find (sv, type))
431
432#define CORO_MAGIC(sv, type) \
433 (expect_true (SvMAGIC (sv)) \
434 ? CORO_MAGIC_NN (sv, type) \
435 : 0)
436
437#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv)
438#define CORO_MAGIC_state(sv) CORO_MAGIC_NN (((SV *)(sv)), CORO_MAGIC_type_state)
439
440INLINE struct coro *
441SvSTATE_ (pTHX_ SV *coro)
442{
443 HV *stash;
444 MAGIC *mg;
445
446 if (SvROK (coro))
447 coro = SvRV (coro);
448
449 if (expect_false (SvTYPE (coro) != SVt_PVHV))
450 croak ("Coro::State object required");
451
452 stash = SvSTASH (coro);
453 if (expect_false (stash != coro_stash && stash != coro_state_stash))
454 {
455 /* very slow, but rare, check */
456 if (!sv_derived_from (sv_2mortal (newRV_inc (coro)), "Coro::State"))
457 croak ("Coro::State object required");
458 }
459
460 mg = CORO_MAGIC_state (coro);
461 return (struct coro *)mg->mg_ptr;
462}
463
464#define SvSTATE(sv) SvSTATE_ (aTHX_ (sv))
465
466/* faster than SvSTATE, but expects a coroutine hv */
467#define SvSTATE_hv(hv) ((struct coro *)CORO_MAGIC_NN ((SV *)hv, CORO_MAGIC_type_state)->mg_ptr)
468#define SvSTATE_current SvSTATE_hv (SvRV (coro_current))
469 490
470/* the next two functions merely cache the padlists */ 491/* the next two functions merely cache the padlists */
471static void 492static void
472get_padlist (pTHX_ CV *cv) 493get_padlist (pTHX_ CV *cv)
473{ 494{
509} 530}
510 531
511/** load & save, init *******************************************************/ 532/** load & save, init *******************************************************/
512 533
513static void 534static void
535on_enterleave_call (pTHX_ SV *cb);
536
537static void
514load_perl (pTHX_ Coro__State c) 538load_perl (pTHX_ Coro__State c)
515{ 539{
516 perl_slots *slot = c->slot; 540 perl_slots *slot = c->slot;
517 c->slot = 0; 541 c->slot = 0;
518 542
544 PUTBACK; 568 PUTBACK;
545 } 569 }
546 570
547 slf_frame = c->slf_frame; 571 slf_frame = c->slf_frame;
548 CORO_THROW = c->except; 572 CORO_THROW = c->except;
573
574 if (expect_false (c->on_enter))
575 {
576 int i;
577
578 for (i = 0; i <= AvFILLp (c->on_enter); ++i)
579 on_enterleave_call (AvARRAY (c->on_enter)[i]);
580 }
549} 581}
550 582
551static void 583static void
552save_perl (pTHX_ Coro__State c) 584save_perl (pTHX_ Coro__State c)
553{ 585{
586 if (expect_false (c->on_leave))
587 {
588 int i;
589
590 for (i = AvFILLp (c->on_leave); i >= 0; --i)
591 on_enterleave_call (AvARRAY (c->on_leave)[i]);
592 }
593
554 c->except = CORO_THROW; 594 c->except = CORO_THROW;
555 c->slf_frame = slf_frame; 595 c->slf_frame = slf_frame;
556 596
557 { 597 {
558 dSP; 598 dSP;
757#endif 797#endif
758 798
759/* 799/*
760 * This overrides the default magic get method of %SIG elements. 800 * This overrides the default magic get method of %SIG elements.
761 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook 801 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook
762 * and instead of tryign to save and restore the hash elements, we just provide 802 * and instead of trying to save and restore the hash elements, we just provide
763 * readback here. 803 * readback here.
764 * We only do this when the hook is != 0, as they are often set to 0 temporarily,
765 * not expecting this to actually change the hook. This is a potential problem
766 * when a schedule happens then, but we ignore this.
767 */ 804 */
768static int 805static int
769coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) 806coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg)
770{ 807{
771 const char *s = MgPV_nolen_const (mg); 808 const char *s = MgPV_nolen_const (mg);
824 if (strEQ (s, "__WARN__")) svp = &PL_warnhook; 861 if (strEQ (s, "__WARN__")) svp = &PL_warnhook;
825 862
826 if (svp) 863 if (svp)
827 { 864 {
828 SV *old = *svp; 865 SV *old = *svp;
829 *svp = newSVsv (sv); 866 *svp = SvOK (sv) ? newSVsv (sv) : 0;
830 SvREFCNT_dec (old); 867 SvREFCNT_dec (old);
831 return 0; 868 return 0;
832 } 869 }
833 } 870 }
834 871
926 /* copy throw, in case it was set before coro_setup */ 963 /* copy throw, in case it was set before coro_setup */
927 CORO_THROW = coro->except; 964 CORO_THROW = coro->except;
928} 965}
929 966
930static void 967static void
931coro_destruct (pTHX_ struct coro *coro) 968coro_unwind_stacks (pTHX)
932{ 969{
933 if (!IN_DESTRUCT) 970 if (!IN_DESTRUCT)
934 { 971 {
935 /* restore all saved variables and stuff */ 972 /* restore all saved variables and stuff */
936 LEAVE_SCOPE (0); 973 LEAVE_SCOPE (0);
944 POPSTACK_TO (PL_mainstack); 981 POPSTACK_TO (PL_mainstack);
945 982
946 /* unwind main stack */ 983 /* unwind main stack */
947 dounwind (-1); 984 dounwind (-1);
948 } 985 }
986}
987
988static void
989coro_destruct_perl (pTHX_ struct coro *coro)
990{
991 coro_unwind_stacks (aTHX);
949 992
950 SvREFCNT_dec (GvSV (PL_defgv)); 993 SvREFCNT_dec (GvSV (PL_defgv));
951 SvREFCNT_dec (GvAV (PL_defgv)); 994 SvREFCNT_dec (GvAV (PL_defgv));
952 SvREFCNT_dec (GvSV (PL_errgv)); 995 SvREFCNT_dec (GvSV (PL_errgv));
953 SvREFCNT_dec (PL_defoutgv); 996 SvREFCNT_dec (PL_defoutgv);
1265cctx_destroy (coro_cctx *cctx) 1308cctx_destroy (coro_cctx *cctx)
1266{ 1309{
1267 if (!cctx) 1310 if (!cctx)
1268 return; 1311 return;
1269 1312
1270 assert (cctx != cctx_current);//D temporary 1313 assert (("FATAL: tried to destroy current cctx", cctx != cctx_current));//D temporary?
1271 1314
1272 --cctx_count; 1315 --cctx_count;
1273 coro_destroy (&cctx->cctx); 1316 coro_destroy (&cctx->cctx);
1274 1317
1275 /* coro_transfer creates new, empty cctx's */ 1318 /* coro_transfer creates new, empty cctx's */
1393 coro_setup (aTHX_ next); 1436 coro_setup (aTHX_ next);
1394 } 1437 }
1395 else 1438 else
1396 load_perl (aTHX_ next); 1439 load_perl (aTHX_ next);
1397 1440
1398 assert (!prev->cctx);//D temporary
1399
1400 /* possibly untie and reuse the cctx */ 1441 /* possibly untie and reuse the cctx */
1401 if (expect_true ( 1442 if (expect_true (
1402 cctx_current->idle_sp == STACKLEVEL 1443 cctx_current->idle_sp == STACKLEVEL
1403 && !(cctx_current->flags & CC_TRACE) 1444 && !(cctx_current->flags & CC_TRACE)
1404 && !force_cctx 1445 && !force_cctx
1459 --coro_nready; 1500 --coro_nready;
1460 } 1501 }
1461 else 1502 else
1462 coro->flags |= CF_READY; /* make sure it is NOT put into the readyqueue */ 1503 coro->flags |= CF_READY; /* make sure it is NOT put into the readyqueue */
1463 1504
1464 if (coro->mainstack && coro->mainstack != main_mainstack) 1505 if (coro->mainstack
1506 && coro->mainstack != main_mainstack
1507 && coro->slot
1508 && !PL_dirty)
1465 { 1509 {
1466 struct coro temp; 1510 struct coro *current = SvSTATE_current;
1467 1511
1468 assert (("FATAL: tried to destroy currently running coroutine (please report)", !(coro->flags & CF_RUNNING))); 1512 assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack));
1469 1513
1470 save_perl (aTHX_ &temp); 1514 save_perl (aTHX_ current);
1471 load_perl (aTHX_ coro); 1515 load_perl (aTHX_ coro);
1472 1516
1473 coro_destruct (aTHX_ coro); 1517 coro_destruct_perl (aTHX_ coro);
1474 1518
1475 load_perl (aTHX_ &temp); 1519 load_perl (aTHX_ current);
1476 1520
1477 coro->slot = 0; 1521 coro->slot = 0;
1478 } 1522 }
1479 1523
1480 cctx_destroy (coro->cctx); 1524 cctx_destroy (coro->cctx);
1850 av_push (av_destroy, (SV *)newRV_inc ((SV *)hv)); /* RVinc for perl */ 1894 av_push (av_destroy, (SV *)newRV_inc ((SV *)hv)); /* RVinc for perl */
1851 api_ready (aTHX_ sv_manager); 1895 api_ready (aTHX_ sv_manager);
1852 1896
1853 frame->prepare = prepare_schedule; 1897 frame->prepare = prepare_schedule;
1854 frame->check = slf_check_repeat; 1898 frame->check = slf_check_repeat;
1899
1900 /* as a minor optimisation, we could unwind all stacks here */
1901 /* but that puts extra pressure on pp_slf, and is not worth much */
1902 /*coro_unwind_stacks (aTHX);*/
1855} 1903}
1856 1904
1857/*****************************************************************************/ 1905/*****************************************************************************/
1858/* async pool handler */ 1906/* async pool handler */
1859 1907
2278 2326
2279 PL_op->op_ppaddr = pp_slf; 2327 PL_op->op_ppaddr = pp_slf;
2280 /*PL_op->op_type = OP_CUSTOM; /* we do behave like entersub still */ 2328 /*PL_op->op_type = OP_CUSTOM; /* we do behave like entersub still */
2281 2329
2282 PL_op = (OP *)&slf_restore; 2330 PL_op = (OP *)&slf_restore;
2331}
2332
2333/*****************************************************************************/
2334/* dynamic wind */
2335
2336static void
2337on_enterleave_call (pTHX_ SV *cb)
2338{
2339 dSP;
2340
2341 PUSHSTACK;
2342
2343 PUSHMARK (SP);
2344 PUTBACK;
2345 call_sv (cb, G_VOID | G_DISCARD);
2346 SPAGAIN;
2347
2348 POPSTACK;
2349}
2350
2351static SV *
2352coro_avp_pop_and_free (AV **avp)
2353{
2354 AV *av = *avp;
2355 SV *res = av_pop (av);
2356
2357 if (AvFILLp (av) < 0)
2358 {
2359 *avp = 0;
2360 SvREFCNT_dec (av);
2361 }
2362
2363 return res;
2364}
2365
2366static void
2367coro_pop_on_enter (pTHX_ void *coro)
2368{
2369 SV *cb = coro_avp_pop_and_free (&((struct coro *)coro)->on_enter);
2370 SvREFCNT_dec (cb);
2371}
2372
2373static void
2374coro_pop_on_leave (pTHX_ void *coro)
2375{
2376 SV *cb = coro_avp_pop_and_free (&((struct coro *)coro)->on_leave);
2377 on_enterleave_call (sv_2mortal (cb));
2283} 2378}
2284 2379
2285/*****************************************************************************/ 2380/*****************************************************************************/
2286/* PerlIO::cede */ 2381/* PerlIO::cede */
2287 2382
2913SV * 3008SV *
2914clone (Coro::State coro) 3009clone (Coro::State coro)
2915 CODE: 3010 CODE:
2916{ 3011{
2917#if CORO_CLONE 3012#if CORO_CLONE
2918 struct coro *ncoro = coro_clone (coro); 3013 struct coro *ncoro = coro_clone (aTHX_ coro);
2919 MAGIC *mg; 3014 MAGIC *mg;
2920 /* TODO: too much duplication */ 3015 /* TODO: too much duplication */
2921 ncoro->hv = newHV (); 3016 ncoro->hv = newHV ();
2922 mg = sv_magicext ((SV *)ncoro->hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)ncoro, 0); 3017 mg = sv_magicext ((SV *)ncoro->hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)ncoro, 0);
2923 mg->mg_flags |= MGf_DUP; 3018 mg->mg_flags |= MGf_DUP;
2985 eval = 1 3080 eval = 1
2986 CODE: 3081 CODE:
2987{ 3082{
2988 if (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot)) 3083 if (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot))
2989 { 3084 {
2990 struct coro temp; 3085 struct coro *current = SvSTATE_current;
2991 3086
2992 if (!(coro->flags & CF_RUNNING)) 3087 if (current != coro)
2993 { 3088 {
2994 PUTBACK; 3089 PUTBACK;
2995 save_perl (aTHX_ &temp); 3090 save_perl (aTHX_ current);
2996 load_perl (aTHX_ coro); 3091 load_perl (aTHX_ coro);
3092 SPAGAIN;
2997 } 3093 }
2998 3094
2999 {
3000 dSP;
3001 ENTER;
3002 SAVETMPS;
3003 PUTBACK;
3004 PUSHSTACK; 3095 PUSHSTACK;
3096
3005 PUSHMARK (SP); 3097 PUSHMARK (SP);
3098 PUTBACK;
3006 3099
3007 if (ix) 3100 if (ix)
3008 eval_sv (coderef, 0); 3101 eval_sv (coderef, 0);
3009 else 3102 else
3010 call_sv (coderef, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 3103 call_sv (coderef, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
3011 3104
3105 SPAGAIN;
3012 POPSTACK; 3106 POPSTACK;
3013 SPAGAIN;
3014 FREETMPS;
3015 LEAVE;
3016 PUTBACK;
3017 }
3018 3107
3019 if (!(coro->flags & CF_RUNNING)) 3108 if (current != coro)
3020 { 3109 {
3110 PUTBACK;
3021 save_perl (aTHX_ coro); 3111 save_perl (aTHX_ coro);
3022 load_perl (aTHX_ &temp); 3112 load_perl (aTHX_ current);
3023 SPAGAIN; 3113 SPAGAIN;
3024 } 3114 }
3025 } 3115 }
3026} 3116}
3027 3117
3114{ 3204{
3115 int i; 3205 int i;
3116 3206
3117 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); 3207 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
3118 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); 3208 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
3119 cv_coro_run = get_cv ( "Coro::_terminate", GV_ADD); 3209 cv_coro_run = get_cv ( "Coro::_coro_run" , GV_ADD);
3120 cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); 3210 cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD);
3121 coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); 3211 coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current);
3122 av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); 3212 av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE);
3123 av_destroy = coro_get_av (aTHX_ "Coro::destroy" , TRUE); 3213 av_destroy = coro_get_av (aTHX_ "Coro::destroy" , TRUE);
3124 sv_manager = coro_get_sv (aTHX_ "Coro::manager" , TRUE); 3214 sv_manager = coro_get_sv (aTHX_ "Coro::manager" , TRUE);
3309rouse_wait (...) 3399rouse_wait (...)
3310 PROTOTYPE: ;$ 3400 PROTOTYPE: ;$
3311 PPCODE: 3401 PPCODE:
3312 CORO_EXECUTE_SLF_XS (slf_init_rouse_wait); 3402 CORO_EXECUTE_SLF_XS (slf_init_rouse_wait);
3313 3403
3404void
3405on_enter (SV *block)
3406 ALIAS:
3407 on_leave = 1
3408 PROTOTYPE: &
3409 CODE:
3410{
3411 struct coro *coro = SvSTATE_current;
3412 AV **avp = ix ? &coro->on_leave : &coro->on_enter;
3413
3414 block = (SV *)coro_sv_2cv (block);
3415
3416 if (!*avp)
3417 *avp = newAV ();
3418
3419 av_push (*avp, SvREFCNT_inc (block));
3420
3421 if (!ix)
3422 on_enterleave_call (aTHX_ block);
3423
3424 LEAVE; /* pp_entersub unfortunately forces an ENTER/LEAVE around xs calls */
3425 SAVEDESTRUCTOR_X (ix ? coro_pop_on_leave : coro_pop_on_enter, (void *)coro);
3426 ENTER; /* pp_entersub unfortunately forces an ENTER/LEAVE around xs calls */
3427}
3428
3314 3429
3315MODULE = Coro::State PACKAGE = PerlIO::cede 3430MODULE = Coro::State PACKAGE = PerlIO::cede
3316 3431
3317BOOT: 3432BOOT:
3318 PerlIO_define_layer (aTHX_ &PerlIO_cede); 3433 PerlIO_define_layer (aTHX_ &PerlIO_cede);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines