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.126 by root, Tue Dec 12 04:19:56 2006 UTC vs.
Revision 1.127 by root, Tue Dec 12 13:56:45 2006 UTC

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 8
9#if USE_VALGRIND
10# include <valgrind/valgrind.h>
11#endif
12
13/* the maximum number of idle cctx that will be pooled */
14#define MAX_IDLE_CCTX 8
15
16#define PERL_VERSION_ATLEAST(a,b,c) \
17 (PERL_REVISION > (a) \
18 || (PERL_REVISION == (a) \
19 && (PERL_VERSION > (b) \
20 || (PERL_VERSION == (b) && PERLSUBVERSION >= (c)))))
21
22#if !PERL_VERSION_ATLEAST (5,6,0)
23# ifndef PL_ppaddr
24# define PL_ppaddr ppaddr
25# endif
26# ifndef call_sv
27# define call_sv perl_call_sv
28# endif
29# ifndef get_sv
30# define get_sv perl_get_sv
31# endif
32# ifndef get_cv
33# define get_cv perl_get_cv
34# endif
35# ifndef IS_PADGV
36# define IS_PADGV(v) 0
37# endif
38# ifndef IS_PADCONST
39# define IS_PADCONST(v) 0
40# endif
41#endif
42
43/* 5.8.7 */
44#ifndef SvRV_set
45# define SvRV_set(s,v) SvRV(s) = (v)
46#endif
47
48#include <stdio.h> 9#include <stdio.h>
49#include <errno.h> 10#include <errno.h>
50#include <assert.h> 11#include <assert.h>
51
52#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
53# undef STACKGUARD
54#endif
55
56#ifndef STACKGUARD
57# define STACKGUARD 0
58#endif
59 12
60#ifdef HAVE_MMAP 13#ifdef HAVE_MMAP
61# include <unistd.h> 14# include <unistd.h>
62# include <sys/mman.h> 15# include <sys/mman.h>
63# ifndef MAP_ANONYMOUS 16# ifndef MAP_ANONYMOUS
78#else 31#else
79# define PAGESIZE 0 32# define PAGESIZE 0
80# define BOOT_PAGESIZE (void)0 33# define BOOT_PAGESIZE (void)0
81#endif 34#endif
82 35
36#if USE_VALGRIND
37# include <valgrind/valgrind.h>
38#endif
39
40/* the maximum number of idle cctx that will be pooled */
41#define MAX_IDLE_CCTX 8
42
43#define PERL_VERSION_ATLEAST(a,b,c) \
44 (PERL_REVISION > (a) \
45 || (PERL_REVISION == (a) \
46 && (PERL_VERSION > (b) \
47 || (PERL_VERSION == (b) && PERLSUBVERSION >= (c)))))
48
49#if !PERL_VERSION_ATLEAST (5,6,0)
50# ifndef PL_ppaddr
51# define PL_ppaddr ppaddr
52# endif
53# ifndef call_sv
54# define call_sv perl_call_sv
55# endif
56# ifndef get_sv
57# define get_sv perl_get_sv
58# endif
59# ifndef get_cv
60# define get_cv perl_get_cv
61# endif
62# ifndef IS_PADGV
63# define IS_PADGV(v) 0
64# endif
65# ifndef IS_PADCONST
66# define IS_PADCONST(v) 0
67# endif
68#endif
69
70/* 5.8.7 */
71#ifndef SvRV_set
72# define SvRV_set(s,v) SvRV(s) = (v)
73#endif
74
75#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
76# undef STACKGUARD
77#endif
78
79#ifndef STACKGUARD
80# define STACKGUARD 0
81#endif
82
83/* prefer perl internal functions over our own? */
84#ifndef PREFER_PERL_FUNCTIONS
85# define PREFER_PERL_FUNCTIONS 0
86#endif
87
83/* The next macro should declare a variable stacklevel that contains and approximation 88/* The next macro should declare a variable stacklevel that contains and approximation
84 * to the current C stack pointer. Its property is that it changes with each call 89 * to the current C stack pointer. Its property is that it changes with each call
85 * and should be unique. */ 90 * and should be unique. */
86#define dSTACKLEVEL int stacklevel 91#define dSTACKLEVEL int stacklevel
87#define STACKLEVEL ((void *)&stacklevel) 92#define STACKLEVEL ((void *)&stacklevel)
259 264
260 if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0) 265 if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)
261 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; 266 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--];
262 else 267 else
263 { 268 {
264#if 0 269#if PREFER_PERL_FUNCTIONS
265 /* this is probably cleaner, but also slower? */ 270 /* this is probably cleaner, but also slower? */
266 CV *cp = Perl_cv_clone (cv); 271 CV *cp = Perl_cv_clone (cv);
267 CvPADLIST (cv) = CvPADLIST (cp); 272 CvPADLIST (cv) = CvPADLIST (cp);
268 CvPADLIST (cp) = 0; 273 CvPADLIST (cp) = 0;
269 SvREFCNT_dec (cp); 274 SvREFCNT_dec (cp);
403 * allocate various perl stacks. This is an exact copy 408 * allocate various perl stacks. This is an exact copy
404 * of perl.c:init_stacks, except that it uses less memory 409 * of perl.c:init_stacks, except that it uses less memory
405 * on the (sometimes correct) assumption that coroutines do 410 * on the (sometimes correct) assumption that coroutines do
406 * not usually need a lot of stackspace. 411 * not usually need a lot of stackspace.
407 */ 412 */
408#if USE_PERL_INIT_STACKS 413#if PREFER_PERL_FUNCTIONS
409# define coro_init_stacks init_stacks 414# define coro_init_stacks init_stacks
410#else 415#else
411
412static void 416static void
413coro_init_stacks () 417coro_init_stacks ()
414{ 418{
415 PL_curstackinfo = new_stackinfo(128, 1024/sizeof(PERL_CONTEXT)); 419 PL_curstackinfo = new_stackinfo(128, 1024/sizeof(PERL_CONTEXT));
416 PL_curstackinfo->si_type = PERLSI_MAIN; 420 PL_curstackinfo->si_type = PERLSI_MAIN;
446 New(54,PL_retstack,16,OP*); 450 New(54,PL_retstack,16,OP*);
447 PL_retstack_ix = 0; 451 PL_retstack_ix = 0;
448 PL_retstack_max = 16; 452 PL_retstack_max = 16;
449#endif 453#endif
450} 454}
455#endif
451 456
452/* 457/*
453 * destroy the stacks, the callchain etc... 458 * destroy the stacks, the callchain etc...
454 */ 459 */
455static void 460static void
489 Safefree (PL_savestack); 494 Safefree (PL_savestack);
490#if !PERL_VERSION_ATLEAST (5,9,0) 495#if !PERL_VERSION_ATLEAST (5,9,0)
491 Safefree (PL_retstack); 496 Safefree (PL_retstack);
492#endif 497#endif
493} 498}
494#endif
495 499
496static void 500static void
497setup_coro (struct coro *coro) 501setup_coro (struct coro *coro)
498{ 502{
499 /* 503 /*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines