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.63 by root, Mon Mar 21 14:35:22 2005 UTC vs.
Revision 1.70 by root, Mon Dec 26 19:26:52 2005 UTC

6#include "perl.h" 6#include "perl.h"
7#include "XSUB.h" 7#include "XSUB.h"
8 8
9#include "patchlevel.h" 9#include "patchlevel.h"
10 10
11#if PATCHLEVEL < 6 11#if PERL_VERSION < 6
12# ifndef PL_ppaddr 12# ifndef PL_ppaddr
13# define PL_ppaddr ppaddr 13# define PL_ppaddr ppaddr
14# endif 14# endif
15# ifndef call_sv 15# ifndef call_sv
16# define call_sv perl_call_sv 16# define call_sv perl_call_sv
27# ifndef IS_PADCONST 27# ifndef IS_PADCONST
28# define IS_PADCONST(v) 0 28# define IS_PADCONST(v) 0
29# endif 29# endif
30#endif 30#endif
31 31
32#include <errno.h>
32#include <signal.h> 33#include <signal.h>
33 34
34#ifdef HAVE_MMAP 35#ifdef HAVE_MMAP
35# include <unistd.h> 36# include <unistd.h>
36# include <sys/mman.h> 37# include <sys/mman.h>
57 58
58#include "CoroAPI.h" 59#include "CoroAPI.h"
59 60
60#ifdef USE_ITHREADS 61#ifdef USE_ITHREADS
61static perl_mutex coro_mutex; 62static perl_mutex coro_mutex;
62# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) 63# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0)
63# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) 64# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0)
64#else 65#else
65# define LOCK 0 66# define LOCK (void)0
66# define UNLOCK 0 67# define UNLOCK (void)0
67#endif 68#endif
68 69
69static struct CoroAPI coroapi; 70static struct CoroAPI coroapi;
70static AV *main_mainstack; /* used to differentiate between $main and others */ 71static AV *main_mainstack; /* used to differentiate between $main and others */
71static HV *coro_state_stash; 72static HV *coro_state_stash;
128 I32 savestack_ix; 129 I32 savestack_ix;
129 I32 savestack_max; 130 I32 savestack_max;
130 OP **retstack; 131 OP **retstack;
131 I32 retstack_ix; 132 I32 retstack_ix;
132 I32 retstack_max; 133 I32 retstack_max;
134 PMOP *curpm;
133 COP *curcop; 135 COP *curcop;
134 JMPENV *top_env; 136 JMPENV *top_env;
135 137
136 /* data associated with this coroutine (initial args) */ 138 /* data associated with this coroutine (initial args) */
137 AV *args; 139 AV *args;
347 PL_savestack_ix = c->savestack_ix; 349 PL_savestack_ix = c->savestack_ix;
348 PL_savestack_max = c->savestack_max; 350 PL_savestack_max = c->savestack_max;
349 PL_retstack = c->retstack; 351 PL_retstack = c->retstack;
350 PL_retstack_ix = c->retstack_ix; 352 PL_retstack_ix = c->retstack_ix;
351 PL_retstack_max = c->retstack_max; 353 PL_retstack_max = c->retstack_max;
354 PL_curpm = c->curpm;
352 PL_curcop = c->curcop; 355 PL_curcop = c->curcop;
353 PL_top_env = c->top_env; 356 PL_top_env = c->top_env;
354 357
355 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 358 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
356 if (c->defsv) REPLACE_SV (DEFSV , c->defsv); 359 if (c->defsv) REPLACE_SV (DEFSV , c->defsv);
472 c->savestack_ix = PL_savestack_ix; 475 c->savestack_ix = PL_savestack_ix;
473 c->savestack_max = PL_savestack_max; 476 c->savestack_max = PL_savestack_max;
474 c->retstack = PL_retstack; 477 c->retstack = PL_retstack;
475 c->retstack_ix = PL_retstack_ix; 478 c->retstack_ix = PL_retstack_ix;
476 c->retstack_max = PL_retstack_max; 479 c->retstack_max = PL_retstack_max;
480 c->curpm = PL_curpm;
477 c->curcop = PL_curcop; 481 c->curcop = PL_curcop;
478 c->top_env = PL_top_env; 482 c->top_env = PL_top_env;
479} 483}
480 484
481/* 485/*
586 stack->gencnt = ctx->gencnt = 0; 590 stack->gencnt = ctx->gencnt = 0;
587 591
588 if (alloc) 592 if (alloc)
589 { 593 {
590#if HAVE_MMAP 594#if HAVE_MMAP
591 stack->ssize = 16384 * sizeof (long); /* mmap should do allocate-on-write for us */ 595 stack->ssize = STACKSIZE * sizeof (long); /* mmap should do allocate-on-write for us */
592 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 596 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
593 if (stack->sptr == (void *)-1) 597 if (stack->sptr == (void *)-1)
594#endif 598#endif
595 { 599 {
596 /*FIXME*//*D*//* reasonable stack size! */ 600 /*FIXME*//*D*//* reasonable stack size! */
597 stack->ssize = - (8192 * sizeof (long)); 601 stack->ssize = - (STACKSIZE * sizeof (long));
598 New (0, stack->sptr, 8192, long); 602 New (0, stack->sptr, STACKSIZE, long);
599 } 603 }
600 } 604 }
601 else 605 else
602 stack->sptr = 0; 606 stack->sptr = 0;
603 607
1051 1055
1052void 1056void
1053yield(...) 1057yield(...)
1054 PROTOTYPE: @ 1058 PROTOTYPE: @
1055 CODE: 1059 CODE:
1056 static SV *returnstk; 1060 SV *yieldstack;
1057 SV *sv; 1061 SV *sv;
1058 AV *defav = GvAV (PL_defgv); 1062 AV *defav = GvAV (PL_defgv);
1059 struct coro *prev, *next; 1063 struct coro *prev, *next;
1060 1064
1061 if (!returnstk) 1065 yieldstack = *hv_fetch (
1062 returnstk = SvRV ((SV *)get_sv ("Coro::Cont::return", FALSE)); 1066 (HV *)SvRV (GvSV (coro_current)),
1067 "yieldstack", sizeof ("yieldstack") - 1,
1068 0
1069 );
1063 1070
1064 /* set up @_ -- ugly */ 1071 /* set up @_ -- ugly */
1065 av_clear (defav); 1072 av_clear (defav);
1066 av_fill (defav, items - 1); 1073 av_fill (defav, items - 1);
1067 while (items--) 1074 while (items--)
1068 av_store (defav, items, SvREFCNT_inc (ST(items))); 1075 av_store (defav, items, SvREFCNT_inc (ST(items)));
1069 1076
1070 SvGETMAGIC (returnstk); /* isn't documentation wrong for mg_get? */
1071 sv = av_pop ((AV *)SvRV (returnstk)); 1077 sv = av_pop ((AV *)SvRV (yieldstack));
1072 prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); 1078 prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0)));
1073 next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); 1079 next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0)));
1074 SvREFCNT_dec (sv); 1080 SvREFCNT_dec (sv);
1075 1081
1076 transfer (aTHX_ prev, next, 0); 1082 transfer (aTHX_ prev, next, 0);
1141cede(...) 1147cede(...)
1142 PROTOTYPE: 1148 PROTOTYPE:
1143 CODE: 1149 CODE:
1144 api_cede (); 1150 api_cede ();
1145 1151
1152# and these are hacks
1153SV *
1154_aio_get_state ()
1155 CODE:
1156{
1157 struct {
1158 int errorno;
1159 int laststype;
1160 int laststatval;
1161 Stat_t statcache;
1162 } data;
1163
1164 data.errorno = errno;
1165 data.laststype = PL_laststype;
1166 data.laststatval = PL_laststatval;
1167 data.statcache = PL_statcache;
1168
1169 RETVAL = newSVpvn ((char *)&data, sizeof data);
1170}
1171 OUTPUT:
1172 RETVAL
1173
1174void
1175_aio_set_state (char *data_)
1176 PROTOTYPE: $
1177 CODE:
1178{
1179 struct {
1180 int errorno;
1181 int laststype;
1182 int laststatval;
1183 Stat_t statcache;
1184 } *data = (void *)data_;
1185
1186 errno = data->errorno;
1187 PL_laststype = data->laststype;
1188 PL_laststatval = data->laststatval;
1189 PL_statcache = data->statcache;
1190}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines