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.103 by root, Mon Nov 27 01:33:30 2006 UTC vs.
Revision 1.105 by root, Mon Nov 27 02:01:33 2006 UTC

3#include "EXTERN.h" 3#include "EXTERN.h"
4#include "perl.h" 4#include "perl.h"
5#include "XSUB.h" 5#include "XSUB.h"
6 6
7#include "patchlevel.h" 7#include "patchlevel.h"
8
9#if USE_VALGRIND
10# include <valgrind/valgrind.h>
11#endif
8 12
9#define PERL_VERSION_ATLEAST(a,b,c) \ 13#define PERL_VERSION_ATLEAST(a,b,c) \
10 (PERL_REVISION > (a) \ 14 (PERL_REVISION > (a) \
11 || (PERL_REVISION == (a) \ 15 || (PERL_REVISION == (a) \
12 && (PERL_VERSION > (b) \ 16 && (PERL_VERSION > (b) \
108 112
109 /* cpu state */ 113 /* cpu state */
110 void *idle_sp; /* sp of top-level transfer/schedule/cede call */ 114 void *idle_sp; /* sp of top-level transfer/schedule/cede call */
111 JMPENV *top_env; 115 JMPENV *top_env;
112 coro_context cctx; 116 coro_context cctx;
117
118#if USE_VALGRIND
119 int valgrind_id;
120#endif
113} coro_stack; 121} coro_stack;
114 122
115/* this is a structure representing a perl-level coroutine */ 123/* this is a structure representing a perl-level coroutine */
116struct coro { 124struct coro {
117 /* the c coroutine allocated to this perl coroutine, if any */ 125 /* the c coroutine allocated to this perl coroutine, if any */
621 prepare_cctx ((coro_stack *)arg); 629 prepare_cctx ((coro_stack *)arg);
622 630
623 /* somebody will hit me for both perl_run and PL_restartop */ 631 /* somebody will hit me for both perl_run and PL_restartop */
624 perl_run (PL_curinterp); 632 perl_run (PL_curinterp);
625 633
626 fputs ("FATAL: C coroutine fell over the edge of the world, aborting.\n", stderr); 634 fputs ("FATAL: C coroutine fell over the edge of the world, aborting. Did you call exit in a coroutine?\n", stderr);
627 abort (); 635 abort ();
628} 636}
629 637
630static coro_stack * 638static coro_stack *
631stack_new () 639stack_new ()
661 _exit (EXIT_FAILURE); 669 _exit (EXIT_FAILURE);
662 } 670 }
663 671
664#endif 672#endif
665 673
674#if USE_VALGRIND
675 stack->valgrind_id = VALGRIND_STACK_REGISTER (
676 STACKGUARD * PAGESIZE + (char *)stack->sptr,
677 stack->ssize + (char *)stack->sptr
678 );
679#endif
680
666 coro_create (&stack->cctx, coro_run, (void *)stack, stack->sptr, stack->ssize); 681 coro_create (&stack->cctx, coro_run, (void *)stack, stack->sptr, stack->ssize);
667 682
668 return stack; 683 return stack;
669} 684}
670 685
671static void 686static void
672stack_free (coro_stack *stack) 687stack_free (coro_stack *stack)
673{ 688{
674 if (!stack) 689 if (!stack)
675 return; 690 return;
691
692#if USE_VALGRIND
693 VALGRIND_STACK_DEREGISTER (stack->valgrind_id);
694#endif
676 695
677#if HAVE_MMAP 696#if HAVE_MMAP
678 munmap (stack->sptr, stack->ssize); 697 munmap (stack->sptr, stack->ssize);
679#else 698#else
680 Safefree (stack->sptr); 699 Safefree (stack->sptr);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines