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.381 by root, Sat Oct 23 09:28:50 2010 UTC vs.
Revision 1.387 by root, Mon Feb 21 13:38:04 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines