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.22 by root, Sun Sep 23 21:52:04 2007 UTC vs.
Revision 1.23 by root, Tue Oct 9 22:29:27 2007 UTC

69 } 69 }
70 else 70 else
71 return 85197.73; /* this is as good as any value, but it factors badly with common values */ 71 return 85197.73; /* this is as good as any value, but it factors badly with common values */
72} 72}
73 73
74static SV *
75event_next (SV *watcher, int cancel, int wantev)
76{
77 pe_watcher *w = GEventAPI->sv_2watcher (watcher);
78 AV *priv = (AV *)w->ext_data;
79
80 if (AvARRAY (priv)[CD_OK] == &PL_sv_yes)
81 {
82 AvARRAY (priv)[CD_OK] = &PL_sv_no;
83
84 if (cancel)
85 GEventAPI->cancel (w);
86
87 if (wantev)
88 {
89 SV *ev = newRV_inc ((SV *)priv);
90
91 /* may need to bless it now */
92 if (!SvOBJECT (priv))
93 {
94 SvREADONLY_off ((SV *)priv);
95 sv_bless (ev, coro_event_event_stash);
96 SvREADONLY_on ((SV *)priv);
97 }
98
99 return sv_2mortal (ev);
100 }
101 else
102 return &PL_sv_undef;
103 }
104
105 av_push ((AV *)AvARRAY (priv)[CD_WAIT], SvREFCNT_inc (CORO_CURRENT));
106
107 if (!w->running)
108 GEventAPI->start (w, 1);
109
110 return 0; /* schedule */
111}
112
74MODULE = Coro::Event PACKAGE = Coro::Event 113MODULE = Coro::Event PACKAGE = Coro::Event
75 114
76PROTOTYPES: ENABLE 115PROTOTYPES: ENABLE
77 116
78BOOT: 117BOOT:
82 I_EVENT_API ("Coro::Event"); 121 I_EVENT_API ("Coro::Event");
83 I_CORO_API ("Coro::Event"); 122 I_CORO_API ("Coro::Event");
84 123
85 GEventAPI->add_hook ("asynccheck", (void *)asynccheck_hook, 0); 124 GEventAPI->add_hook ("asynccheck", (void *)asynccheck_hook, 0);
86 GEventAPI->add_hook ("prepare", (void *)prepare_hook, 0); 125 GEventAPI->add_hook ("prepare", (void *)prepare_hook, 0);
126
127 GCoroAPI->coro_event_next = event_next;
87} 128}
88 129
89void 130void
90_install_std_cb (SV *self, int type) 131_install_std_cb (SV *self, int type)
91 CODE: 132 CODE:
111 152
112 sv_magicext (SvRV (self), newRV_noinc ((SV *)priv), PERL_MAGIC_coro_event, 0, (char *)w, 0); 153 sv_magicext (SvRV (self), newRV_noinc ((SV *)priv), PERL_MAGIC_coro_event, 0, (char *)w, 0);
113 } 154 }
114} 155}
115 156
116void
117_next (SV *self)
118 CODE:
119{
120 pe_watcher *w = GEventAPI->sv_2watcher (self);
121 AV *priv = (AV *)w->ext_data;
122
123 if (AvARRAY (priv)[CD_OK] == &PL_sv_yes)
124 {
125 AvARRAY (priv)[CD_OK] = &PL_sv_no;
126 XSRETURN_NO; /* got an event */
127 }
128
129 av_push ((AV *)AvARRAY (priv)[CD_WAIT], SvREFCNT_inc (CORO_CURRENT));
130
131 if (!w->running)
132 GEventAPI->start (w, 1);
133
134 XSRETURN_YES; /* schedule */
135}
136
137SV *
138_event (SV *self)
139 CODE:
140{
141 if (GIMME_V == G_VOID)
142 XSRETURN_EMPTY;
143
144 {
145 pe_watcher *w = GEventAPI->sv_2watcher (self);
146 AV *priv = (AV *)w->ext_data;
147
148 RETVAL = newRV_inc ((SV *)priv);
149
150 /* may need to bless it now */
151 if (!SvOBJECT (priv))
152 {
153 SvREADONLY_off ((SV *)priv);
154 sv_bless (RETVAL, coro_event_event_stash);
155 SvREADONLY_on ((SV *)priv);
156 }
157 }
158}
159 OUTPUT:
160 RETVAL
161

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines