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.69 by root, Fri Dec 16 01:33:20 2005 UTC vs.
Revision 1.75 by root, Thu Oct 26 06:50:20 2006 UTC

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>
170 av_store (newpadlist, 1, (SV *) newpad); 171 av_store (newpadlist, 1, (SV *) newpad);
171 172
172 av = newAV (); /* will be @_ */ 173 av = newAV (); /* will be @_ */
173 av_extend (av, 0); 174 av_extend (av, 0);
174 av_store (newpad, 0, (SV *) av); 175 av_store (newpad, 0, (SV *) av);
175 AvFLAGS (av) = AVf_REIFY; 176 AvREIFY_on (av);
176 177
177 for (ix = fpad; ix > 0; ix--) 178 for (ix = fpad; ix > 0; ix--)
178 { 179 {
179 SV *namesv = (ix <= fname) ? pname[ix] : Nullsv; 180 SV *namesv = (ix <= fname) ? pname[ix] : Nullsv;
180 181
345 PL_scopestack_ix = c->scopestack_ix; 346 PL_scopestack_ix = c->scopestack_ix;
346 PL_scopestack_max = c->scopestack_max; 347 PL_scopestack_max = c->scopestack_max;
347 PL_savestack = c->savestack; 348 PL_savestack = c->savestack;
348 PL_savestack_ix = c->savestack_ix; 349 PL_savestack_ix = c->savestack_ix;
349 PL_savestack_max = c->savestack_max; 350 PL_savestack_max = c->savestack_max;
351#if PERL_VERSION < 9
350 PL_retstack = c->retstack; 352 PL_retstack = c->retstack;
351 PL_retstack_ix = c->retstack_ix; 353 PL_retstack_ix = c->retstack_ix;
352 PL_retstack_max = c->retstack_max; 354 PL_retstack_max = c->retstack_max;
355#endif
353 PL_curpm = c->curpm; 356 PL_curpm = c->curpm;
354 PL_curcop = c->curcop; 357 PL_curcop = c->curcop;
355 PL_top_env = c->top_env; 358 PL_top_env = c->top_env;
356 359
357 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 360 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
471 c->scopestack_ix = PL_scopestack_ix; 474 c->scopestack_ix = PL_scopestack_ix;
472 c->scopestack_max = PL_scopestack_max; 475 c->scopestack_max = PL_scopestack_max;
473 c->savestack = PL_savestack; 476 c->savestack = PL_savestack;
474 c->savestack_ix = PL_savestack_ix; 477 c->savestack_ix = PL_savestack_ix;
475 c->savestack_max = PL_savestack_max; 478 c->savestack_max = PL_savestack_max;
479#if PERL_VERSION < 9
476 c->retstack = PL_retstack; 480 c->retstack = PL_retstack;
477 c->retstack_ix = PL_retstack_ix; 481 c->retstack_ix = PL_retstack_ix;
478 c->retstack_max = PL_retstack_max; 482 c->retstack_max = PL_retstack_max;
483#endif
479 c->curpm = PL_curpm; 484 c->curpm = PL_curpm;
480 c->curcop = PL_curcop; 485 c->curcop = PL_curcop;
481 c->top_env = PL_top_env; 486 c->top_env = PL_top_env;
482} 487}
483 488
520 525
521 New(54,PL_savestack,96,ANY); 526 New(54,PL_savestack,96,ANY);
522 PL_savestack_ix = 0; 527 PL_savestack_ix = 0;
523 PL_savestack_max = 96; 528 PL_savestack_max = 96;
524 529
530#if PERL_VERSION < 9
525 New(54,PL_retstack,8,OP*); 531 New(54,PL_retstack,8,OP*);
526 PL_retstack_ix = 0; 532 PL_retstack_ix = 0;
527 PL_retstack_max = 8; 533 PL_retstack_max = 8;
534#endif
528 535
529 UNLOCK; 536 UNLOCK;
530} 537}
531 538
532/* 539/*
572 579
573 Safefree (PL_tmps_stack); 580 Safefree (PL_tmps_stack);
574 Safefree (PL_markstack); 581 Safefree (PL_markstack);
575 Safefree (PL_scopestack); 582 Safefree (PL_scopestack);
576 Safefree (PL_savestack); 583 Safefree (PL_savestack);
584#if PERL_VERSION < 9
577 Safefree (PL_retstack); 585 Safefree (PL_retstack);
586#endif
578} 587}
579 588
580static void 589static void
581allocate_stack (Coro__State ctx, int alloc) 590allocate_stack (Coro__State ctx, int alloc)
582{ 591{
830 if (!SvOBJECT (sv) || SvSTASH (sv) != coro_state_stash) \ 839 if (!SvOBJECT (sv) || SvSTASH (sv) != coro_state_stash) \
831 croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \ 840 croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \
832 \ 841 \
833 } while(0) 842 } while(0)
834 843
835#define SvSTATE(sv) (struct coro *)SvIV (sv) 844#define SvSTATE(sv) INT2PTR (struct coro *, SvIV (sv))
836 845
837static void 846static void
838api_transfer(pTHX_ SV *prev, SV *next, int flags) 847api_transfer(pTHX_ SV *prev, SV *next, int flags)
839{ 848{
840 SV_CORO (prev, "Coro::transfer"); 849 SV_CORO (prev, "Coro::transfer");
858static int coro_nready; 867static int coro_nready;
859 868
860static void 869static void
861coro_enq (pTHX_ SV *sv) 870coro_enq (pTHX_ SV *sv)
862{ 871{
872 SV **xprio;
873 int prio;
874
863 if (SvTYPE (sv) == SVt_PVHV) 875 if (SvTYPE (sv) != SVt_PVHV)
864 {
865 SV **xprio = hv_fetch ((HV *)sv, "prio", 4, 0);
866 int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL;
867
868 prio = prio > PRIO_MAX ? PRIO_MAX
869 : prio < PRIO_MIN ? PRIO_MIN
870 : prio;
871
872 av_push (coro_ready [prio - PRIO_MIN], sv);
873 coro_nready++;
874
875 return;
876 }
877
878 croak ("Coro::ready tried to enqueue something that is not a coroutine"); 876 croak ("Coro::ready tried to enqueue something that is not a coroutine");
877
878 xprio = hv_fetch ((HV *)sv, "prio", 4, 0);
879 prio = xprio ? SvIV (*xprio) : PRIO_NORMAL;
880
881 prio = prio > PRIO_MAX ? PRIO_MAX
882 : prio < PRIO_MIN ? PRIO_MIN
883 : prio;
884
885 av_push (coro_ready [prio - PRIO_MIN], sv);
886 coro_nready++;
879} 887}
880 888
881static SV * 889static SV *
882coro_deq (pTHX_ int min_prio) 890coro_deq (pTHX_ int min_prio)
883{ 891{
1072 av_fill (defav, items - 1); 1080 av_fill (defav, items - 1);
1073 while (items--) 1081 while (items--)
1074 av_store (defav, items, SvREFCNT_inc (ST(items))); 1082 av_store (defav, items, SvREFCNT_inc (ST(items)));
1075 1083
1076 sv = av_pop ((AV *)SvRV (yieldstack)); 1084 sv = av_pop ((AV *)SvRV (yieldstack));
1077 prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); 1085 prev = INT2PTR (struct coro *, SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))));
1078 next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); 1086 next = INT2PTR (struct coro *, SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))));
1079 SvREFCNT_dec (sv); 1087 SvREFCNT_dec (sv);
1080 1088
1081 transfer (aTHX_ prev, next, 0); 1089 transfer (aTHX_ prev, next, 0);
1082 1090
1083MODULE = Coro::State PACKAGE = Coro 1091MODULE = Coro::State PACKAGE = Coro
1146cede(...) 1154cede(...)
1147 PROTOTYPE: 1155 PROTOTYPE:
1148 CODE: 1156 CODE:
1149 api_cede (); 1157 api_cede ();
1150 1158
1159# and these are hacks
1160SV *
1161_aio_get_state ()
1162 CODE:
1163{
1164 struct {
1165 int errorno;
1166 int laststype;
1167 int laststatval;
1168 Stat_t statcache;
1169 } data;
1170
1171 data.errorno = errno;
1172 data.laststype = PL_laststype;
1173 data.laststatval = PL_laststatval;
1174 data.statcache = PL_statcache;
1175
1176 RETVAL = newSVpvn ((char *)&data, sizeof data);
1177}
1178 OUTPUT:
1179 RETVAL
1180
1181void
1182_aio_set_state (char *data_)
1183 PROTOTYPE: $
1184 CODE:
1185{
1186 struct {
1187 int errorno;
1188 int laststype;
1189 int laststatval;
1190 Stat_t statcache;
1191 } *data = (void *)data_;
1192
1193 errno = data->errorno;
1194 PL_laststype = data->laststype;
1195 PL_laststatval = data->laststatval;
1196 PL_statcache = data->statcache;
1197}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines