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.382 by root, Thu Feb 10 08:06:27 2011 UTC vs.
Revision 1.389 by root, Fri Mar 4 16:41:21 2011 UTC

21 21
22#ifndef SVs_PADSTALE 22#ifndef SVs_PADSTALE
23# define SVs_PADSTALE 0 23# define SVs_PADSTALE 0
24#endif 24#endif
25 25
26#ifdef WIN32 26#if defined(_WIN32)
27# undef HAS_GETTIMEOFDAY
27# undef setjmp 28# undef setjmp
28# undef longjmp 29# undef longjmp
29# undef _exit 30# undef _exit
30# define setjmp _setjmp /* deep magic */ 31# define setjmp _setjmp /* deep magic */
31#else 32#else
240 CV *startcv; /* the CV to execute */ 241 CV *startcv; /* the CV to execute */
241 AV *args; /* data associated with this coroutine (initial args) */ 242 AV *args; /* data associated with this coroutine (initial args) */
242 int refcnt; /* coroutines are refcounted, yes */ 243 int refcnt; /* coroutines are refcounted, yes */
243 int flags; /* CF_ flags */ 244 int flags; /* CF_ flags */
244 HV *hv; /* the perl hash associated with this coro, if any */ 245 HV *hv; /* the perl hash associated with this coro, if any */
245 void (*on_destroy)(pTHX_ struct coro *coro); 246 void (*on_destroy)(pTHX_ struct coro *coro); /* for temporary use by xs in critical sections */
246 247
247 /* statistics */ 248 /* statistics */
248 int usecount; /* number of transfers to this coro */ 249 int usecount; /* number of transfers to this coro */
249 250
250 /* coro process data */ 251 /* coro process data */
313 /* entersub is an UNOP, select a LISTOP... keep your fingers crossed */ 314 /* entersub is an UNOP, select a LISTOP... keep your fingers crossed */
314 PL_op->op_flags |= OPf_STACKED; 315 PL_op->op_flags |= OPf_STACKED;
315 PL_op->op_private = 0; 316 PL_op->op_private = 0;
316 return PL_ppaddr [OP_ENTERSUB](aTHX); 317 return PL_ppaddr [OP_ENTERSUB](aTHX);
317} 318}
319
320/** time stuff **************************************************************/
321
322#ifdef HAS_GETTIMEOFDAY
323
324static void
325coro_u2time (pTHX_ UV ret[2])
326{
327 struct timeval tv;
328 gettimeofday (&tv, 0);
329
330 ret [0] = tv.tv_sec;
331 ret [1] = tv.tv_usec;
332}
333
334static double
335coro_nvtime ()
336{
337 struct timeval tv;
338 gettimeofday (&tv, 0);
339
340 return tv.tv_sec + tv.tv_usec * 1e-6;
341}
342
343static void
344time_init (pTHX)
345{
346 nvtime = coro_nvtime;
347 u2time = coro_u2time;
348}
349
350#else
351
352static void
353time_init (pTHX)
354{
355 SV **svp;
356
357 require_pv ("Time/HiRes.pm");
358
359 svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
360
361 if (!svp) croak ("Time::HiRes is required, but missing.");
362 if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer");
363
364 nvtime = INT2PTR (double (*)(), SvIV (*svp));
365
366 svp = hv_fetch (PL_modglobal, "Time::U2time", 12, 0);
367 u2time = INT2PTR (void (*)(pTHX_ UV ret[2]), SvIV (*svp));
368}
369
370#endif
318 371
319/** lowlevel stuff **********************************************************/ 372/** lowlevel stuff **********************************************************/
320 373
321static SV * 374static SV *
322coro_get_sv (pTHX_ const char *name, int create) 375coro_get_sv (pTHX_ const char *name, int create)
586 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep); 639 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep);
587 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep); 640 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep);
588 641
589#if PERL_VERSION_ATLEAST (5,10,0) 642#if PERL_VERSION_ATLEAST (5,10,0)
590 /* perl 5.10 complicates this _quite_ a bit, but it also is 643 /* perl 5.10 complicates this _quite_ a bit, but it also is
591 * is much faster, so no quarrels here. alternatively, we could 644 * much faster, so no quarrels here. alternatively, we could
592 * sv_upgrade to avoid this. 645 * sv_upgrade to avoid this.
593 */ 646 */
594 { 647 {
595 /* swap sv_u */ 648 /* swap sv_u */
596 tmp.sv_u = a->sv_u; a->sv_u = b->sv_u; b->sv_u = tmp.sv_u; 649 tmp.sv_u = a->sv_u; a->sv_u = b->sv_u; b->sv_u = tmp.sv_u;
1013 PL_comppad_name_fill = 0; 1066 PL_comppad_name_fill = 0;
1014 PL_comppad_name_floor = 0; 1067 PL_comppad_name_floor = 0;
1015 PL_curpm = 0; 1068 PL_curpm = 0;
1016 PL_curpad = 0; 1069 PL_curpad = 0;
1017 PL_localizing = 0; 1070 PL_localizing = 0;
1018 PL_dirty = 0;
1019 PL_restartop = 0; 1071 PL_restartop = 0;
1020#if PERL_VERSION_ATLEAST (5,10,0) 1072#if PERL_VERSION_ATLEAST (5,10,0)
1021 PL_parser = 0; 1073 PL_parser = 0;
1022#endif 1074#endif
1023 PL_hints = 0; 1075 PL_hints = 0;
3110 coroapi.prepare_nop = prepare_nop; 3162 coroapi.prepare_nop = prepare_nop;
3111 coroapi.prepare_schedule = prepare_schedule; 3163 coroapi.prepare_schedule = prepare_schedule;
3112 coroapi.prepare_cede = prepare_cede; 3164 coroapi.prepare_cede = prepare_cede;
3113 coroapi.prepare_cede_notself = prepare_cede_notself; 3165 coroapi.prepare_cede_notself = prepare_cede_notself;
3114 3166
3115 { 3167 time_init (aTHX);
3116 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
3117
3118 if (!svp) croak ("Time::HiRes is required");
3119 if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer");
3120
3121 nvtime = INT2PTR (double (*)(), SvIV (*svp));
3122
3123 svp = hv_fetch (PL_modglobal, "Time::U2time", 12, 0);
3124 u2time = INT2PTR (void (*)(pTHX_ UV ret[2]), SvIV (*svp));
3125 }
3126 3168
3127 assert (("PRIO_NORMAL must be 0", !CORO_PRIO_NORMAL)); 3169 assert (("PRIO_NORMAL must be 0", !CORO_PRIO_NORMAL));
3128} 3170}
3129 3171
3130SV * 3172SV *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines