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.106 by root, Mon Nov 27 02:08:55 2006 UTC vs.
Revision 1.112 by root, Thu Nov 30 20:52:52 2006 UTC

103static struct CoroAPI coroapi; 103static struct CoroAPI coroapi;
104static AV *main_mainstack; /* used to differentiate between $main and others */ 104static AV *main_mainstack; /* used to differentiate between $main and others */
105static HV *coro_state_stash, *coro_stash; 105static HV *coro_state_stash, *coro_stash;
106static SV *coro_mortal; /* will be freed after next transfer */ 106static SV *coro_mortal; /* will be freed after next transfer */
107 107
108static struct coro_cctx *cctx_first;
109static int cctx_count, cctx_idle;
110
108/* this is a structure representing a c-level coroutine */ 111/* this is a structure representing a c-level coroutine */
109typedef struct coro_cctx { 112typedef struct coro_cctx {
110 struct coro_cctx *next; 113 struct coro_cctx *next;
111 114
112 /* the stack */ 115 /* the stack */
116 /* cpu state */ 119 /* cpu state */
117 void *idle_sp; /* sp of top-level transfer/schedule/cede call */ 120 void *idle_sp; /* sp of top-level transfer/schedule/cede call */
118 JMPENV *top_env; 121 JMPENV *top_env;
119 coro_context cctx; 122 coro_context cctx;
120 123
124 int inuse;
125
121#if USE_VALGRIND 126#if USE_VALGRIND
122 int valgrind_id; 127 int valgrind_id;
123#endif 128#endif
124} coro_cctx; 129} coro_cctx;
130
131enum {
132 CF_RUNNING, /* coroutine is running */
133 CF_READY, /* coroutine is ready */
134};
125 135
126/* this is a structure representing a perl-level coroutine */ 136/* this is a structure representing a perl-level coroutine */
127struct coro { 137struct coro {
128 /* the c coroutine allocated to this perl coroutine, if any */ 138 /* the c coroutine allocated to this perl coroutine, if any */
129 coro_cctx *cctx; 139 coro_cctx *cctx;
130 140
131 /* data associated with this coroutine (initial args) */ 141 /* data associated with this coroutine (initial args) */
132 AV *args; 142 AV *args;
133 int refcnt; 143 int refcnt;
144 int flags;
134 145
135 /* optionally saved, might be zero */ 146 /* optionally saved, might be zero */
136 AV *defav; 147 AV *defav;
137 SV *defsv; 148 SV *defsv;
138 SV *errsv; 149 SV *errsv;
139 150
140 /* saved global state not related to stacks */ 151#define VAR(name,type) type name;
141 U8 dowarn; 152# include "state.h"
142 I32 in_eval; 153#undef VAR
143
144 /* the stacks and related info (callchain etc..) */
145 PERL_SI *curstackinfo;
146 AV *curstack;
147 AV *mainstack;
148 SV **stack_sp;
149 OP *op;
150 SV **curpad;
151 AV *comppad;
152 CV *compcv;
153 SV **stack_base;
154 SV **stack_max;
155 SV **tmps_stack;
156 I32 tmps_floor;
157 I32 tmps_ix;
158 I32 tmps_max;
159 I32 *markstack;
160 I32 *markstack_ptr;
161 I32 *markstack_max;
162 I32 *scopestack;
163 I32 scopestack_ix;
164 I32 scopestack_max;
165 ANY *savestack;
166 I32 savestack_ix;
167 I32 savestack_max;
168 OP **retstack;
169 I32 retstack_ix;
170 I32 retstack_max;
171 PMOP *curpm;
172 COP *curcop;
173 154
174 /* coro process data */ 155 /* coro process data */
175 int prio; 156 int prio;
176}; 157};
177 158
241 222
242#define PERL_MAGIC_coro PERL_MAGIC_ext 223#define PERL_MAGIC_coro PERL_MAGIC_ext
243 224
244static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free}; 225static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free};
245 226
227#define CORO_MAGIC(cv) \
228 SvMAGIC (cv) \
229 ? SvMAGIC (cv)->mg_type == PERL_MAGIC_coro \
230 ? SvMAGIC (cv) \
231 : mg_find ((SV *)cv, PERL_MAGIC_coro) \
232 : 0
233
246/* the next two functions merely cache the padlists */ 234/* the next two functions merely cache the padlists */
247static void 235static void
248get_padlist (CV *cv) 236get_padlist (CV *cv)
249{ 237{
250 MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro); 238 MAGIC *mg = CORO_MAGIC (cv);
239 AV *av;
251 240
252 if (mg && AvFILLp ((AV *)mg->mg_obj) >= 0) 241 if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)
253 CvPADLIST (cv) = (AV *)av_pop ((AV *)mg->mg_obj); 242 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--];
254 else 243 else
255 { 244 {
256#if 0 245#if 0
257 /* this is probably cleaner, but also slower? */ 246 /* this is probably cleaner, but also slower? */
258 CV *cp = Perl_cv_clone (cv); 247 CV *cp = Perl_cv_clone (cv);
266} 255}
267 256
268static void 257static void
269put_padlist (CV *cv) 258put_padlist (CV *cv)
270{ 259{
271 MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro); 260 MAGIC *mg = CORO_MAGIC (cv);
261 AV *av;
272 262
273 if (!mg) 263 if (!mg)
274 { 264 {
275 sv_magic ((SV *)cv, 0, PERL_MAGIC_coro, 0, 0); 265 sv_magic ((SV *)cv, 0, PERL_MAGIC_coro, 0, 0);
276 mg = mg_find ((SV *)cv, PERL_MAGIC_coro); 266 mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
277 mg->mg_virtual = &vtbl_coro; 267 mg->mg_virtual = &vtbl_coro;
278 mg->mg_obj = (SV *)newAV (); 268 mg->mg_obj = (SV *)newAV ();
279 } 269 }
280 270
281 av_push ((AV *)mg->mg_obj, (SV *)CvPADLIST (cv)); 271 av = (AV *)mg->mg_obj;
272
273 if (AvFILLp (av) >= AvMAX (av))
274 av_extend (av, AvMAX (av) + 1);
275
276 AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv);
282} 277}
283 278
284#define SB do { 279#define SB do {
285#define SE } while (0) 280#define SE } while (0)
286 281
290#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); (val) = 0; SE 285#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); (val) = 0; SE
291 286
292static void 287static void
293load_state(Coro__State c) 288load_state(Coro__State c)
294{ 289{
295 PL_dowarn = c->dowarn; 290#define VAR(name,type) PL_ ## name = c->name;
296 PL_in_eval = c->in_eval; 291# include "state.h"
297 292#undef VAR
298 PL_curstackinfo = c->curstackinfo;
299 PL_curstack = c->curstack;
300 PL_mainstack = c->mainstack;
301 PL_stack_sp = c->stack_sp;
302 PL_op = c->op;
303 PL_curpad = c->curpad;
304 PL_comppad = c->comppad;
305 PL_compcv = c->compcv;
306 PL_stack_base = c->stack_base;
307 PL_stack_max = c->stack_max;
308 PL_tmps_stack = c->tmps_stack;
309 PL_tmps_floor = c->tmps_floor;
310 PL_tmps_ix = c->tmps_ix;
311 PL_tmps_max = c->tmps_max;
312 PL_markstack = c->markstack;
313 PL_markstack_ptr = c->markstack_ptr;
314 PL_markstack_max = c->markstack_max;
315 PL_scopestack = c->scopestack;
316 PL_scopestack_ix = c->scopestack_ix;
317 PL_scopestack_max = c->scopestack_max;
318 PL_savestack = c->savestack;
319 PL_savestack_ix = c->savestack_ix;
320 PL_savestack_max = c->savestack_max;
321#if !PERL_VERSION_ATLEAST (5,9,0)
322 PL_retstack = c->retstack;
323 PL_retstack_ix = c->retstack_ix;
324 PL_retstack_max = c->retstack_max;
325#endif
326 PL_curpm = c->curpm;
327 PL_curcop = c->curcop;
328 293
329 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 294 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
330 if (c->defsv) REPLACE_SV (DEFSV , c->defsv); 295 if (c->defsv) REPLACE_SV (DEFSV , c->defsv);
331 if (c->errsv) REPLACE_SV (ERRSV , c->errsv); 296 if (c->errsv) REPLACE_SV (ERRSV , c->errsv);
332 297
335 CV *cv; 300 CV *cv;
336 301
337 /* now do the ugly restore mess */ 302 /* now do the ugly restore mess */
338 while ((cv = (CV *)POPs)) 303 while ((cv = (CV *)POPs))
339 { 304 {
340 AV *padlist = (AV *)POPs;
341
342 if (padlist)
343 {
344 put_padlist (cv); /* mark this padlist as available */ 305 put_padlist (cv); /* mark this padlist as available */
345 CvPADLIST(cv) = padlist; 306 CvDEPTH (cv) = PTR2IV (POPs);
346 } 307 CvPADLIST (cv) = (AV *)POPs;
347
348 ++CvDEPTH(cv);
349 } 308 }
350 309
351 PUTBACK; 310 PUTBACK;
352 } 311 }
353} 312}
375 PERL_CONTEXT *cx = &ccstk[cxix--]; 334 PERL_CONTEXT *cx = &ccstk[cxix--];
376 335
377 if (CxTYPE(cx) == CXt_SUB) 336 if (CxTYPE(cx) == CXt_SUB)
378 { 337 {
379 CV *cv = cx->blk_sub.cv; 338 CV *cv = cx->blk_sub.cv;
339
380 if (CvDEPTH(cv)) 340 if (CvDEPTH (cv))
381 { 341 {
382 EXTEND (SP, CvDEPTH(cv)*2); 342 EXTEND (SP, 3);
383
384 while (--CvDEPTH(cv))
385 {
386 /* this tells the restore code to increment CvDEPTH */
387 PUSHs (Nullsv);
388 PUSHs ((SV *)cv);
389 }
390 343
391 PUSHs ((SV *)CvPADLIST(cv)); 344 PUSHs ((SV *)CvPADLIST(cv));
345 PUSHs (INT2PTR (SV *, CvDEPTH (cv)));
392 PUSHs ((SV *)cv); 346 PUSHs ((SV *)cv);
393 347
348 CvDEPTH (cv) = 0;
394 get_padlist (cv); 349 get_padlist (cv);
395 } 350 }
396 } 351 }
397#ifdef CXt_FORMAT 352#ifdef CXt_FORMAT
398 else if (CxTYPE(cx) == CXt_FORMAT) 353 else if (CxTYPE(cx) == CXt_FORMAT)
417 372
418 c->defav = flags & TRANSFER_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0; 373 c->defav = flags & TRANSFER_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0;
419 c->defsv = flags & TRANSFER_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0; 374 c->defsv = flags & TRANSFER_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0;
420 c->errsv = flags & TRANSFER_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0; 375 c->errsv = flags & TRANSFER_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0;
421 376
422 c->dowarn = PL_dowarn; 377#define VAR(name,type)c->name = PL_ ## name;
423 c->in_eval = PL_in_eval; 378# include "state.h"
424 379#undef VAR
425 c->curstackinfo = PL_curstackinfo;
426 c->curstack = PL_curstack;
427 c->mainstack = PL_mainstack;
428 c->stack_sp = PL_stack_sp;
429 c->op = PL_op;
430 c->curpad = PL_curpad;
431 c->comppad = PL_comppad;
432 c->compcv = PL_compcv;
433 c->stack_base = PL_stack_base;
434 c->stack_max = PL_stack_max;
435 c->tmps_stack = PL_tmps_stack;
436 c->tmps_floor = PL_tmps_floor;
437 c->tmps_ix = PL_tmps_ix;
438 c->tmps_max = PL_tmps_max;
439 c->markstack = PL_markstack;
440 c->markstack_ptr = PL_markstack_ptr;
441 c->markstack_max = PL_markstack_max;
442 c->scopestack = PL_scopestack;
443 c->scopestack_ix = PL_scopestack_ix;
444 c->scopestack_max = PL_scopestack_max;
445 c->savestack = PL_savestack;
446 c->savestack_ix = PL_savestack_ix;
447 c->savestack_max = PL_savestack_max;
448#if !PERL_VERSION_ATLEAST (5,9,0)
449 c->retstack = PL_retstack;
450 c->retstack_ix = PL_retstack_ix;
451 c->retstack_max = PL_retstack_max;
452#endif
453 c->curpm = PL_curpm;
454 c->curcop = PL_curcop;
455} 380}
456 381
457/* 382/*
458 * allocate various perl stacks. This is an exact copy 383 * allocate various perl stacks. This is an exact copy
459 * of perl.c:init_stacks, except that it uses less memory 384 * of perl.c:init_stacks, except that it uses less memory
578 myop.op_flags = OPf_WANT_VOID; 503 myop.op_flags = OPf_WANT_VOID;
579 504
580 PL_op = (OP *)&myop; 505 PL_op = (OP *)&myop;
581 506
582 PUSHMARK (SP); 507 PUSHMARK (SP);
583 XPUSHs ((SV *)get_cv ("Coro::State::coro_init", FALSE)); 508 XPUSHs ((SV *)get_cv ("Coro::State::_coro_init", FALSE));
584 PUTBACK; 509 PUTBACK;
585 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); 510 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
586 SPAGAIN; 511 SPAGAIN;
587 512
588 ENTER; /* necessary e.g. for dounwind */ 513 ENTER; /* necessary e.g. for dounwind */
607 532
608 Zero (&myop, 1, LOGOP); 533 Zero (&myop, 1, LOGOP);
609 myop.op_next = PL_op; 534 myop.op_next = PL_op;
610 myop.op_flags = OPf_WANT_VOID; 535 myop.op_flags = OPf_WANT_VOID;
611 536
612 sv_setiv (get_sv ("Coro::State::cctx", FALSE), PTR2IV (cctx)); 537 sv_setiv (get_sv ("Coro::State::_cctx", FALSE), PTR2IV (cctx));
613 538
614 PUSHMARK (SP); 539 PUSHMARK (SP);
615 XPUSHs ((SV *)get_cv ("Coro::State::cctx_init", FALSE)); 540 XPUSHs ((SV *)get_cv ("Coro::State::_cctx_init", FALSE));
616 PUTBACK; 541 PUTBACK;
617 PL_restartop = PL_ppaddr[OP_ENTERSUB](aTHX); 542 PL_restartop = PL_ppaddr[OP_ENTERSUB](aTHX);
618 SPAGAIN; 543 SPAGAIN;
619} 544}
620 545
626 551
627 /* 552 /*
628 * this is a _very_ stripped down perl interpreter ;) 553 * this is a _very_ stripped down perl interpreter ;)
629 */ 554 */
630 PL_top_env = &PL_start_env; 555 PL_top_env = &PL_start_env;
556
631 /* inject call to cctx_init */ 557 /* inject call to cctx_init */
632 prepare_cctx ((coro_cctx *)arg); 558 prepare_cctx ((coro_cctx *)arg);
633 559
634 /* somebody will hit me for both perl_run and PL_restartop */ 560 /* somebody will hit me for both perl_run and PL_restartop */
635 perl_run (PL_curinterp); 561 perl_run (PL_curinterp);
640 566
641static coro_cctx * 567static coro_cctx *
642cctx_new () 568cctx_new ()
643{ 569{
644 coro_cctx *cctx; 570 coro_cctx *cctx;
571
572 ++cctx_count;
645 573
646 New (0, cctx, 1, coro_cctx); 574 New (0, cctx, 1, coro_cctx);
647 575
648#if HAVE_MMAP 576#if HAVE_MMAP
649 577
690cctx_free (coro_cctx *cctx) 618cctx_free (coro_cctx *cctx)
691{ 619{
692 if (!cctx) 620 if (!cctx)
693 return; 621 return;
694 622
623 --cctx_count;
624
695#if USE_VALGRIND 625#if USE_VALGRIND
696 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); 626 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id);
697#endif 627#endif
698 628
699#if HAVE_MMAP 629#if HAVE_MMAP
702 Safefree (cctx->sptr); 632 Safefree (cctx->sptr);
703#endif 633#endif
704 634
705 Safefree (cctx); 635 Safefree (cctx);
706} 636}
707
708static coro_cctx *cctx_first;
709static int cctx_count, cctx_idle;
710 637
711static coro_cctx * 638static coro_cctx *
712cctx_get () 639cctx_get ()
713{ 640{
714 coro_cctx *cctx; 641 coro_cctx *cctx;
719 cctx = cctx_first; 646 cctx = cctx_first;
720 cctx_first = cctx->next; 647 cctx_first = cctx->next;
721 } 648 }
722 else 649 else
723 { 650 {
724 ++cctx_count;
725 cctx = cctx_new (); 651 cctx = cctx_new ();
726 PL_op = PL_op->op_next; 652 PL_op = PL_op->op_next;
727 } 653 }
728 654
729 return cctx; 655 return cctx;
747 if (flags == TRANSFER_SET_STACKLEVEL) 673 if (flags == TRANSFER_SET_STACKLEVEL)
748 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 674 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
749 else if (prev != next) 675 else if (prev != next)
750 { 676 {
751 coro_cctx *prev__cctx; 677 coro_cctx *prev__cctx;
678
679 if (!prev->cctx)
680 {
681 /* create a new empty context */
682 Newz (0, prev->cctx, 1, coro_cctx);
683 prev->cctx->inuse = 1;
684 prev->flags |= CF_RUNNING;
685 }
686
687 if (!prev->flags & CF_RUNNING)
688 croak ("Coro::State::transfer called with non-running prev Coro::State, but can only transfer from running states");
689
690 if (next->flags & CF_RUNNING)
691 croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states");
692
693 prev->flags &= ~CF_RUNNING;
694 next->flags |= CF_RUNNING;
752 695
753 LOCK; 696 LOCK;
754 697
755 if (next->mainstack) 698 if (next->mainstack)
756 { 699 {
763 /* need to start coroutine */ 706 /* need to start coroutine */
764 /* first get rid of the old state */ 707 /* first get rid of the old state */
765 SAVE (prev, -1); 708 SAVE (prev, -1);
766 /* setup coroutine call */ 709 /* setup coroutine call */
767 setup_coro (next); 710 setup_coro (next);
768 /* need a stack */ 711 /* need a new stack */
769 next->cctx = 0; 712 assert (!next->stack);
770 } 713 }
771
772 if (!prev->cctx)
773 /* create a new empty context */
774 Newz (0, prev->cctx, 1, coro_cctx);
775 714
776 prev__cctx = prev->cctx; 715 prev__cctx = prev->cctx;
777 716
778 /* possibly "free" the cctx */ 717 /* possibly "free" the cctx */
779 if (prev__cctx->idle_sp == STACKLEVEL) 718 if (prev__cctx->idle_sp == STACKLEVEL)
780 { 719 {
720 assert (PL_top_env == prev__cctx->top_env);
721
781 cctx_put (prev__cctx); 722 cctx_put (prev__cctx);
782 prev->cctx = 0; 723 prev->cctx = 0;
783 } 724 }
784 725
785 if (!next->cctx) 726 if (!next->cctx)
786 next->cctx = cctx_get (); 727 next->cctx = cctx_get ();
787 728
788 if (prev__cctx != next->cctx) 729 if (prev__cctx != next->cctx)
789 { 730 {
731 assert ( prev__cctx->inuse);
732 assert (!next->cctx->inuse);
733
734 prev__cctx->inuse = 0;
735 next->cctx->inuse = 1;
736
790 prev__cctx->top_env = PL_top_env; 737 prev__cctx->top_env = PL_top_env;
791 PL_top_env = next->cctx->top_env; 738 PL_top_env = next->cctx->top_env;
792 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); 739 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx);
793 } 740 }
794 741
809static void 756static void
810coro_state_destroy (struct coro *coro) 757coro_state_destroy (struct coro *coro)
811{ 758{
812 if (coro->refcnt--) 759 if (coro->refcnt--)
813 return; 760 return;
761
762 if (coro->flags & CF_RUNNING)
763 croak ("FATAL: tried to destroy currently running coroutine");
814 764
815 if (coro->mainstack && coro->mainstack != main_mainstack) 765 if (coro->mainstack && coro->mainstack != main_mainstack)
816 { 766 {
817 struct coro temp; 767 struct coro temp;
818 768
916static GV *coro_current, *coro_idle; 866static GV *coro_current, *coro_idle;
917static AV *coro_ready [PRIO_MAX-PRIO_MIN+1]; 867static AV *coro_ready [PRIO_MAX-PRIO_MIN+1];
918static int coro_nready; 868static int coro_nready;
919 869
920static void 870static void
921coro_enq (SV *sv) 871coro_enq (SV *coro_sv)
922{ 872{
923 int prio;
924
925 if (SvTYPE (sv) != SVt_PVHV)
926 croak ("Coro::ready tried to enqueue something that is not a coroutine");
927
928 prio = SvSTATE (sv)->prio;
929
930 av_push (coro_ready [prio - PRIO_MIN], sv); 873 av_push (coro_ready [SvSTATE (coro_sv)->prio - PRIO_MIN], coro_sv);
931 coro_nready++; 874 coro_nready++;
932} 875}
933 876
934static SV * 877static SV *
935coro_deq (int min_prio) 878coro_deq (int min_prio)
948 } 891 }
949 892
950 return 0; 893 return 0;
951} 894}
952 895
953static void 896static int
954api_ready (SV *coro) 897api_ready (SV *coro_sv)
955{ 898{
956 dTHX; 899 struct coro *coro;
957 900
958 if (SvROK (coro)) 901 if (SvROK (coro_sv))
959 coro = SvRV (coro); 902 coro_sv = SvRV (coro_sv);
903
904 coro = SvSTATE (coro_sv);
905
906 if (coro->flags & CF_READY)
907 return 0;
908
909 if (coro->flags & CF_RUNNING)
910 croak ("Coro::ready called on currently running coroutine");
911
912 coro->flags |= CF_READY;
960 913
961 LOCK; 914 LOCK;
962 coro_enq (SvREFCNT_inc (coro)); 915 coro_enq (SvREFCNT_inc (coro_sv));
963 UNLOCK; 916 UNLOCK;
917
918 return 1;
919}
920
921static int
922api_is_ready (SV *coro_sv)
923{
924 return !!SvSTATE (coro_sv)->flags & CF_READY;
964} 925}
965 926
966static void 927static void
967prepare_schedule (struct transfer_args *ta) 928prepare_schedule (struct transfer_args *ta)
968{ 929{
1004 coro_mortal = prev; 965 coro_mortal = prev;
1005 966
1006 ta->prev = SvSTATE (prev); 967 ta->prev = SvSTATE (prev);
1007 ta->next = SvSTATE (next); 968 ta->next = SvSTATE (next);
1008 ta->flags = TRANSFER_SAVE_ALL; 969 ta->flags = TRANSFER_SAVE_ALL;
970
971 ta->next->flags &= ~CF_READY;
1009} 972}
1010 973
1011static void 974static void
1012prepare_cede (struct transfer_args *ta) 975prepare_cede (struct transfer_args *ta)
1013{ 976{
1014 LOCK; 977 api_ready (GvSV (coro_current));
1015 coro_enq (SvREFCNT_inc (SvRV (GvSV (coro_current))));
1016 UNLOCK;
1017 978
1018 prepare_schedule (ta); 979 prepare_schedule (ta);
1019} 980}
1020 981
1021static void 982static void
1207 SV *sv = perl_get_sv("Coro::API", 1); 1168 SV *sv = perl_get_sv("Coro::API", 1);
1208 1169
1209 coroapi.schedule = api_schedule; 1170 coroapi.schedule = api_schedule;
1210 coroapi.cede = api_cede; 1171 coroapi.cede = api_cede;
1211 coroapi.ready = api_ready; 1172 coroapi.ready = api_ready;
1173 coroapi.is_ready = api_is_ready;
1212 coroapi.nready = &coro_nready; 1174 coroapi.nready = &coro_nready;
1213 coroapi.current = coro_current; 1175 coroapi.current = coro_current;
1214 1176
1215 GCoroAPI = &coroapi; 1177 GCoroAPI = &coroapi;
1216 sv_setiv (sv, (IV)&coroapi); 1178 sv_setiv (sv, (IV)&coroapi);
1236 1198
1237 coro->prio = newprio; 1199 coro->prio = newprio;
1238 } 1200 }
1239} 1201}
1240 1202
1241void 1203SV *
1242ready (SV *self) 1204ready (SV *self)
1243 PROTOTYPE: $ 1205 PROTOTYPE: $
1244 CODE: 1206 CODE:
1245 api_ready (self); 1207 RETVAL = boolSV (api_ready (self));
1208 OUTPUT:
1209 RETVAL
1210
1211SV *
1212is_ready (SV *self)
1213 PROTOTYPE: $
1214 CODE:
1215 RETVAL = boolSV (api_is_ready (self));
1216 OUTPUT:
1217 RETVAL
1246 1218
1247int 1219int
1248nready (...) 1220nready (...)
1249 PROTOTYPE: 1221 PROTOTYPE:
1250 CODE: 1222 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines