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.31 by root, Sun Aug 26 16:36:08 2001 UTC vs.
Revision 1.36 by root, Fri Oct 5 14:20:10 2001 UTC

7#include <signal.h> 7#include <signal.h>
8 8
9#ifdef HAVE_MMAP 9#ifdef HAVE_MMAP
10# include <unistd.h> 10# include <unistd.h>
11# include <sys/mman.h> 11# include <sys/mman.h>
12# ifndef MAP_ANON
13# ifdef MAP_ANONYMOUS 12# ifndef MAP_ANONYMOUS
14# define MAP_ANON MAP_ANONYMOUS 13# ifdef MAP_ANON
14# define MAP_ANONYMOUS MAP_ANON
15# else 15# else
16# undef HAVE_MMAP 16# undef HAVE_MMAP
17# endif 17# endif
18# endif 18# endif
19#endif 19#endif
25 25
26/* The next macro should declare a variable stacklevel that contains and approximation 26/* The next macro should declare a variable stacklevel that contains and approximation
27 * to the current C stack pointer. Its property is that it changes with each call 27 * to the current C stack pointer. Its property is that it changes with each call
28 * and should be unique. */ 28 * and should be unique. */
29#define dSTACKLEVEL void *stacklevel = &stacklevel 29#define dSTACKLEVEL void *stacklevel = &stacklevel
30
31#define IN_DESTRUCT (PL_main_cv == Nullcv)
30 32
31#define labs(l) ((l) >= 0 ? (l) : -(l)) 33#define labs(l) ((l) >= 0 ? (l) : -(l))
32 34
33#include "CoroAPI.h" 35#include "CoroAPI.h"
34 36
487 * still there is a memleak of 128 bytes... 489 * still there is a memleak of 128 bytes...
488 */ 490 */
489STATIC void 491STATIC void
490destroy_stacks(pTHX) 492destroy_stacks(pTHX)
491{ 493{
492 int destruct = PL_main_cv != Nullcv; 494 if (!IN_DESTRUCT)
493
494 if (destruct)
495 { 495 {
496 /* is this ugly, I ask? */ 496 /* is this ugly, I ask? */
497 while (PL_scopestack_ix) 497 while (PL_scopestack_ix)
498 LEAVE; 498 LEAVE;
499 499
513 dSP; 513 dSP;
514 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); 514 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack);
515 PUTBACK; /* possibly superfluous */ 515 PUTBACK; /* possibly superfluous */
516 } 516 }
517 517
518 if (destruct) 518 if (!IN_DESTRUCT)
519 { 519 {
520 dounwind(-1); 520 dounwind(-1);
521 SvREFCNT_dec(PL_curstackinfo->si_stack); 521 SvREFCNT_dec(PL_curstackinfo->si_stack);
522 } 522 }
523 523
545 stack->gencnt = ctx->gencnt = 0; 545 stack->gencnt = ctx->gencnt = 0;
546 if (alloc) 546 if (alloc)
547 { 547 {
548#ifdef HAVE_MMAP 548#ifdef HAVE_MMAP
549 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */ 549 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */
550 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); 550 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
551 if (stack->sptr == (void *)-1) 551 if (stack->sptr == (void *)-1)
552#endif 552#endif
553 { 553 {
554 /*FIXME*//*D*//* reasonable stack size! */ 554 /*FIXME*//*D*//* reasonable stack size! */
555 stack->ssize = -4096 * sizeof (long); 555 stack->ssize = -4096 * sizeof (long);
650{ 650{
651 /* 651 /*
652 * this is a _very_ stripped down perl interpreter ;) 652 * this is a _very_ stripped down perl interpreter ;)
653 */ 653 */
654 Coro__State ctx = (Coro__State)arg; 654 Coro__State ctx = (Coro__State)arg;
655 JMPENV coro_start_env;
655 656
656 /*FIXME*//* must set up top_env here */ 657 /* same as JMPENV_BOOTSTRAP */
658 Zero(&coro_start_env, 1, JMPENV);
659 coro_start_env.je_ret = -1;
660 coro_start_env.je_mustcatch = TRUE;
661 PL_top_env = &coro_start_env;
662
657 ctx->cursp = 0; 663 ctx->cursp = 0;
658 PL_op = PL_op->op_next; 664 PL_op = PL_op->op_next;
659 CALLRUNOPS(aTHX); 665 CALLRUNOPS(aTHX);
660 666
661 abort (); 667 abort ();
738 } 744 }
739 } 745 }
740 else 746 else
741 setup_coro (next); 747 setup_coro (next);
742 } 748 }
743 }
744 749
745 /* 750 /*
746 * xnext is now either prev or next, depending on wether 751 * xnext is now either prev or next, depending on wether
747 * we switched the c stack or not. that's why i use a global 752 * we switched the c stack or not. that's why i use a global
748 * variable, that should become thread-specific at one point. 753 * variable, that should become thread-specific at one point.
749 */ 754 */
750 xnext->cursp = stacklevel; 755 xnext->cursp = stacklevel;
756 }
751} 757}
752 758
753static struct coro * 759static struct coro *
754sv_to_coro (SV *arg, const char *funcname, const char *varname) 760sv_to_coro (SV *arg, const char *funcname, const char *varname)
755{ 761{
762 768
763 arg = HeVAL(he); 769 arg = HeVAL(he);
764 } 770 }
765 771
766 /* must also be changed inside Coro::Cont::yield */ 772 /* must also be changed inside Coro::Cont::yield */
773 if (SvROK(arg) && SvOBJECT(SvRV(arg))
767 if (SvROK(arg) && SvSTASH(SvRV(arg)) == coro_state_stash) 774 && SvSTASH(SvRV(arg)) == coro_state_stash)
768 return (struct coro *) SvIV((SV*)SvRV(arg)); 775 return (struct coro *) SvIV((SV*)SvRV(arg));
769 776
770 croak ("%s() -- %s is not (and contains not) a Coro::State object", funcname, varname); 777 croak ("%s() -- %s is not (and contains not) a Coro::State object", funcname, varname);
771 /*NORETURN*/ 778 /*NORETURN*/
772} 779}
1036} 1043}
1037 1044
1038void 1045void
1039ready(self) 1046ready(self)
1040 SV * self 1047 SV * self
1048 PROTOTYPE: $
1041 CODE: 1049 CODE:
1042 api_ready (self); 1050 api_ready (self);
1043 1051
1044int 1052int
1045nready(...) 1053nready(...)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines