… | |
… | |
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 | |
|
|
323 | static void |
|
|
324 | coro_u2time (aTHX_ 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 | |
|
|
333 | static double |
|
|
334 | coro_nvtime () |
|
|
335 | { |
|
|
336 | struct timeval tv; |
|
|
337 | gettimeofday (&tv, 0); |
|
|
338 | |
|
|
339 | return tv.tv_sec + tv.tv_usec * 1e-6; |
|
|
340 | } |
|
|
341 | |
|
|
342 | static void |
|
|
343 | time_init (void) |
|
|
344 | { |
|
|
345 | nvtime = coro_nvtime; |
|
|
346 | u2time = coro_u2time; |
|
|
347 | } |
|
|
348 | |
|
|
349 | #else |
|
|
350 | |
|
|
351 | static void |
|
|
352 | time_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 | |
321 | static SV * |
373 | static SV * |
322 | coro_get_sv (pTHX_ const char *name, int create) |
374 | coro_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; |
… | |
… | |
3109 | coroapi.prepare_nop = prepare_nop; |
3161 | coroapi.prepare_nop = prepare_nop; |
3110 | coroapi.prepare_schedule = prepare_schedule; |
3162 | coroapi.prepare_schedule = prepare_schedule; |
3111 | coroapi.prepare_cede = prepare_cede; |
3163 | coroapi.prepare_cede = prepare_cede; |
3112 | coroapi.prepare_cede_notself = prepare_cede_notself; |
3164 | coroapi.prepare_cede_notself = prepare_cede_notself; |
3113 | |
3165 | |
3114 | { |
3166 | time_init (); |
3115 | SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
|
|
3116 | |
|
|
3117 | if (!svp) croak ("Time::HiRes is required"); |
|
|
3118 | if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer"); |
|
|
3119 | |
|
|
3120 | nvtime = INT2PTR (double (*)(), SvIV (*svp)); |
|
|
3121 | |
|
|
3122 | svp = hv_fetch (PL_modglobal, "Time::U2time", 12, 0); |
|
|
3123 | u2time = INT2PTR (void (*)(pTHX_ UV ret[2]), SvIV (*svp)); |
|
|
3124 | } |
|
|
3125 | |
3167 | |
3126 | assert (("PRIO_NORMAL must be 0", !CORO_PRIO_NORMAL)); |
3168 | assert (("PRIO_NORMAL must be 0", !CORO_PRIO_NORMAL)); |
3127 | } |
3169 | } |
3128 | |
3170 | |
3129 | SV * |
3171 | SV * |