ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Event/Event.xs
(Generate patch)

Comparing Coro/Event/Event.xs (file contents):
Revision 1.16 by root, Sat Dec 2 18:01:30 2006 UTC vs.
Revision 1.18 by root, Fri Dec 29 11:37:49 2006 UTC

41} 41}
42 42
43static void 43static void
44asynccheck_hook (void *data) 44asynccheck_hook (void *data)
45{ 45{
46 /* ceding from C means allocating a stack, but we assume this is a rare case */ 46 /* this loops as long as we have _other_ coros with the same or higher priority */
47 while (CORO_NREADY && CORO_CEDE)
48 ;
49}
50
51static double
52prepare_hook (void *data)
53{
54 /* this yields once to another coro with any priority */
47 while (CORO_NREADY) 55 if (CORO_NREADY)
48 CORO_CEDE; 56 {
57 CORO_CEDE_NOTSELF;
58 /*
59 * timers might have changed, and Event fails to notice this
60 * so we have to assume the worst. If Event didn't have that bug,
61 * we would only need to do this if CORO_NREADY is != 0 now.
62 */
63 return 0.;
64 }
65 else
66 return 85197.73; /* this is as good as any value, but it factors badly with common values */
49} 67}
50 68
51MODULE = Coro::Event PACKAGE = Coro::Event 69MODULE = Coro::Event PACKAGE = Coro::Event
52 70
53PROTOTYPES: ENABLE 71PROTOTYPES: ENABLE
56{ 74{
57 I_EVENT_API ("Coro::Event"); 75 I_EVENT_API ("Coro::Event");
58 I_CORO_API ("Coro::Event"); 76 I_CORO_API ("Coro::Event");
59 77
60 GEventAPI->add_hook ("asynccheck", (void *)asynccheck_hook, 0); 78 GEventAPI->add_hook ("asynccheck", (void *)asynccheck_hook, 0);
79 GEventAPI->add_hook ("prepare", (void *)prepare_hook, 0);
61} 80}
62 81
63void 82void
64_install_std_cb (SV *self, int type) 83_install_std_cb (SV *self, int type)
65 CODE: 84 CODE:
72 { 91 {
73 AV *priv = newAV (); 92 AV *priv = newAV ();
74 SV *rv = newRV_noinc ((SV *)priv); 93 SV *rv = newRV_noinc ((SV *)priv);
75 94
76 av_fill (priv, CD_MAX); 95 av_fill (priv, CD_MAX);
77 AvARRAY (priv)[CD_WAIT] = newAV (); /* badbad */ 96 AvARRAY (priv)[CD_WAIT] = (SV *)newAV (); /* badbad */
78 AvARRAY (priv)[CD_TYPE] = newSViv (type); 97 AvARRAY (priv)[CD_TYPE] = newSViv (type);
79 AvARRAY (priv)[CD_OK ] = &PL_sv_no; 98 AvARRAY (priv)[CD_OK ] = &PL_sv_no;
80 AvARRAY (priv)[CD_HITS] = newSViv (0); 99 AvARRAY (priv)[CD_HITS] = newSViv (0);
81 AvARRAY (priv)[CD_GOT ] = newSViv (0); 100 AvARRAY (priv)[CD_GOT ] = newSViv (0);
82 SvREADONLY_on (priv); 101 SvREADONLY_on (priv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines