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.32 by root, Sun Aug 26 17:01:54 2001 UTC vs.
Revision 1.37 by root, Tue Oct 9 00:39:11 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
543 stack->refcnt = 1; 543 stack->refcnt = 1;
544 stack->usecnt = 1; 544 stack->usecnt = 1;
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#if 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);
744 } 744 }
745 } 745 }
746 else 746 else
747 setup_coro (next); 747 setup_coro (next);
748 } 748 }
749 }
750 749
751 /* 750 /*
752 * xnext is now either prev or next, depending on wether 751 * xnext is now either prev or next, depending on wether
753 * 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
754 * variable, that should become thread-specific at one point. 753 * variable, that should become thread-specific at one point.
755 */ 754 */
756 xnext->cursp = stacklevel; 755 xnext->cursp = stacklevel;
756 }
757} 757}
758 758
759static struct coro * 759static struct coro *
760sv_to_coro (SV *arg, const char *funcname, const char *varname) 760sv_to_coro (SV *arg, const char *funcname, const char *varname)
761{ 761{
768 768
769 arg = HeVAL(he); 769 arg = HeVAL(he);
770 } 770 }
771 771
772 /* must also be changed inside Coro::Cont::yield */ 772 /* must also be changed inside Coro::Cont::yield */
773 if (SvROK(arg) && SvOBJECT(SvRV(arg))
773 if (SvROK(arg) && SvSTASH(SvRV(arg)) == coro_state_stash) 774 && SvSTASH(SvRV(arg)) == coro_state_stash)
774 return (struct coro *) SvIV((SV*)SvRV(arg)); 775 return (struct coro *) SvIV((SV*)SvRV(arg));
775 776
776 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);
777 /*NORETURN*/ 778 /*NORETURN*/
778} 779}
1042} 1043}
1043 1044
1044void 1045void
1045ready(self) 1046ready(self)
1046 SV * self 1047 SV * self
1048 PROTOTYPE: $
1047 CODE: 1049 CODE:
1048 api_ready (self); 1050 api_ready (self);
1049 1051
1050int 1052int
1051nready(...) 1053nready(...)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines