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.141 by root, Mon Jan 22 18:45:17 2007 UTC vs.
Revision 1.143 by root, Wed Feb 28 11:43:03 2007 UTC

31#else 31#else
32# define PAGESIZE 0 32# define PAGESIZE 0
33# define BOOT_PAGESIZE (void)0 33# define BOOT_PAGESIZE (void)0
34#endif 34#endif
35 35
36#if USE_VALGRIND 36#if CORO_USE_VALGRIND
37# include <valgrind/valgrind.h> 37# include <valgrind/valgrind.h>
38# define REGISTER_STACK(cctx,start,end) (cctx)->valgrind_id = VALGRIND_STACK_REGISTER ((start), (end)) 38# define REGISTER_STACK(cctx,start,end) (cctx)->valgrind_id = VALGRIND_STACK_REGISTER ((start), (end))
39#else 39#else
40# define REGISTER_STACK(cctx,start,end) 40# define REGISTER_STACK(cctx,start,end)
41#endif 41#endif
74#ifndef SvRV_set 74#ifndef SvRV_set
75# define SvRV_set(s,v) SvRV(s) = (v) 75# define SvRV_set(s,v) SvRV(s) = (v)
76#endif 76#endif
77 77
78#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 78#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
79# undef STACKGUARD 79# undef CORO_STACKGUARD
80#endif 80#endif
81 81
82#ifndef STACKGUARD 82#ifndef CORO_STACKGUARD
83# define STACKGUARD 0 83# define CORO_STACKGUARD 0
84#endif 84#endif
85 85
86/* prefer perl internal functions over our own? */ 86/* prefer perl internal functions over our own? */
87#ifndef PREFER_PERL_FUNCTIONS 87#ifndef CORO_PREFER_PERL_FUNCTIONS
88# define PREFER_PERL_FUNCTIONS 0 88# define CORO_PREFER_PERL_FUNCTIONS 0
89#endif 89#endif
90 90
91/* The next macro should declare a variable stacklevel that contains and approximation 91/* The next macro should declare a variable stacklevel that contains and approximation
92 * to the current C stack pointer. Its property is that it changes with each call 92 * to the current C stack pointer. Its property is that it changes with each call
93 * and should be unique. */ 93 * and should be unique. */
148 JMPENV *top_env; 148 JMPENV *top_env;
149 coro_context cctx; 149 coro_context cctx;
150 150
151 int inuse; 151 int inuse;
152 152
153#if USE_VALGRIND 153#if CORO_USE_VALGRIND
154 int valgrind_id; 154 int valgrind_id;
155#endif 155#endif
156} coro_cctx; 156} coro_cctx;
157 157
158enum { 158enum {
288 288
289 if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0) 289 if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)
290 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; 290 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--];
291 else 291 else
292 { 292 {
293#if PREFER_PERL_FUNCTIONS 293#if CORO_PREFER_PERL_FUNCTIONS
294 /* this is probably cleaner, but also slower? */ 294 /* this is probably cleaner, but also slower? */
295 CV *cp = Perl_cv_clone (cv); 295 CV *cp = Perl_cv_clone (cv);
296 CvPADLIST (cv) = CvPADLIST (cp); 296 CvPADLIST (cv) = CvPADLIST (cp);
297 CvPADLIST (cp) = 0; 297 CvPADLIST (cp) = 0;
298 SvREFCNT_dec (cp); 298 SvREFCNT_dec (cp);
365 CvPADLIST (cv) = (AV *)POPs; 365 CvPADLIST (cv) = (AV *)POPs;
366 } 366 }
367 367
368 PUTBACK; 368 PUTBACK;
369 } 369 }
370 assert (!PL_comppad || AvARRAY (PL_comppad));//D
370} 371}
371 372
372static void 373static void
373save_perl (Coro__State c) 374save_perl (Coro__State c)
374{ 375{
376 assert (!PL_comppad || AvARRAY (PL_comppad));//D
375 { 377 {
376 dSP; 378 dSP;
377 I32 cxix = cxstack_ix; 379 I32 cxix = cxstack_ix;
378 PERL_CONTEXT *ccstk = cxstack; 380 PERL_CONTEXT *ccstk = cxstack;
379 PERL_SI *top_si = PL_curstackinfo; 381 PERL_SI *top_si = PL_curstackinfo;
434 * allocate various perl stacks. This is an exact copy 436 * allocate various perl stacks. This is an exact copy
435 * of perl.c:init_stacks, except that it uses less memory 437 * of perl.c:init_stacks, except that it uses less memory
436 * on the (sometimes correct) assumption that coroutines do 438 * on the (sometimes correct) assumption that coroutines do
437 * not usually need a lot of stackspace. 439 * not usually need a lot of stackspace.
438 */ 440 */
439#if PREFER_PERL_FUNCTIONS 441#if CORO_PREFER_PERL_FUNCTIONS
440# define coro_init_stacks init_stacks 442# define coro_init_stacks init_stacks
441#else 443#else
442static void 444static void
443coro_init_stacks () 445coro_init_stacks ()
444{ 446{
538 540
539 coro_init_stacks (); 541 coro_init_stacks ();
540 542
541 PL_curcop = &PL_compiling; 543 PL_curcop = &PL_compiling;
542 PL_in_eval = EVAL_NULL; 544 PL_in_eval = EVAL_NULL;
545 PL_comppad = 0;
543 PL_curpm = 0; 546 PL_curpm = 0;
544 PL_localizing = 0; 547 PL_localizing = 0;
545 PL_dirty = 0; 548 PL_dirty = 0;
546 PL_restartop = 0; 549 PL_restartop = 0;
547 550
629 632
630 Newz (0, cctx, 1, coro_cctx); 633 Newz (0, cctx, 1, coro_cctx);
631 634
632#if HAVE_MMAP 635#if HAVE_MMAP
633 636
634 cctx->ssize = ((STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + STACKGUARD) * PAGESIZE; 637 cctx->ssize = ((CORO_STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE;
635 /* mmap supposedly does allocate-on-write for us */ 638 /* mmap supposedly does allocate-on-write for us */
636 cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 639 cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
637 640
638 if (cctx->sptr != (void *)-1) 641 if (cctx->sptr != (void *)-1)
639 { 642 {
640# if STACKGUARD 643# if CORO_STACKGUARD
641 mprotect (cctx->sptr, STACKGUARD * PAGESIZE, PROT_NONE); 644 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE);
642# endif 645# endif
643 REGISTER_STACK ( 646 REGISTER_STACK (
644 cctx, 647 cctx,
645 STACKGUARD * PAGESIZE + (char *)cctx->sptr, 648 CORO_STACKGUARD * PAGESIZE + (char *)cctx->sptr,
646 cctx->ssize + (char *)cctx->sptr 649 cctx->ssize + (char *)cctx->sptr
647 ); 650 );
648 651
649 coro_create (&cctx->cctx, coro_run, (void *)cctx, cctx->sptr, cctx->ssize); 652 coro_create (&cctx->cctx, coro_run, (void *)cctx, cctx->sptr, cctx->ssize);
650 } 653 }
651 else 654 else
652#endif 655#endif
653 { 656 {
654 cctx->ssize = -STACKSIZE * (long)sizeof (long); 657 cctx->ssize = -CORO_STACKSIZE * (long)sizeof (long);
655 New (0, cctx->sptr, STACKSIZE, long); 658 New (0, cctx->sptr, CORO_STACKSIZE, long);
656 659
657 if (!cctx->sptr) 660 if (!cctx->sptr)
658 { 661 {
659 perror ("FATAL: unable to allocate stack for coroutine"); 662 perror ("FATAL: unable to allocate stack for coroutine");
660 _exit (EXIT_FAILURE); 663 _exit (EXIT_FAILURE);
678 if (!cctx) 681 if (!cctx)
679 return; 682 return;
680 683
681 --cctx_count; 684 --cctx_count;
682 685
683#if USE_VALGRIND 686#if CORO_USE_VALGRIND
684 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); 687 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id);
685#endif 688#endif
686 689
687#if HAVE_MMAP 690#if HAVE_MMAP
688 if (cctx->ssize > 0) 691 if (cctx->ssize > 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines