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.410 by root, Sun Jun 12 08:14:12 2011 UTC vs.
Revision 1.421 by root, Sun May 27 16:36:05 2012 UTC

63#endif 63#endif
64 64
65/* the maximum number of idle cctx that will be pooled */ 65/* the maximum number of idle cctx that will be pooled */
66static int cctx_max_idle = 4; 66static int cctx_max_idle = 4;
67 67
68#if defined(DEBUGGING) && PERL_VERSION_ATLEAST(5,12,0)
69# define HAS_SCOPESTACK_NAME 1
70#endif
71
68#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 72#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
69# undef CORO_STACKGUARD 73# undef CORO_STACKGUARD
70#endif 74#endif
71 75
72#ifndef CORO_STACKGUARD 76#ifndef CORO_STACKGUARD
97# if CORO_PTHREAD 101# if CORO_PTHREAD
98static void *coro_thx; 102static void *coro_thx;
99# endif 103# endif
100#endif 104#endif
101 105
102/* used in state.h */
103#define VAR(name,type) VARx(name, PL_ ## name, type)
104
105#ifdef __linux 106#ifdef __linux
106# include <time.h> /* for timespec */ 107# include <time.h> /* for timespec */
107# include <syscall.h> /* for SYS_* */ 108# include <syscall.h> /* for SYS_* */
108# ifdef SYS_clock_gettime 109# ifdef SYS_clock_gettime
109# define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) 110# define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
177 void *sptr; 178 void *sptr;
178 size_t ssize; 179 size_t ssize;
179 180
180 /* cpu state */ 181 /* cpu state */
181 void *idle_sp; /* sp of top-level transfer/schedule/cede call */ 182 void *idle_sp; /* sp of top-level transfer/schedule/cede call */
183#ifndef NDEBUG
182 JMPENV *idle_te; /* same as idle_sp, but for top_env, TODO: remove once stable */ 184 JMPENV *idle_te; /* same as idle_sp, but for top_env */
185#endif
183 JMPENV *top_env; 186 JMPENV *top_env;
184 coro_context cctx; 187 coro_context cctx;
185 188
186 U32 gen; 189 U32 gen;
187#if CORO_USE_VALGRIND 190#if CORO_USE_VALGRIND
207}; 210};
208 211
209/* the structure where most of the perl state is stored, overlaid on the cxstack */ 212/* the structure where most of the perl state is stored, overlaid on the cxstack */
210typedef struct 213typedef struct
211{ 214{
212#define VARx(name,expr,type) type name; 215 #define VARx(name,expr,type) type name;
213# include "state.h" 216 #include "state.h"
214#undef VARx
215} perl_slots; 217} perl_slots;
216 218
217/* how many context stack entries do we need for perl_slots */ 219/* how many context stack entries do we need for perl_slots */
218#define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT)) 220#define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT))
219 221
335 337
336/** time stuff **************************************************************/ 338/** time stuff **************************************************************/
337 339
338#ifdef HAS_GETTIMEOFDAY 340#ifdef HAS_GETTIMEOFDAY
339 341
340ECB_INLINE void 342ecb_inline void
341coro_u2time (pTHX_ UV ret[2]) 343coro_u2time (pTHX_ UV ret[2])
342{ 344{
343 struct timeval tv; 345 struct timeval tv;
344 gettimeofday (&tv, 0); 346 gettimeofday (&tv, 0);
345 347
346 ret [0] = tv.tv_sec; 348 ret [0] = tv.tv_sec;
347 ret [1] = tv.tv_usec; 349 ret [1] = tv.tv_usec;
348} 350}
349 351
350ECB_INLINE double 352ecb_inline double
351coro_nvtime (void) 353coro_nvtime (void)
352{ 354{
353 struct timeval tv; 355 struct timeval tv;
354 gettimeofday (&tv, 0); 356 gettimeofday (&tv, 0);
355 357
356 return tv.tv_sec + tv.tv_usec * 1e-6; 358 return tv.tv_sec + tv.tv_usec * 1e-6;
357} 359}
358 360
359ECB_INLINE void 361ecb_inline void
360time_init (pTHX) 362time_init (pTHX)
361{ 363{
362 nvtime = coro_nvtime; 364 nvtime = coro_nvtime;
363 u2time = coro_u2time; 365 u2time = coro_u2time;
364} 366}
365 367
366#else 368#else
367 369
368ECB_INLINE void 370ecb_inline void
369time_init (pTHX) 371time_init (pTHX)
370{ 372{
371 SV **svp; 373 SV **svp;
372 374
373 require_pv ("Time/HiRes.pm"); 375 require_pv ("Time/HiRes.pm");
415 get_hv (name, create); 417 get_hv (name, create);
416#endif 418#endif
417 return get_hv (name, create); 419 return get_hv (name, create);
418} 420}
419 421
420ECB_INLINE void 422ecb_inline void
421coro_times_update (void) 423coro_times_update (void)
422{ 424{
423#ifdef coro_clock_gettime 425#ifdef coro_clock_gettime
424 struct timespec ts; 426 struct timespec ts;
425 427
438 time_real [0] = tv [0]; 440 time_real [0] = tv [0];
439 time_real [1] = tv [1] * 1000; 441 time_real [1] = tv [1] * 1000;
440#endif 442#endif
441} 443}
442 444
443ECB_INLINE void 445ecb_inline void
444coro_times_add (struct coro *c) 446coro_times_add (struct coro *c)
445{ 447{
446 c->t_real [1] += time_real [1]; 448 c->t_real [1] += time_real [1];
447 if (c->t_real [1] > 1000000000) { c->t_real [1] -= 1000000000; ++c->t_real [0]; } 449 if (c->t_real [1] > 1000000000) { c->t_real [1] -= 1000000000; ++c->t_real [0]; }
448 c->t_real [0] += time_real [0]; 450 c->t_real [0] += time_real [0];
450 c->t_cpu [1] += time_cpu [1]; 452 c->t_cpu [1] += time_cpu [1];
451 if (c->t_cpu [1] > 1000000000) { c->t_cpu [1] -= 1000000000; ++c->t_cpu [0]; } 453 if (c->t_cpu [1] > 1000000000) { c->t_cpu [1] -= 1000000000; ++c->t_cpu [0]; }
452 c->t_cpu [0] += time_cpu [0]; 454 c->t_cpu [0] += time_cpu [0];
453} 455}
454 456
455ECB_INLINE void 457ecb_inline void
456coro_times_sub (struct coro *c) 458coro_times_sub (struct coro *c)
457{ 459{
458 if (c->t_real [1] < time_real [1]) { c->t_real [1] += 1000000000; --c->t_real [0]; } 460 if (c->t_real [1] < time_real [1]) { c->t_real [1] += 1000000000; --c->t_real [0]; }
459 c->t_real [1] -= time_real [1]; 461 c->t_real [1] -= time_real [1];
460 c->t_real [0] -= time_real [0]; 462 c->t_real [0] -= time_real [0];
481 : 0) 483 : 0)
482 484
483#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) 485#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv)
484#define CORO_MAGIC_state(sv) CORO_MAGIC_NN (((SV *)(sv)), CORO_MAGIC_type_state) 486#define CORO_MAGIC_state(sv) CORO_MAGIC_NN (((SV *)(sv)), CORO_MAGIC_type_state)
485 487
486ECB_INLINE MAGIC * 488ecb_inline MAGIC *
487SvSTATEhv_p (pTHX_ SV *coro) 489SvSTATEhv_p (pTHX_ SV *coro)
488{ 490{
489 MAGIC *mg; 491 MAGIC *mg;
490 492
491 if (ecb_expect_true ( 493 if (ecb_expect_true (
496 return mg; 498 return mg;
497 499
498 return 0; 500 return 0;
499} 501}
500 502
501ECB_INLINE struct coro * 503ecb_inline struct coro *
502SvSTATE_ (pTHX_ SV *coro) 504SvSTATE_ (pTHX_ SV *coro)
503{ 505{
504 MAGIC *mg; 506 MAGIC *mg;
505 507
506 if (SvROK (coro)) 508 if (SvROK (coro))
520#define SvSTATE_current SvSTATE_hv (SvRV (coro_current)) 522#define SvSTATE_current SvSTATE_hv (SvRV (coro_current))
521 523
522/*****************************************************************************/ 524/*****************************************************************************/
523/* padlist management and caching */ 525/* padlist management and caching */
524 526
525ECB_INLINE AV * 527ecb_inline AV *
526coro_derive_padlist (pTHX_ CV *cv) 528coro_derive_padlist (pTHX_ CV *cv)
527{ 529{
528 AV *padlist = CvPADLIST (cv); 530 AV *padlist = CvPADLIST (cv);
529 AV *newpadlist, *newpad; 531 AV *newpadlist, *newpad;
530 532
542 av_store (newpadlist, 1, (SV *)newpad); 544 av_store (newpadlist, 1, (SV *)newpad);
543 545
544 return newpadlist; 546 return newpadlist;
545} 547}
546 548
547ECB_INLINE void 549ecb_inline void
548free_padlist (pTHX_ AV *padlist) 550free_padlist (pTHX_ AV *padlist)
549{ 551{
550 /* may be during global destruction */ 552 /* may be during global destruction */
551 if (!IN_DESTRUCT) 553 if (!IN_DESTRUCT)
552 { 554 {
595 0, 0, 0, 0, 597 0, 0, 0, 0,
596 coro_cv_free 598 coro_cv_free
597}; 599};
598 600
599/* the next two functions merely cache the padlists */ 601/* the next two functions merely cache the padlists */
600ECB_INLINE void 602ecb_inline void
601get_padlist (pTHX_ CV *cv) 603get_padlist (pTHX_ CV *cv)
602{ 604{
603 MAGIC *mg = CORO_MAGIC_cv (cv); 605 MAGIC *mg = CORO_MAGIC_cv (cv);
604 AV *av; 606 AV *av;
605 607
618 CvPADLIST (cv) = coro_derive_padlist (aTHX_ cv); 620 CvPADLIST (cv) = coro_derive_padlist (aTHX_ cv);
619#endif 621#endif
620 } 622 }
621} 623}
622 624
623ECB_INLINE void 625ecb_inline void
624put_padlist (pTHX_ CV *cv) 626put_padlist (pTHX_ CV *cv)
625{ 627{
626 MAGIC *mg = CORO_MAGIC_cv (cv); 628 MAGIC *mg = CORO_MAGIC_cv (cv);
627 AV *av; 629 AV *av;
628 630
637 AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv); 639 AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv);
638} 640}
639 641
640/** load & save, init *******************************************************/ 642/** load & save, init *******************************************************/
641 643
644ecb_inline void
645swap_sv (SV *a, SV *b)
646{
647 const U32 keep = SVs_PADSTALE | SVs_PADTMP | SVs_PADMY; /* keep these flags */
648 SV tmp;
649
650 /* swap sv_any */
651 SvANY (&tmp) = SvANY (a); SvANY (a) = SvANY (b); SvANY (b) = SvANY (&tmp);
652
653 /* swap sv_flags */
654 SvFLAGS (&tmp) = SvFLAGS (a);
655 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep);
656 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep);
657
658#if PERL_VERSION_ATLEAST (5,10,0)
659 /* perl 5.10 and later complicates this _quite_ a bit, but it also
660 * is much faster, so no quarrels here. alternatively, we could
661 * sv_upgrade to avoid this.
662 */
663 {
664 /* swap sv_u */
665 tmp.sv_u = a->sv_u; a->sv_u = b->sv_u; b->sv_u = tmp.sv_u;
666
667 /* if SvANY points to the head, we need to adjust the pointers,
668 * as the pointer for a still points to b, and maybe vice versa.
669 */
670 #define svany_in_head(type) \
671 (((1 << SVt_NULL) | (1 << SVt_BIND) | (1 << SVt_IV) | (1 << SVt_RV)) & (1 << (type)))
672
673 if (svany_in_head (SvTYPE (a)))
674 SvANY (a) = (void *)((PTRV)SvANY (a) - (PTRV)b + (PTRV)a);
675
676 if (svany_in_head (SvTYPE (b)))
677 SvANY (b) = (void *)((PTRV)SvANY (b) - (PTRV)a + (PTRV)b);
678 }
679#endif
680}
681
642/* swap sv heads, at least logically */ 682/* swap sv heads, at least logically */
643static void 683static void
644swap_svs (pTHX_ Coro__State c) 684swap_svs (pTHX_ Coro__State c)
645{ 685{
646 int i; 686 int i;
647 687
648 for (i = 0; i <= AvFILLp (c->swap_sv); ) 688 for (i = 0; i <= AvFILLp (c->swap_sv); i += 2)
649 { 689 swap_sv (AvARRAY (c->swap_sv)[i], AvARRAY (c->swap_sv)[i + 1]);
650 SV *a = AvARRAY (c->swap_sv)[i++];
651 SV *b = AvARRAY (c->swap_sv)[i++];
652
653 const U32 keep = SVs_PADSTALE | SVs_PADTMP | SVs_PADMY; /* keep these flags */
654 SV tmp;
655
656 /* swap sv_any */
657 SvANY (&tmp) = SvANY (a); SvANY (a) = SvANY (b); SvANY (b) = SvANY (&tmp);
658
659 /* swap sv_flags */
660 SvFLAGS (&tmp) = SvFLAGS (a);
661 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep);
662 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep);
663
664#if PERL_VERSION_ATLEAST (5,10,0)
665 /* perl 5.10 complicates this _quite_ a bit, but it also is
666 * much faster, so no quarrels here. alternatively, we could
667 * sv_upgrade to avoid this.
668 */
669 {
670 /* swap sv_u */
671 tmp.sv_u = a->sv_u; a->sv_u = b->sv_u; b->sv_u = tmp.sv_u;
672
673 /* if SvANY points to the head, we need to adjust the pointers,
674 * as the pointer for a still points to b, and maybe vice versa.
675 */
676 #define svany_in_head(type) \
677 (((1 << SVt_NULL) | (1 << SVt_BIND) | (1 << SVt_IV) | (1 << SVt_RV)) & (1 << (type)))
678
679 if (svany_in_head (SvTYPE (a)))
680 SvANY (a) = (void *)((PTRV)SvANY (a) - (PTRV)b + (PTRV)a);
681
682 if (svany_in_head (SvTYPE (b)))
683 SvANY (b) = (void *)((PTRV)SvANY (b) - (PTRV)a + (PTRV)b);
684 }
685#endif
686 }
687} 690}
688 691
689#define SWAP_SVS(coro) \ 692#define SWAP_SVS(coro) \
690 if (ecb_expect_false ((coro)->swap_sv)) \ 693 if (ecb_expect_false ((coro)->swap_sv)) \
691 swap_svs (aTHX_ (coro)) 694 swap_svs (aTHX_ (coro))
703 706
704#if CORO_JIT 707#if CORO_JIT
705 load_perl_slots (slot); 708 load_perl_slots (slot);
706#else 709#else
707 #define VARx(name,expr,type) expr = slot->name; 710 #define VARx(name,expr,type) expr = slot->name;
708 # include "state.h" 711 #include "state.h"
709 #undef VARx
710#endif 712#endif
711 713
712 { 714 {
713 dSP; 715 dSP;
714 716
817 819
818 PUTBACK; 820 PUTBACK;
819 } 821 }
820 822
821 /* allocate some space on the context stack for our purposes */ 823 /* allocate some space on the context stack for our purposes */
822 if (ecb_expect_false (cxstack_ix + SLOT_COUNT >= cxstack_max)) 824 if (ecb_expect_false (cxstack_ix + (int)SLOT_COUNT >= cxstack_max))
823 { 825 {
824 unsigned int i; 826 unsigned int i;
825 827
826 for (i = 0; i < SLOT_COUNT; ++i) 828 for (i = 0; i < SLOT_COUNT; ++i)
827 CXINC; 829 CXINC;
836 838
837#if CORO_JIT 839#if CORO_JIT
838 save_perl_slots (slot); 840 save_perl_slots (slot);
839#else 841#else
840 #define VARx(name,expr,type) slot->name = expr; 842 #define VARx(name,expr,type) slot->name = expr;
841 # include "state.h" 843 #include "state.h"
842 #undef VARx
843#endif 844#endif
844 } 845 }
845} 846}
846 847
847/* 848/*
879#endif 880#endif
880 881
881 New(54,PL_scopestack,8,I32); 882 New(54,PL_scopestack,8,I32);
882 PL_scopestack_ix = 0; 883 PL_scopestack_ix = 0;
883 PL_scopestack_max = 8; 884 PL_scopestack_max = 8;
885#if HAS_SCOPESTACK_NAME
886 New(54,PL_scopestack_name,8,const char*);
887#endif
884 888
885 New(54,PL_savestack,24,ANY); 889 New(54,PL_savestack,24,ANY);
886 PL_savestack_ix = 0; 890 PL_savestack_ix = 0;
887 PL_savestack_max = 24; 891 PL_savestack_max = 24;
888 892
916 } 920 }
917 921
918 Safefree (PL_tmps_stack); 922 Safefree (PL_tmps_stack);
919 Safefree (PL_markstack); 923 Safefree (PL_markstack);
920 Safefree (PL_scopestack); 924 Safefree (PL_scopestack);
925#if HAS_SCOPESTACK_NAME
926 Safefree (PL_scopestack_name);
927#endif
921 Safefree (PL_savestack); 928 Safefree (PL_savestack);
922#if !PERL_VERSION_ATLEAST (5,10,0) 929#if !PERL_VERSION_ATLEAST (5,10,0)
923 Safefree (PL_retstack); 930 Safefree (PL_retstack);
924#endif 931#endif
925} 932}
988 if (strEQ (s, "__DIE__" )) svp = &PL_diehook; 995 if (strEQ (s, "__DIE__" )) svp = &PL_diehook;
989 if (strEQ (s, "__WARN__")) svp = &PL_warnhook; 996 if (strEQ (s, "__WARN__")) svp = &PL_warnhook;
990 997
991 if (svp) 998 if (svp)
992 { 999 {
993 sv_setsv (sv, *svp ? *svp : &PL_sv_undef); 1000 SV *ssv;
1001
1002 if (!*svp)
1003 ssv = &PL_sv_undef;
1004 else if (SvTYPE (*svp) == SVt_PVCV) /* perlio directly stores a CV in warnhook. ugh. */
1005 ssv = sv_2mortal (newRV_inc (*svp));
1006 else
1007 ssv = *svp;
1008
1009 sv_setsv (sv, ssv);
994 return 0; 1010 return 0;
995 } 1011 }
996 } 1012 }
997 1013
998 return orig_sigelem_get ? orig_sigelem_get (aTHX_ sv, mg) : 0; 1014 return orig_sigelem_get ? orig_sigelem_get (aTHX_ sv, mg) : 0;
1220 SvREFCNT_dec (coro->invoke_cb); 1236 SvREFCNT_dec (coro->invoke_cb);
1221 SvREFCNT_dec (coro->invoke_av); 1237 SvREFCNT_dec (coro->invoke_av);
1222 } 1238 }
1223} 1239}
1224 1240
1225ECB_INLINE void 1241ecb_inline void
1226free_coro_mortal (pTHX) 1242free_coro_mortal (pTHX)
1227{ 1243{
1228 if (ecb_expect_true (coro_mortal)) 1244 if (ecb_expect_true (coro_mortal))
1229 { 1245 {
1230 SvREFCNT_dec ((SV *)coro_mortal); 1246 SvREFCNT_dec ((SV *)coro_mortal);
1389 slf_frame.prepare = slf_prepare_set_stacklevel; 1405 slf_frame.prepare = slf_prepare_set_stacklevel;
1390 slf_frame.check = slf_check_set_stacklevel; 1406 slf_frame.check = slf_check_set_stacklevel;
1391} 1407}
1392 1408
1393/* the tail of transfer: execute stuff we can only do after a transfer */ 1409/* the tail of transfer: execute stuff we can only do after a transfer */
1394ECB_INLINE void 1410ecb_inline void
1395transfer_tail (pTHX) 1411transfer_tail (pTHX)
1396{ 1412{
1397 free_coro_mortal (aTHX); 1413 free_coro_mortal (aTHX);
1414}
1415
1416/* try to exit the same way perl's main function would do */
1417/* we do not bother resetting the environment or other things *7
1418/* that are not, uhm, essential */
1419/* this obviously also doesn't work when perl is embedded */
1420static void ecb_noinline ecb_cold
1421perlish_exit (pTHX)
1422{
1423 int exitstatus = perl_destruct (PL_curinterp);
1424 perl_free (PL_curinterp);
1425 exit (exitstatus);
1398} 1426}
1399 1427
1400/* 1428/*
1401 * this is a _very_ stripped down perl interpreter ;) 1429 * this is a _very_ stripped down perl interpreter ;)
1402 */ 1430 */
1431 */ 1459 */
1432 1460
1433 /* 1461 /*
1434 * If perl-run returns we assume exit() was being called or the coro 1462 * If perl-run returns we assume exit() was being called or the coro
1435 * fell off the end, which seems to be the only valid (non-bug) 1463 * fell off the end, which seems to be the only valid (non-bug)
1436 * reason for perl_run to return. We try to exit by jumping to the 1464 * reason for perl_run to return. We try to mimic whatever perl is normally
1437 * bootstrap-time "top" top_env, as we cannot restore the "main" 1465 * doing in that case. YMMV.
1438 * coroutine as Coro has no such concept.
1439 * This actually isn't valid with the pthread backend, but OSes requiring
1440 * that backend are too broken to do it in a standards-compliant way.
1441 */ 1466 */
1442 PL_top_env = main_top_env; 1467 perlish_exit (aTHX);
1443 JMPENV_JUMP (2); /* I do not feel well about the hardcoded 2 at all */
1444 } 1468 }
1445} 1469}
1446 1470
1447static coro_cctx * 1471static coro_cctx *
1448cctx_new (void) 1472cctx_new (void)
1480 size_t stack_size; 1504 size_t stack_size;
1481 1505
1482#if HAVE_MMAP 1506#if HAVE_MMAP
1483 cctx->ssize = ((cctx_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; 1507 cctx->ssize = ((cctx_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE;
1484 /* mmap supposedly does allocate-on-write for us */ 1508 /* mmap supposedly does allocate-on-write for us */
1485 cctx->sptr = mmap (0, cctx->ssize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, 0, 0); 1509 cctx->sptr = mmap (0, cctx->ssize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, -1, 0);
1486 1510
1487 if (cctx->sptr != (void *)-1) 1511 if (cctx->sptr != (void *)-1)
1488 { 1512 {
1489 #if CORO_STACKGUARD 1513 #if CORO_STACKGUARD
1490 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); 1514 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE);
1792 TRANSFER (ta, 1); 1816 TRANSFER (ta, 1);
1793} 1817}
1794 1818
1795/** Coro ********************************************************************/ 1819/** Coro ********************************************************************/
1796 1820
1797ECB_INLINE void 1821ecb_inline void
1798coro_enq (pTHX_ struct coro *coro) 1822coro_enq (pTHX_ struct coro *coro)
1799{ 1823{
1800 struct coro **ready = coro_ready [coro->prio - CORO_PRIO_MIN]; 1824 struct coro **ready = coro_ready [coro->prio - CORO_PRIO_MIN];
1801 1825
1802 SvREFCNT_inc_NN (coro->hv); 1826 SvREFCNT_inc_NN (coro->hv);
1804 coro->next_ready = 0; 1828 coro->next_ready = 0;
1805 *(ready [0] ? &ready [1]->next_ready : &ready [0]) = coro; 1829 *(ready [0] ? &ready [1]->next_ready : &ready [0]) = coro;
1806 ready [1] = coro; 1830 ready [1] = coro;
1807} 1831}
1808 1832
1809ECB_INLINE struct coro * 1833ecb_inline struct coro *
1810coro_deq (pTHX) 1834coro_deq (pTHX)
1811{ 1835{
1812 int prio; 1836 int prio;
1813 1837
1814 for (prio = CORO_PRIO_MAX - CORO_PRIO_MIN + 1; --prio >= 0; ) 1838 for (prio = CORO_PRIO_MAX - CORO_PRIO_MIN + 1; --prio >= 0; )
1867{ 1891{
1868 return !!(SvSTATE (coro_sv)->flags & CF_READY); 1892 return !!(SvSTATE (coro_sv)->flags & CF_READY);
1869} 1893}
1870 1894
1871/* expects to own a reference to next->hv */ 1895/* expects to own a reference to next->hv */
1872ECB_INLINE void 1896ecb_inline void
1873prepare_schedule_to (pTHX_ struct coro_transfer_args *ta, struct coro *next) 1897prepare_schedule_to (pTHX_ struct coro_transfer_args *ta, struct coro *next)
1874{ 1898{
1875 SV *prev_sv = SvRV (coro_current); 1899 SV *prev_sv = SvRV (coro_current);
1876 1900
1877 ta->prev = SvSTATE_hv (prev_sv); 1901 ta->prev = SvSTATE_hv (prev_sv);
1936 } 1960 }
1937 } 1961 }
1938 } 1962 }
1939} 1963}
1940 1964
1941ECB_INLINE void 1965ecb_inline void
1942prepare_cede (pTHX_ struct coro_transfer_args *ta) 1966prepare_cede (pTHX_ struct coro_transfer_args *ta)
1943{ 1967{
1944 api_ready (aTHX_ coro_current); 1968 api_ready (aTHX_ coro_current);
1945 prepare_schedule (aTHX_ ta); 1969 prepare_schedule (aTHX_ ta);
1946} 1970}
1947 1971
1948ECB_INLINE void 1972ecb_inline void
1949prepare_cede_notself (pTHX_ struct coro_transfer_args *ta) 1973prepare_cede_notself (pTHX_ struct coro_transfer_args *ta)
1950{ 1974{
1951 SV *prev = SvRV (coro_current); 1975 SV *prev = SvRV (coro_current);
1952 1976
1953 if (coro_nready) 1977 if (coro_nready)
3343#endif 3367#endif
3344 3368
3345#if CORO_JIT 3369#if CORO_JIT
3346 3370
3347static void ecb_noinline ecb_cold 3371static void ecb_noinline ecb_cold
3348pushav_3uv (pTHX_ UV a, UV b, UV c) 3372pushav_4uv (pTHX_ UV a, UV b, UV c, UV d)
3349{ 3373{
3350 dSP; 3374 dSP;
3351 AV *av = newAV (); 3375 AV *av = newAV ();
3352 3376
3377 av_store (av, 3, newSVuv (d));
3353 av_store (av, 2, newSVuv (c)); 3378 av_store (av, 2, newSVuv (c));
3354 av_store (av, 1, newSVuv (b)); 3379 av_store (av, 1, newSVuv (b));
3355 av_store (av, 0, newSVuv (a)); 3380 av_store (av, 0, newSVuv (a));
3356 3381
3357 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); 3382 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
3370 int count; 3395 int count;
3371 3396
3372 eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1); 3397 eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1);
3373 3398
3374 PUSHMARK (SP); 3399 PUSHMARK (SP);
3375#define VARx(name,expr,type) pushav_3uv (aTHX_ (UV)&(expr), offsetof (perl_slots, name), sizeof (type)); 3400 #define VARx(name,expr,type) pushav_4uv (aTHX_ (UV)&(expr), sizeof (expr), offsetof (perl_slots, name), sizeof (type));
3376# include "state.h" 3401 #include "state.h"
3377#undef VARx
3378 count = call_pv ("Coro::State::_jit", G_ARRAY); 3402 count = call_pv ("Coro::State::_jit", G_ARRAY);
3379 SPAGAIN; 3403 SPAGAIN;
3380 3404
3381 save = POPs; save_ptr = SvPVbyte (save, save_len); 3405 save = POPs; save_ptr = SvPVbyte (save, save_len);
3382 load = POPs; load_ptr = SvPVbyte (load, load_len); 3406 load = POPs; load_ptr = SvPVbyte (load, load_len);
4138} 4162}
4139 4163
4140MODULE = Coro::State PACKAGE = Coro::SemaphoreSet 4164MODULE = Coro::State PACKAGE = Coro::SemaphoreSet
4141 4165
4142void 4166void
4143_may_delete (SV *sem, int count, int extra_refs) 4167_may_delete (SV *sem, int count, unsigned int extra_refs)
4144 PPCODE: 4168 PPCODE:
4145{ 4169{
4146 AV *av = (AV *)SvRV (sem); 4170 AV *av = (AV *)SvRV (sem);
4147 4171
4148 if (SvREFCNT ((SV *)av) == 1 + extra_refs 4172 if (SvREFCNT ((SV *)av) == 1 + extra_refs

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines