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.47 by pcg, Sat Nov 15 03:53:10 2003 UTC vs.
Revision 1.55 by pcg, Thu Apr 1 02:29:05 2004 UTC

39# undef HAVE_MMAP 39# undef HAVE_MMAP
40# endif 40# endif
41# endif 41# endif
42#endif 42#endif
43 43
44#define MAY_FLUSH /* increases codesize and is rarely used */
45
46#define SUB_INIT "Coro::State::initialize" 44#define SUB_INIT "Coro::State::initialize"
47#define UCORO_STATE "_coro_state" 45#define UCORO_STATE "_coro_state"
48 46
49/* The next macro should declare a variable stacklevel that contains and approximation 47/* The next macro should declare a variable stacklevel that contains and approximation
50 * to the current C stack pointer. Its property is that it changes with each call 48 * to the current C stack pointer. Its property is that it changes with each call
54#define IN_DESTRUCT (PL_main_cv == Nullcv) 52#define IN_DESTRUCT (PL_main_cv == Nullcv)
55 53
56#define labs(l) ((l) >= 0 ? (l) : -(l)) 54#define labs(l) ((l) >= 0 ? (l) : -(l))
57 55
58#include "CoroAPI.h" 56#include "CoroAPI.h"
57
58#ifdef USE_ITHREADS
59static perl_mutex coro_mutex;
60# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0)
61# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0)
62#else
63# define LOCK 0
64# define UNLOCK 0
65#endif
59 66
60static struct CoroAPI coroapi; 67static struct CoroAPI coroapi;
61 68
62/* this is actually not only the c stack but also c registers etc... */ 69/* this is actually not only the c stack but also c registers etc... */
63typedef struct { 70typedef struct {
127 134
128static AV *main_mainstack; /* used to differentiate between $main and others */ 135static AV *main_mainstack; /* used to differentiate between $main and others */
129static HV *coro_state_stash; 136static HV *coro_state_stash;
130static SV *ucoro_state_sv; 137static SV *ucoro_state_sv;
131static U32 ucoro_state_hash; 138static U32 ucoro_state_hash;
132static HV *padlist_cache;
133static SV *coro_mortal; /* will be freed after next transfer */ 139static SV *coro_mortal; /* will be freed after next transfer */
134 140
135/* mostly copied from op.c:cv_clone2 */ 141/* mostly copied from op.c:cv_clone2 */
136STATIC AV * 142STATIC AV *
137clone_padlist (AV *protopadlist) 143clone_padlist (AV *protopadlist)
166 AvFLAGS (av) = AVf_REIFY; 172 AvFLAGS (av) = AVf_REIFY;
167 173
168 for (ix = fpad; ix > 0; ix--) 174 for (ix = fpad; ix > 0; ix--)
169 { 175 {
170 SV *namesv = (ix <= fname) ? pname[ix] : Nullsv; 176 SV *namesv = (ix <= fname) ? pname[ix] : Nullsv;
177
171 if (namesv && namesv != &PL_sv_undef) 178 if (namesv && namesv != &PL_sv_undef)
172 { 179 {
173 char *name = SvPVX (namesv); /* XXX */ 180 char *name = SvPVX (namesv); /* XXX */
181
174 if (SvFLAGS (namesv) & SVf_FAKE || *name == '&') 182 if (SvFLAGS (namesv) & SVf_FAKE || *name == '&')
175 { /* lexical from outside? */ 183 { /* lexical from outside? */
176 npad[ix] = SvREFCNT_inc (ppad[ix]); 184 npad[ix] = SvREFCNT_inc (ppad[ix]);
177 } 185 }
178 else 186 else
184 sv = (SV *) newAV (); 192 sv = (SV *) newAV ();
185 else if (*name == '%') 193 else if (*name == '%')
186 sv = (SV *) newHV (); 194 sv = (SV *) newHV ();
187 else 195 else
188 sv = NEWSV (0, 0); 196 sv = NEWSV (0, 0);
197
198#ifdef SvPADBUSY
189 if (!SvPADBUSY (sv)) 199 if (!SvPADBUSY (sv))
200#endif
190 SvPADMY_on (sv); 201 SvPADMY_on (sv);
202
191 npad[ix] = sv; 203 npad[ix] = sv;
192 } 204 }
193 } 205 }
194 else if (IS_PADGV (ppad[ix]) || IS_PADCONST (ppad[ix])) 206 else if (IS_PADGV (ppad[ix]) || IS_PADCONST (ppad[ix]))
195 { 207 {
224#endif 236#endif
225 237
226 return newpadlist; 238 return newpadlist;
227} 239}
228 240
229#ifdef MAY_FLUSH
230STATIC void 241STATIC void
231free_padlist (AV *padlist) 242free_padlist (AV *padlist)
232{ 243{
233 /* may be during global destruction */ 244 /* may be during global destruction */
234 if (SvREFCNT(padlist)) 245 if (SvREFCNT (padlist))
235 { 246 {
236 I32 i = AvFILLp(padlist); 247 I32 i = AvFILLp (padlist);
237 while (i >= 0) 248 while (i >= 0)
238 { 249 {
239 SV **svp = av_fetch(padlist, i--, FALSE); 250 SV **svp = av_fetch (padlist, i--, FALSE);
240 SV *sv = svp ? *svp : Nullsv;
241 if (sv) 251 if (svp)
252 {
253 SV *sv;
254 while (&PL_sv_undef != (sv = av_pop ((AV *)*svp)))
242 SvREFCNT_dec(sv); 255 SvREFCNT_dec (sv);
256
257 SvREFCNT_dec (*svp);
258 }
243 } 259 }
244 260
245 SvREFCNT_dec((SV*)padlist); 261 SvREFCNT_dec ((SV*)padlist);
246 } 262 }
247} 263}
248#endif 264
265STATIC int
266coro_cv_free (pTHX_ SV *sv, MAGIC *mg)
267{
268 AV *padlist;
269 AV *av = (AV *)mg->mg_obj;
270
271 /* casting is fun. */
272 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av)))
273 free_padlist (padlist);
274}
275
276#define PERL_MAGIC_coro PERL_MAGIC_ext
277
278static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free};
249 279
250/* the next two functions merely cache the padlists */ 280/* the next two functions merely cache the padlists */
251STATIC void 281STATIC void
252get_padlist (CV *cv) 282get_padlist (CV *cv)
253{ 283{
254 SV **he = hv_fetch (padlist_cache, (void *)&cv, sizeof (CV *), 0); 284 MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
255 285
256 if (he && AvFILLp ((AV *)*he) >= 0) 286 if (mg && AvFILLp ((AV *)mg->mg_obj) >= 0)
257 CvPADLIST (cv) = (AV *)av_pop ((AV *)*he); 287 CvPADLIST (cv) = (AV *)av_pop ((AV *)mg->mg_obj);
258 else 288 else
259 CvPADLIST (cv) = clone_padlist (CvPADLIST (cv)); 289 CvPADLIST (cv) = clone_padlist (CvPADLIST (cv));
260} 290}
261 291
262STATIC void 292STATIC void
263put_padlist (CV *cv) 293put_padlist (CV *cv)
264{ 294{
265 SV **he = hv_fetch (padlist_cache, (void *)&cv, sizeof (CV *), 1); 295 MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
266 296
267 if (SvTYPE (*he) != SVt_PVAV) 297 if (!mg)
268 { 298 {
269 SvREFCNT_dec (*he); 299 sv_magic ((SV *)cv, 0, PERL_MAGIC_coro, 0, 0);
300 mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
301 mg->mg_virtual = &vtbl_coro;
270 *he = (SV *)newAV (); 302 mg->mg_obj = (SV *)newAV ();
271 } 303 }
272 304
273 av_push ((AV *)*he, (SV *)CvPADLIST (cv)); 305 av_push ((AV *)mg->mg_obj, (SV *)CvPADLIST (cv));
274} 306}
275
276#ifdef MAY_FLUSH
277STATIC void
278flush_padlist_cache ()
279{
280 HV *hv = padlist_cache;
281 padlist_cache = newHV ();
282
283 if (hv_iterinit (hv))
284 {
285 HE *he;
286 AV *padlist;
287
288 while (!!(he = hv_iternext (hv)))
289 {
290 AV *av = (AV *)HeVAL(he);
291
292 /* casting is fun. */
293 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av)))
294 free_padlist (padlist);
295 }
296 }
297
298 SvREFCNT_dec (hv);
299}
300#endif
301 307
302#define SB do { 308#define SB do {
303#define SE } while (0) 309#define SE } while (0)
304 310
305#define LOAD(state) load_state(aTHX_ (state)); 311#define LOAD(state) load_state(aTHX_ (state));
356 362
357 if (padlist) 363 if (padlist)
358 { 364 {
359 put_padlist (cv); /* mark this padlist as available */ 365 put_padlist (cv); /* mark this padlist as available */
360 CvPADLIST(cv) = padlist; 366 CvPADLIST(cv) = padlist;
361#ifdef USE_THREADS
362 /*CvOWNER(cv) = (struct perl_thread *)POPs;*/
363#endif
364 } 367 }
365 368
366 ++CvDEPTH(cv); 369 ++CvDEPTH(cv);
367 } 370 }
368 371
395 if (CxTYPE(cx) == CXt_SUB) 398 if (CxTYPE(cx) == CXt_SUB)
396 { 399 {
397 CV *cv = cx->blk_sub.cv; 400 CV *cv = cx->blk_sub.cv;
398 if (CvDEPTH(cv)) 401 if (CvDEPTH(cv))
399 { 402 {
400#ifdef USE_THREADS
401 /*XPUSHs ((SV *)CvOWNER(cv));*/
402 /*CvOWNER(cv) = 0;*/
403 /*error must unlock this cv etc.. etc...*/
404#endif
405 EXTEND (SP, CvDEPTH(cv)*2); 403 EXTEND (SP, CvDEPTH(cv)*2);
406 404
407 while (--CvDEPTH(cv)) 405 while (--CvDEPTH(cv))
408 { 406 {
409 /* this tells the restore code to increment CvDEPTH */ 407 /* this tells the restore code to increment CvDEPTH */
475} 473}
476 474
477/* 475/*
478 * allocate various perl stacks. This is an exact copy 476 * allocate various perl stacks. This is an exact copy
479 * of perl.c:init_stacks, except that it uses less memory 477 * of perl.c:init_stacks, except that it uses less memory
480 * on the assumption that coroutines do not usually need 478 * on the (sometimes correct) assumption that coroutines do
481 * a lot of stackspace. 479 * not usually need a lot of stackspace.
482 */ 480 */
483STATIC void 481STATIC void
484coro_init_stacks (pTHX) 482coro_init_stacks (pTHX)
485{ 483{
484 LOCK;
485
486 PL_curstackinfo = new_stackinfo(96, 1024/sizeof(PERL_CONTEXT) - 1); 486 PL_curstackinfo = new_stackinfo(96, 1024/sizeof(PERL_CONTEXT) - 1);
487 PL_curstackinfo->si_type = PERLSI_MAIN; 487 PL_curstackinfo->si_type = PERLSI_MAIN;
488 PL_curstack = PL_curstackinfo->si_stack; 488 PL_curstack = PL_curstackinfo->si_stack;
489 PL_mainstack = PL_curstack; /* remember in case we switch stacks */ 489 PL_mainstack = PL_curstack; /* remember in case we switch stacks */
490 490
514 PL_savestack_max = 96; 514 PL_savestack_max = 96;
515 515
516 New(54,PL_retstack,8,OP*); 516 New(54,PL_retstack,8,OP*);
517 PL_retstack_ix = 0; 517 PL_retstack_ix = 0;
518 PL_retstack_max = 8; 518 PL_retstack_max = 8;
519
520 UNLOCK;
519} 521}
520 522
521/* 523/*
522 * destroy the stacks, the callchain etc... 524 * destroy the stacks, the callchain etc...
523 * still there is a memleak of 128 bytes...
524 */ 525 */
525STATIC void 526STATIC void
526destroy_stacks(pTHX) 527destroy_stacks(pTHX)
527{ 528{
528 if (!IN_DESTRUCT) 529 if (!IN_DESTRUCT)
529 { 530 {
530 /* is this ugly, I ask? */ 531 /* is this ugly, I ask? */
531 while (PL_scopestack_ix) 532 LEAVE_SCOPE (0);
532 LEAVE;
533 533
534 /* sure it is, but more important: is it correct?? :/ */ 534 /* sure it is, but more important: is it correct?? :/ */
535 while (PL_tmps_ix > PL_tmps_floor) /* should only ever be one iteration */
536 FREETMPS; 535 FREETMPS;
537 } 536 }
538 537
539 while (PL_curstackinfo->si_next) 538 while (PL_curstackinfo->si_next)
540 PL_curstackinfo = PL_curstackinfo->si_next; 539 PL_curstackinfo = PL_curstackinfo->si_next;
541 540
575 New (0, stack, 1, coro_stack); 574 New (0, stack, 1, coro_stack);
576 575
577 stack->refcnt = 1; 576 stack->refcnt = 1;
578 stack->usecnt = 1; 577 stack->usecnt = 1;
579 stack->gencnt = ctx->gencnt = 0; 578 stack->gencnt = ctx->gencnt = 0;
579
580 if (alloc) 580 if (alloc)
581 { 581 {
582#if HAVE_MMAP 582#if HAVE_MMAP
583 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */ 583 stack->ssize = 16384 * sizeof (long); /* mmap should do allocate-on-write for us */
584 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 584 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
585 if (stack->sptr == (void *)-1) 585 if (stack->sptr == (void *)-1)
586#endif 586#endif
587 { 587 {
588 /*FIXME*//*D*//* reasonable stack size! */ 588 /*FIXME*//*D*//* reasonable stack size! */
589 stack->ssize = -4096 * sizeof (long); 589 stack->ssize = - (8192 * sizeof (long));
590 New (0, stack->sptr, 4096, long); 590 New (0, stack->sptr, 8192, long);
591 } 591 }
592 } 592 }
593 else 593 else
594 stack->sptr = 0; 594 stack->sptr = 0;
595 595
627 /* 627 /*
628 * emulate part of the perl startup here. 628 * emulate part of the perl startup here.
629 */ 629 */
630 dSP; 630 dSP;
631 Coro__State ctx = (Coro__State)arg; 631 Coro__State ctx = (Coro__State)arg;
632 SV *sub_init = (SV*)get_cv(SUB_INIT, FALSE); 632 SV *sub_init = (SV *)get_cv (SUB_INIT, FALSE);
633 633
634 coro_init_stacks (aTHX); 634 coro_init_stacks (aTHX);
635 /*PL_curcop = 0;*/ 635 /*PL_curcop = 0;*/
636 /*PL_in_eval = PL_in_eval;*/ /* inherit */ 636 /*PL_in_eval = PL_in_eval;*/ /* inherit */
637 SvREFCNT_dec (GvAV (PL_defgv)); 637 SvREFCNT_dec (GvAV (PL_defgv));
696 696
697 abort (); 697 abort ();
698} 698}
699 699
700STATIC void 700STATIC void
701transfer(pTHX_ struct coro *prev, struct coro *next, int flags) 701transfer (pTHX_ struct coro *prev, struct coro *next, int flags)
702{ 702{
703 dSTACKLEVEL; 703 dSTACKLEVEL;
704 static struct coro *xnext;
705 704
706 if (prev != next) 705 if (prev != next)
707 { 706 {
708 xnext = next;
709
710 if (next->mainstack) 707 if (next->mainstack)
711 { 708 {
709 LOCK;
712 SAVE (prev, flags); 710 SAVE (prev, flags);
713 LOAD (next); 711 LOAD (next);
712 UNLOCK;
714 713
715 /* mark this state as in-use */ 714 /* mark this state as in-use */
716 next->mainstack = 0; 715 next->mainstack = 0;
717 next->tmps_ix = -2; 716 next->tmps_ix = -2;
718 717
737 continue_coro, (void *)next, 736 continue_coro, (void *)next,
738 next->stack->sptr, labs (next->stack->ssize)); 737 next->stack->sptr, labs (next->stack->ssize));
739 } 738 }
740 739
741 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 740 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
741 prev->cursp = stacklevel;
742 /* don't add any code here */ 742 /* don't add any code here */
743 } 743 }
744 744 else
745 next->cursp = stacklevel;
745 } 746 }
746 else if (next->tmps_ix == -2) 747 else if (next->tmps_ix == -2)
747 croak ("tried to transfer to running coroutine"); 748 croak ("tried to transfer to running coroutine");
748 else 749 else
749 { 750 {
751 LOCK;
750 SAVE (prev, -1); /* first get rid of the old state */ 752 SAVE (prev, -1); /* first get rid of the old state */
753 UNLOCK;
751 754
752 if (flags & TRANSFER_SAVE_CCTXT) 755 if (flags & TRANSFER_SAVE_CCTXT)
753 { 756 {
754 if (!prev->stack) 757 if (!prev->stack)
755 allocate_stack (prev, 0); 758 allocate_stack (prev, 0);
757 if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK) 760 if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK)
758 { 761 {
759 PL_top_env = &next->start_env; 762 PL_top_env = &next->start_env;
760 763
761 setup_coro (next); 764 setup_coro (next);
765 next->cursp = stacklevel;
762 766
763 prev->stack->refcnt++; 767 prev->stack->refcnt++;
764 prev->stack->usecnt++; 768 prev->stack->usecnt++;
765 next->stack = prev->stack; 769 next->stack = prev->stack;
766 next->gencnt = prev->gencnt; 770 next->gencnt = prev->gencnt;
771 allocate_stack (next, 1); 775 allocate_stack (next, 1);
772 coro_create (&(next->stack->cctx), 776 coro_create (&(next->stack->cctx),
773 setup_coro, (void *)next, 777 setup_coro, (void *)next,
774 next->stack->sptr, labs (next->stack->ssize)); 778 next->stack->sptr, labs (next->stack->ssize));
775 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 779 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
780 prev->cursp = stacklevel;
776 /* don't add any code here */ 781 /* don't add any code here */
777 } 782 }
778 } 783 }
779 else 784 else
785 {
780 setup_coro (next); 786 setup_coro (next);
787 next->cursp = stacklevel;
788 }
781 } 789 }
782
783 /*
784 * xnext is now either prev or next, depending on wether
785 * we switched the c stack or not. that's why I use a global
786 * variable, that should become thread-specific at one point.
787 */
788 xnext->cursp = stacklevel;
789 } 790 }
790 791
792 LOCK;
791 if (coro_mortal) 793 if (coro_mortal)
792 { 794 {
793 SvREFCNT_dec (coro_mortal); 795 SvREFCNT_dec (coro_mortal);
794 coro_mortal = 0; 796 coro_mortal = 0;
795 } 797 }
798 UNLOCK;
796} 799}
797 800
798#define SV_CORO(sv,func) \ 801#define SV_CORO(sv,func) \
799 do { \ 802 do { \
800 if (SvROK (sv)) \ 803 if (SvROK (sv)) \
801 sv = SvRV (sv); \ 804 sv = SvRV (sv); \
802 \ 805 \
803 if (SvTYPE(sv) == SVt_PVHV) \ 806 if (SvTYPE (sv) == SVt_PVHV) \
804 { \ 807 { \
805 HE *he = hv_fetch_ent((HV *)sv, ucoro_state_sv, 0, ucoro_state_hash); \ 808 HE *he = hv_fetch_ent ((HV *)sv, ucoro_state_sv, 0, ucoro_state_hash); \
806 \ 809 \
807 if (!he) \ 810 if (!he) \
808 croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", func, # sv); \ 811 croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", func, # sv); \
809 \ 812 \
810 (sv) = SvRV (HeVAL(he)); \ 813 (sv) = SvRV (HeVAL(he)); \
811 } \ 814 } \
812 \ 815 \
813 /* must also be changed inside Coro::Cont::yield */ \ 816 /* must also be changed inside Coro::Cont::yield */ \
814 if (!SvOBJECT(sv) || SvSTASH(sv) != coro_state_stash) \ 817 if (!SvOBJECT (sv) || SvSTASH (sv) != coro_state_stash) \
815 croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \ 818 croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \
816 \ 819 \
817 } while(0) 820 } while(0)
818 821
819#define SvSTATE(sv) (struct coro *)SvIV (sv) 822#define SvSTATE(sv) (struct coro *)SvIV (sv)
885api_ready (SV *coro) 888api_ready (SV *coro)
886{ 889{
887 if (SvROK (coro)) 890 if (SvROK (coro))
888 coro = SvRV (coro); 891 coro = SvRV (coro);
889 892
893 LOCK;
890 coro_enq (SvREFCNT_inc (coro)); 894 coro_enq (SvREFCNT_inc (coro));
895 UNLOCK;
891} 896}
892 897
893static void 898static void
894api_schedule (void) 899api_schedule (void)
895{ 900{
896 SV *prev, *next; 901 SV *prev, *next;
902
903 LOCK;
897 904
898 prev = SvRV (GvSV (coro_current)); 905 prev = SvRV (GvSV (coro_current));
899 next = coro_deq (PRIO_MIN); 906 next = coro_deq (PRIO_MIN);
900 907
901 if (!next) 908 if (!next)
907 914
908 SvRV (GvSV (coro_current)) = next; 915 SvRV (GvSV (coro_current)) = next;
909 916
910 SV_CORO (next, "Coro::schedule"); 917 SV_CORO (next, "Coro::schedule");
911 918
919 UNLOCK;
920
912 transfer (aTHX_ SvSTATE (prev), SvSTATE (next), 921 transfer (aTHX_ SvSTATE (prev), SvSTATE (next),
913 TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK); 922 TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK);
914} 923}
915 924
916static void 925static void
917api_cede (void) 926api_cede (void)
918{ 927{
928 LOCK;
919 coro_enq (SvREFCNT_inc (SvRV (GvSV (coro_current)))); 929 coro_enq (SvREFCNT_inc (SvRV (GvSV (coro_current))));
930 UNLOCK;
920 931
921 api_schedule (); 932 api_schedule ();
922} 933}
923 934
924MODULE = Coro::State PACKAGE = Coro::State 935MODULE = Coro::State PACKAGE = Coro::State
925 936
926PROTOTYPES: ENABLE 937PROTOTYPES: ENABLE
927 938
928BOOT: 939BOOT:
929{ /* {} necessary for stoopid perl-5.6.x */ 940{ /* {} necessary for stoopid perl-5.6.x */
941#ifdef USE_ITHREADS
942 MUTEX_INIT (&coro_mutex);
943#endif
944
930 ucoro_state_sv = newSVpv (UCORO_STATE, sizeof(UCORO_STATE) - 1); 945 ucoro_state_sv = newSVpv (UCORO_STATE, sizeof(UCORO_STATE) - 1);
931 PERL_HASH(ucoro_state_hash, UCORO_STATE, sizeof(UCORO_STATE) - 1); 946 PERL_HASH(ucoro_state_hash, UCORO_STATE, sizeof(UCORO_STATE) - 1);
932 coro_state_stash = gv_stashpv ("Coro::State", TRUE); 947 coro_state_stash = gv_stashpv ("Coro::State", TRUE);
933 948
934 newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (TRANSFER_SAVE_DEFAV)); 949 newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (TRANSFER_SAVE_DEFAV));
935 newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (TRANSFER_SAVE_DEFSV)); 950 newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (TRANSFER_SAVE_DEFSV));
936 newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (TRANSFER_SAVE_ERRSV)); 951 newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (TRANSFER_SAVE_ERRSV));
937 newCONSTSUB (coro_state_stash, "SAVE_CCTXT", newSViv (TRANSFER_SAVE_CCTXT)); 952 newCONSTSUB (coro_state_stash, "SAVE_CCTXT", newSViv (TRANSFER_SAVE_CCTXT));
938
939 if (!padlist_cache)
940 padlist_cache = newHV ();
941 953
942 main_mainstack = PL_mainstack; 954 main_mainstack = PL_mainstack;
943 955
944 coroapi.ver = CORO_API_VERSION; 956 coroapi.ver = CORO_API_VERSION;
945 coroapi.transfer = api_transfer; 957 coroapi.transfer = api_transfer;
1009 deallocate_stack (coro); 1021 deallocate_stack (coro);
1010 SvREFCNT_dec (coro->args); 1022 SvREFCNT_dec (coro->args);
1011 Safefree (coro); 1023 Safefree (coro);
1012 1024
1013void 1025void
1014flush()
1015 CODE:
1016#ifdef MAY_FLUSH
1017 flush_padlist_cache ();
1018#endif
1019
1020void
1021_exit(code) 1026_exit(code)
1022 int code 1027 int code
1023 PROTOTYPE: $ 1028 PROTOTYPE: $
1024 CODE: 1029 CODE:
1025#if defined(__GLIBC__) || _POSIX_C_SOURCE
1026 _exit (code); 1030 _exit (code);
1027#else
1028 signal (SIGTERM, SIG_DFL);
1029 raise (SIGTERM);
1030 exit (code);
1031#endif
1032 1031
1033MODULE = Coro::State PACKAGE = Coro::Cont 1032MODULE = Coro::State PACKAGE = Coro::Cont
1034 1033
1035# this is slightly dirty (should expose a c-level api) 1034# this is slightly dirty (should expose a c-level api)
1036 1035
1095 sv_setiv(sv, (IV)&coroapi); 1094 sv_setiv(sv, (IV)&coroapi);
1096 SvREADONLY_on(sv); 1095 SvREADONLY_on(sv);
1097 } 1096 }
1098} 1097}
1099 1098
1099#if !PERL_MICRO
1100
1100void 1101void
1101ready(self) 1102ready(self)
1102 SV * self 1103 SV * self
1103 PROTOTYPE: $ 1104 PROTOTYPE: $
1104 CODE: 1105 CODE:
1105 api_ready (self); 1106 api_ready (self);
1107
1108#endif
1106 1109
1107int 1110int
1108nready(...) 1111nready(...)
1109 PROTOTYPE: 1112 PROTOTYPE:
1110 CODE: 1113 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines