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.380 by root, Sun Sep 12 03:06:38 2010 UTC vs.
Revision 1.387 by root, Mon Feb 21 13:38:04 2011 UTC

1/* this works around a bug in mingw32 providing a non-working setjmp */
2#define USE_NO_MINGW_SETJMP_TWO_ARGS
3
1#define NDEBUG 1 4#define NDEBUG 1
2 5
3#include "libcoro/coro.c" 6#include "libcoro/coro.c"
4 7
5#define PERL_NO_GET_CONTEXT 8#define PERL_NO_GET_CONTEXT
237 CV *startcv; /* the CV to execute */ 240 CV *startcv; /* the CV to execute */
238 AV *args; /* data associated with this coroutine (initial args) */ 241 AV *args; /* data associated with this coroutine (initial args) */
239 int refcnt; /* coroutines are refcounted, yes */ 242 int refcnt; /* coroutines are refcounted, yes */
240 int flags; /* CF_ flags */ 243 int flags; /* CF_ flags */
241 HV *hv; /* the perl hash associated with this coro, if any */ 244 HV *hv; /* the perl hash associated with this coro, if any */
242 void (*on_destroy)(pTHX_ struct coro *coro); 245 void (*on_destroy)(pTHX_ struct coro *coro); /* for temporary use by xs in critical sections */
243 246
244 /* statistics */ 247 /* statistics */
245 int usecount; /* number of transfers to this coro */ 248 int usecount; /* number of transfers to this coro */
246 249
247 /* coro process data */ 250 /* coro process data */
310 /* entersub is an UNOP, select a LISTOP... keep your fingers crossed */ 313 /* entersub is an UNOP, select a LISTOP... keep your fingers crossed */
311 PL_op->op_flags |= OPf_STACKED; 314 PL_op->op_flags |= OPf_STACKED;
312 PL_op->op_private = 0; 315 PL_op->op_private = 0;
313 return PL_ppaddr [OP_ENTERSUB](aTHX); 316 return PL_ppaddr [OP_ENTERSUB](aTHX);
314} 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
315 370
316/** lowlevel stuff **********************************************************/ 371/** lowlevel stuff **********************************************************/
317 372
318static SV * 373static SV *
319coro_get_sv (pTHX_ const char *name, int create) 374coro_get_sv (pTHX_ const char *name, int create)
583 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep); 638 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep);
584 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep); 639 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep);
585 640
586#if PERL_VERSION_ATLEAST (5,10,0) 641#if PERL_VERSION_ATLEAST (5,10,0)
587 /* 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
588 * is much faster, so no quarrels here. alternatively, we could 643 * much faster, so no quarrels here. alternatively, we could
589 * sv_upgrade to avoid this. 644 * sv_upgrade to avoid this.
590 */ 645 */
591 { 646 {
592 /* swap sv_u */ 647 /* swap sv_u */
593 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;
1010 PL_comppad_name_fill = 0; 1065 PL_comppad_name_fill = 0;
1011 PL_comppad_name_floor = 0; 1066 PL_comppad_name_floor = 0;
1012 PL_curpm = 0; 1067 PL_curpm = 0;
1013 PL_curpad = 0; 1068 PL_curpad = 0;
1014 PL_localizing = 0; 1069 PL_localizing = 0;
1015 PL_dirty = 0;
1016 PL_restartop = 0; 1070 PL_restartop = 0;
1017#if PERL_VERSION_ATLEAST (5,10,0) 1071#if PERL_VERSION_ATLEAST (5,10,0)
1018 PL_parser = 0; 1072 PL_parser = 0;
1019#endif 1073#endif
1020 PL_hints = 0; 1074 PL_hints = 0;
2794 { 2848 {
2795 SV *cb_cv = s_get_cv_croak (arg [1]); 2849 SV *cb_cv = s_get_cv_croak (arg [1]);
2796 av_push (av, SvREFCNT_inc_NN (cb_cv)); 2850 av_push (av, SvREFCNT_inc_NN (cb_cv));
2797 2851
2798 if (SvIVX (AvARRAY (av)[0])) 2852 if (SvIVX (AvARRAY (av)[0]))
2799 coro_signal_wake (aTHX_ av, 1); /* ust be the only waiter */ 2853 coro_signal_wake (aTHX_ av, 1); /* must be the only waiter */
2800 2854
2801 frame->prepare = prepare_nop; 2855 frame->prepare = prepare_nop;
2802 frame->check = slf_check_nop; 2856 frame->check = slf_check_nop;
2803 } 2857 }
2804 else if (SvIVX (AvARRAY (av)[0])) 2858 else if (SvIVX (AvARRAY (av)[0]))
3107 coroapi.prepare_nop = prepare_nop; 3161 coroapi.prepare_nop = prepare_nop;
3108 coroapi.prepare_schedule = prepare_schedule; 3162 coroapi.prepare_schedule = prepare_schedule;
3109 coroapi.prepare_cede = prepare_cede; 3163 coroapi.prepare_cede = prepare_cede;
3110 coroapi.prepare_cede_notself = prepare_cede_notself; 3164 coroapi.prepare_cede_notself = prepare_cede_notself;
3111 3165
3112 { 3166 time_init ();
3113 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
3114
3115 if (!svp) croak ("Time::HiRes is required");
3116 if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer");
3117
3118 nvtime = INT2PTR (double (*)(), SvIV (*svp));
3119
3120 svp = hv_fetch (PL_modglobal, "Time::U2time", 12, 0);
3121 u2time = INT2PTR (void (*)(pTHX_ UV ret[2]), SvIV (*svp));
3122 }
3123 3167
3124 assert (("PRIO_NORMAL must be 0", !CORO_PRIO_NORMAL)); 3168 assert (("PRIO_NORMAL must be 0", !CORO_PRIO_NORMAL));
3125} 3169}
3126 3170
3127SV * 3171SV *
3873 { 3917 {
3874 PL_ppaddr [OP_SSELECT] = coro_old_pp_sselect; 3918 PL_ppaddr [OP_SSELECT] = coro_old_pp_sselect;
3875 coro_old_pp_sselect = 0; 3919 coro_old_pp_sselect = 0;
3876 } 3920 }
3877 3921
3878

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines