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.61 by root, Tue Aug 10 01:56:30 2004 UTC vs.
Revision 1.69 by root, Fri Dec 16 01:33:20 2005 UTC

1#define PERL_NO_GET_CONTEXT 1#define PERL_NO_GET_CONTEXT
2
3#include "libcoro/coro.c"
2 4
3#include "EXTERN.h" 5#include "EXTERN.h"
4#include "perl.h" 6#include "perl.h"
5#include "XSUB.h" 7#include "XSUB.h"
6 8
7#include "patchlevel.h" 9#include "patchlevel.h"
8 10
9#if PATCHLEVEL < 6 11#if PERL_VERSION < 6
10# ifndef PL_ppaddr 12# ifndef PL_ppaddr
11# define PL_ppaddr ppaddr 13# define PL_ppaddr ppaddr
12# endif 14# endif
13# ifndef call_sv 15# ifndef call_sv
14# define call_sv perl_call_sv 16# define call_sv perl_call_sv
25# ifndef IS_PADCONST 27# ifndef IS_PADCONST
26# define IS_PADCONST(v) 0 28# define IS_PADCONST(v) 0
27# endif 29# endif
28#endif 30#endif
29 31
30#include "libcoro/coro.c"
31
32#include <signal.h> 32#include <signal.h>
33 33
34#ifdef HAVE_MMAP 34#ifdef HAVE_MMAP
35# include <unistd.h> 35# include <unistd.h>
36# include <sys/mman.h> 36# include <sys/mman.h>
57 57
58#include "CoroAPI.h" 58#include "CoroAPI.h"
59 59
60#ifdef USE_ITHREADS 60#ifdef USE_ITHREADS
61static perl_mutex coro_mutex; 61static perl_mutex coro_mutex;
62# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) 62# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0)
63# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) 63# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0)
64#else 64#else
65# define LOCK 0 65# define LOCK (void)0
66# define UNLOCK 0 66# define UNLOCK (void)0
67#endif 67#endif
68 68
69static struct CoroAPI coroapi; 69static struct CoroAPI coroapi;
70static AV *main_mainstack; /* used to differentiate between $main and others */ 70static AV *main_mainstack; /* used to differentiate between $main and others */
71static HV *coro_state_stash; 71static HV *coro_state_stash;
109 AV *mainstack; 109 AV *mainstack;
110 SV **stack_sp; 110 SV **stack_sp;
111 OP *op; 111 OP *op;
112 SV **curpad; 112 SV **curpad;
113 AV *comppad; 113 AV *comppad;
114 CV *compcv;
114 SV **stack_base; 115 SV **stack_base;
115 SV **stack_max; 116 SV **stack_max;
116 SV **tmps_stack; 117 SV **tmps_stack;
117 I32 tmps_floor; 118 I32 tmps_floor;
118 I32 tmps_ix; 119 I32 tmps_ix;
127 I32 savestack_ix; 128 I32 savestack_ix;
128 I32 savestack_max; 129 I32 savestack_max;
129 OP **retstack; 130 OP **retstack;
130 I32 retstack_ix; 131 I32 retstack_ix;
131 I32 retstack_max; 132 I32 retstack_max;
133 PMOP *curpm;
132 COP *curcop; 134 COP *curcop;
133 JMPENV *top_env; 135 JMPENV *top_env;
134 136
135 /* data associated with this coroutine (initial args) */ 137 /* data associated with this coroutine (initial args) */
136 AV *args; 138 AV *args;
327 PL_mainstack = c->mainstack; 329 PL_mainstack = c->mainstack;
328 PL_stack_sp = c->stack_sp; 330 PL_stack_sp = c->stack_sp;
329 PL_op = c->op; 331 PL_op = c->op;
330 PL_curpad = c->curpad; 332 PL_curpad = c->curpad;
331 PL_comppad = c->comppad; 333 PL_comppad = c->comppad;
334 PL_compcv = c->compcv;
332 PL_stack_base = c->stack_base; 335 PL_stack_base = c->stack_base;
333 PL_stack_max = c->stack_max; 336 PL_stack_max = c->stack_max;
334 PL_tmps_stack = c->tmps_stack; 337 PL_tmps_stack = c->tmps_stack;
335 PL_tmps_floor = c->tmps_floor; 338 PL_tmps_floor = c->tmps_floor;
336 PL_tmps_ix = c->tmps_ix; 339 PL_tmps_ix = c->tmps_ix;
345 PL_savestack_ix = c->savestack_ix; 348 PL_savestack_ix = c->savestack_ix;
346 PL_savestack_max = c->savestack_max; 349 PL_savestack_max = c->savestack_max;
347 PL_retstack = c->retstack; 350 PL_retstack = c->retstack;
348 PL_retstack_ix = c->retstack_ix; 351 PL_retstack_ix = c->retstack_ix;
349 PL_retstack_max = c->retstack_max; 352 PL_retstack_max = c->retstack_max;
353 PL_curpm = c->curpm;
350 PL_curcop = c->curcop; 354 PL_curcop = c->curcop;
351 PL_top_env = c->top_env; 355 PL_top_env = c->top_env;
352 356
353 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 357 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
354 if (c->defsv) REPLACE_SV (DEFSV , c->defsv); 358 if (c->defsv) REPLACE_SV (DEFSV , c->defsv);
451 c->mainstack = PL_mainstack; 455 c->mainstack = PL_mainstack;
452 c->stack_sp = PL_stack_sp; 456 c->stack_sp = PL_stack_sp;
453 c->op = PL_op; 457 c->op = PL_op;
454 c->curpad = PL_curpad; 458 c->curpad = PL_curpad;
455 c->comppad = PL_comppad; 459 c->comppad = PL_comppad;
460 c->compcv = PL_compcv;
456 c->stack_base = PL_stack_base; 461 c->stack_base = PL_stack_base;
457 c->stack_max = PL_stack_max; 462 c->stack_max = PL_stack_max;
458 c->tmps_stack = PL_tmps_stack; 463 c->tmps_stack = PL_tmps_stack;
459 c->tmps_floor = PL_tmps_floor; 464 c->tmps_floor = PL_tmps_floor;
460 c->tmps_ix = PL_tmps_ix; 465 c->tmps_ix = PL_tmps_ix;
469 c->savestack_ix = PL_savestack_ix; 474 c->savestack_ix = PL_savestack_ix;
470 c->savestack_max = PL_savestack_max; 475 c->savestack_max = PL_savestack_max;
471 c->retstack = PL_retstack; 476 c->retstack = PL_retstack;
472 c->retstack_ix = PL_retstack_ix; 477 c->retstack_ix = PL_retstack_ix;
473 c->retstack_max = PL_retstack_max; 478 c->retstack_max = PL_retstack_max;
479 c->curpm = PL_curpm;
474 c->curcop = PL_curcop; 480 c->curcop = PL_curcop;
475 c->top_env = PL_top_env; 481 c->top_env = PL_top_env;
476} 482}
477 483
478/* 484/*
583 stack->gencnt = ctx->gencnt = 0; 589 stack->gencnt = ctx->gencnt = 0;
584 590
585 if (alloc) 591 if (alloc)
586 { 592 {
587#if HAVE_MMAP 593#if HAVE_MMAP
588 stack->ssize = 16384 * sizeof (long); /* mmap should do allocate-on-write for us */ 594 stack->ssize = STACKSIZE * sizeof (long); /* mmap should do allocate-on-write for us */
589 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 595 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
590 if (stack->sptr == (void *)-1) 596 if (stack->sptr == (void *)-1)
591#endif 597#endif
592 { 598 {
593 /*FIXME*//*D*//* reasonable stack size! */ 599 /*FIXME*//*D*//* reasonable stack size! */
594 stack->ssize = - (8192 * sizeof (long)); 600 stack->ssize = - (STACKSIZE * sizeof (long));
595 New (0, stack->sptr, 8192, long); 601 New (0, stack->sptr, STACKSIZE, long);
596 } 602 }
597 } 603 }
598 else 604 else
599 stack->sptr = 0; 605 stack->sptr = 0;
600 606
1048 1054
1049void 1055void
1050yield(...) 1056yield(...)
1051 PROTOTYPE: @ 1057 PROTOTYPE: @
1052 CODE: 1058 CODE:
1053 static SV *returnstk; 1059 SV *yieldstack;
1054 SV *sv; 1060 SV *sv;
1055 AV *defav = GvAV (PL_defgv); 1061 AV *defav = GvAV (PL_defgv);
1056 struct coro *prev, *next; 1062 struct coro *prev, *next;
1057 1063
1058 if (!returnstk) 1064 yieldstack = *hv_fetch (
1059 returnstk = SvRV ((SV *)get_sv ("Coro::Cont::return", FALSE)); 1065 (HV *)SvRV (GvSV (coro_current)),
1066 "yieldstack", sizeof ("yieldstack") - 1,
1067 0
1068 );
1060 1069
1061 /* set up @_ -- ugly */ 1070 /* set up @_ -- ugly */
1062 av_clear (defav); 1071 av_clear (defav);
1063 av_fill (defav, items - 1); 1072 av_fill (defav, items - 1);
1064 while (items--) 1073 while (items--)
1065 av_store (defav, items, SvREFCNT_inc (ST(items))); 1074 av_store (defav, items, SvREFCNT_inc (ST(items)));
1066 1075
1067 SvGETMAGIC (returnstk); /* isn't documentation wrong for mg_get? */
1068 sv = av_pop ((AV *)SvRV (returnstk)); 1076 sv = av_pop ((AV *)SvRV (yieldstack));
1069 prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); 1077 prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0)));
1070 next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); 1078 next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0)));
1071 SvREFCNT_dec (sv); 1079 SvREFCNT_dec (sv);
1072 1080
1073 transfer (aTHX_ prev, next, 0); 1081 transfer (aTHX_ prev, next, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines