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

Comparing EV/EV.xs (file contents):
Revision 1.114 by root, Sat Jul 12 22:19:22 2008 UTC vs.
Revision 1.124 by root, Mon Jun 29 18:46:52 2009 UTC

24 24
25#ifndef _WIN32 25#ifndef _WIN32
26# include <pthread.h> 26# include <pthread.h>
27#endif 27#endif
28 28
29/* 5.10.0 */
30#ifndef SvREFCNT_inc_NN
31# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv)
32#endif
33
34/* 5.6.x */
35#ifndef SvRV_set
36# define SvRV_set(a,b) SvRV ((a)) = (b)
37#endif
38
29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 39#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
30 40
31#define WFLAG_KEEPALIVE 1 41#define WFLAG_KEEPALIVE 1
42#define WFLAG_UNREFED 2 /* has been unref'ed */
32 43
33#define UNREF(w) \ 44#define UNREF(w) \
34 if (!((w)->e_flags & WFLAG_KEEPALIVE) \ 45 if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
35 && !ev_is_active (w)) \ 46 && ev_is_active (w)) \
47 { \
36 ev_unref (e_loop (w)); 48 ev_unref (e_loop (w)); \
49 (w)->e_flags |= WFLAG_UNREFED; \
50 }
37 51
38#define REF(w) \ 52#define REF(w) \
39 if (!((w)->e_flags & WFLAG_KEEPALIVE) \ 53 if ((w)->e_flags & WFLAG_UNREFED) \
40 && ev_is_active (w)) \ 54 { \
55 (w)->e_flags &= ~WFLAG_UNREFED; \
41 ev_ref (e_loop (w)); 56 ev_ref (e_loop (w)); \
57 }
42 58
43#define START(type,w) \ 59#define START(type,w) \
44 do { \ 60 do { \
61 ev_ ## type ## _start (e_loop (w), w); \
45 UNREF (w); \ 62 UNREF (w); \
46 ev_ ## type ## _start (e_loop (w), w); \
47 } while (0) 63 } while (0)
48 64
49#define STOP(type,w) \ 65#define STOP(type,w) \
50 do { \ 66 do { \
51 REF (w); \ 67 REF (w); \
191 } 207 }
192 208
193 return rv; 209 return rv;
194} 210}
195 211
196static SV *sv_events_cache; 212static SV *sv_self_cache, *sv_events_cache;
197 213
198static void 214static void
199e_cb (EV_P_ ev_watcher *w, int revents) 215e_cb (EV_P_ ev_watcher *w, int revents)
200{ 216{
201 dSP; 217 dSP;
202 I32 mark = SP - PL_stack_base; 218 I32 mark = SP - PL_stack_base;
203 SV *sv_self, *sv_events; 219 SV *sv_self, *sv_events;
204 220
221 /* libev might have stopped the watcher */
222 if (expect_false (w->e_flags & WFLAG_UNREFED)
223 && !ev_is_active (w))
224 REF (w);
225
226 if (expect_true (sv_self_cache))
227 {
228 sv_self = sv_self_cache; sv_self_cache = 0;
229 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
230 }
231 else
232 {
205 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 233 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
234 SvREADONLY_on (sv_self);
235 }
236
237 if (expect_true (sv_events_cache))
238 {
239 sv_events = sv_events_cache; sv_events_cache = 0;
240 SvIV_set (sv_events, revents);
241 }
242 else
243 {
244 sv_events = newSViv (revents);
245 SvREADONLY_on (sv_events);
246 }
247
248 PUSHMARK (SP);
249 EXTEND (SP, 2);
250 PUSHs (sv_self);
251 PUSHs (sv_events);
252
253 PUTBACK;
254 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
255
256 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
257 SvREFCNT_dec (sv_self);
258 else
259 {
260 SvREFCNT_dec (SvRV (sv_self));
261 SvRV_set (sv_self, &PL_sv_undef);
262 sv_self_cache = sv_self;
263 }
264
265 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
266 SvREFCNT_dec (sv_events);
267 else
268 sv_events_cache = sv_events;
269
270 if (expect_false (SvTRUE (ERRSV)))
271 {
272 SPAGAIN;
273 PUSHMARK (SP);
274 PUTBACK;
275 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
276 }
277
278 SP = PL_stack_base + mark;
279 PUTBACK;
280}
281
282static void
283e_once_cb (int revents, void *arg)
284{
285 dSP;
286 I32 mark = SP - PL_stack_base;
287 SV *sv_events;
206 288
207 if (sv_events_cache) 289 if (sv_events_cache)
208 { 290 {
209 sv_events = sv_events_cache; sv_events_cache = 0; 291 sv_events = sv_events_cache; sv_events_cache = 0;
210 SvIV_set (sv_events, revents); 292 SvIV_set (sv_events, revents);
211 } 293 }
212 else 294 else
213 sv_events = newSViv (revents); 295 sv_events = newSViv (revents);
214 296
215 PUSHMARK (SP); 297 PUSHMARK (SP);
216 EXTEND (SP, 2);
217 PUSHs (sv_self);
218 PUSHs (sv_events); 298 XPUSHs (sv_events);
219 299
220 PUTBACK; 300 PUTBACK;
221 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 301 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
222 302
223 SvREFCNT_dec (sv_self); 303 SvREFCNT_dec ((SV *)arg);
224 304
225 if (sv_events_cache) 305 if (sv_events_cache)
226 SvREFCNT_dec (sv_events); 306 SvREFCNT_dec (sv_events);
227 else 307 else
228 sv_events_cache = sv_events; 308 sv_events_cache = sv_events;
237 317
238 SP = PL_stack_base + mark; 318 SP = PL_stack_base + mark;
239 PUTBACK; 319 PUTBACK;
240} 320}
241 321
242static void
243e_once_cb (int revents, void *arg)
244{
245 dSP;
246 I32 mark = SP - PL_stack_base;
247 SV *sv_events;
248
249 if (sv_events_cache)
250 {
251 sv_events = sv_events_cache; sv_events_cache = 0;
252 SvIV_set (sv_events, revents);
253 }
254 else
255 sv_events = newSViv (revents);
256
257 PUSHMARK (SP);
258 XPUSHs (sv_events);
259
260 PUTBACK;
261 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
262
263 SvREFCNT_dec ((SV *)arg);
264
265 if (sv_events_cache)
266 SvREFCNT_dec (sv_events);
267 else
268 sv_events_cache = sv_events;
269
270 if (SvTRUE (ERRSV))
271 {
272 SPAGAIN;
273 PUSHMARK (SP);
274 PUTBACK;
275 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
276 }
277
278 SP = PL_stack_base + mark;
279 PUTBACK;
280}
281
282static ev_tstamp 322static ev_tstamp
283e_periodic_cb (ev_periodic *w, ev_tstamp now) 323e_periodic_cb (ev_periodic *w, ev_tstamp now)
284{ 324{
285 ev_tstamp retval; 325 ev_tstamp retval;
286 int count; 326 int count;
350 const_iv (EV_, MINPRI) 390 const_iv (EV_, MINPRI)
351 const_iv (EV_, MAXPRI) 391 const_iv (EV_, MAXPRI)
352 392
353 const_iv (EV_, UNDEF) 393 const_iv (EV_, UNDEF)
354 const_iv (EV_, NONE) 394 const_iv (EV_, NONE)
355 const_iv (EV_, TIMEOUT)
356 const_iv (EV_, READ) 395 const_iv (EV_, READ)
357 const_iv (EV_, WRITE) 396 const_iv (EV_, WRITE)
397 const_iv (EV_, IO)
398 const_iv (EV_, TIMEOUT)
399 const_iv (EV_, TIMER)
400 const_iv (EV_, PERIODIC)
358 const_iv (EV_, SIGNAL) 401 const_iv (EV_, SIGNAL)
402 const_iv (EV_, CHILD)
403 const_iv (EV_, STAT)
359 const_iv (EV_, IDLE) 404 const_iv (EV_, IDLE)
405 const_iv (EV_, PREPARE)
360 const_iv (EV_, CHECK) 406 const_iv (EV_, CHECK)
407 const_iv (EV_, EMBED)
408 const_iv (EV_, FORK)
409 const_iv (EV_, ASYNC)
410 const_iv (EV_, CUSTOM)
361 const_iv (EV_, ERROR) 411 const_iv (EV_, ERROR)
362 412
413 const_iv (EV, LOOP_NONBLOCK)
363 const_iv (EV, LOOP_ONESHOT) 414 const_iv (EV, LOOP_ONESHOT)
415
364 const_iv (EV, LOOP_NONBLOCK) 416 const_iv (EV, UNLOOP_CANCEL)
365 const_iv (EV, UNLOOP_ONE) 417 const_iv (EV, UNLOOP_ONE)
366 const_iv (EV, UNLOOP_ALL) 418 const_iv (EV, UNLOOP_ALL)
367 419
368 const_iv (EV, BACKEND_SELECT) 420 const_iv (EV, BACKEND_SELECT)
369 const_iv (EV, BACKEND_POLL) 421 const_iv (EV, BACKEND_POLL)
372 const_iv (EV, BACKEND_DEVPOLL) 424 const_iv (EV, BACKEND_DEVPOLL)
373 const_iv (EV, BACKEND_PORT) 425 const_iv (EV, BACKEND_PORT)
374 const_iv (EV, FLAG_AUTO) 426 const_iv (EV, FLAG_AUTO)
375 const_iv (EV, FLAG_NOENV) 427 const_iv (EV, FLAG_NOENV)
376 const_iv (EV, FLAG_FORKCHECK) 428 const_iv (EV, FLAG_FORKCHECK)
429
430 const_iv (EV_, VERSION_MAJOR)
431 const_iv (EV_, VERSION_MINOR)
377 }; 432 };
378 433
379 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 434 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
380 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 435 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
381 436
411 evapi.loop_new = ev_loop_new; 466 evapi.loop_new = ev_loop_new;
412 evapi.loop_destroy = ev_loop_destroy; 467 evapi.loop_destroy = ev_loop_destroy;
413 evapi.loop_fork = ev_loop_fork; 468 evapi.loop_fork = ev_loop_fork;
414 evapi.loop_count = ev_loop_count; 469 evapi.loop_count = ev_loop_count;
415 evapi.now = ev_now; 470 evapi.now = ev_now;
471 evapi.now_update = ev_now_update;
472 evapi.suspend = ev_suspend;
473 evapi.resume = ev_resume;
416 evapi.backend = ev_backend; 474 evapi.backend = ev_backend;
417 evapi.unloop = ev_unloop; 475 evapi.unloop = ev_unloop;
418 evapi.ref = ev_ref; 476 evapi.ref = ev_ref;
419 evapi.unref = ev_unref; 477 evapi.unref = ev_unref;
420 evapi.loop = ev_loop; 478 evapi.loop = ev_loop;
486 544
487unsigned int ev_recommended_backends () 545unsigned int ev_recommended_backends ()
488 546
489unsigned int ev_embeddable_backends () 547unsigned int ev_embeddable_backends ()
490 548
549void ev_sleep (NV interval)
550
491NV ev_time () 551NV ev_time ()
492 552
493NV ev_now () 553NV ev_now ()
554 C_ARGS: evapi.default_loop
555
556void ev_now_update ()
557 C_ARGS: evapi.default_loop
558
559void ev_suspend ()
560 C_ARGS: evapi.default_loop
561
562void ev_resume ()
494 C_ARGS: evapi.default_loop 563 C_ARGS: evapi.default_loop
495 564
496unsigned int ev_backend () 565unsigned int ev_backend ()
497 C_ARGS: evapi.default_loop 566 C_ARGS: evapi.default_loop
498 567
703 RETVAL = w->e_flags & WFLAG_KEEPALIVE; 772 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
704 new_value = new_value ? WFLAG_KEEPALIVE : 0; 773 new_value = new_value ? WFLAG_KEEPALIVE : 0;
705 774
706 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) 775 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
707 { 776 {
777 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
708 REF (w); 778 REF (w);
709 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
710 UNREF (w); 779 UNREF (w);
711 } 780 }
712} 781}
713 OUTPUT: 782 OUTPUT:
714 RETVAL 783 RETVAL
889 958
890void ev_timer_again (ev_timer *w) 959void ev_timer_again (ev_timer *w)
891 INIT: 960 INIT:
892 CHECK_REPEAT (w->repeat); 961 CHECK_REPEAT (w->repeat);
893 CODE: 962 CODE:
894 REF (w);
895 ev_timer_again (e_loop (w), w); 963 ev_timer_again (e_loop (w), w);
896 UNREF (w); 964 UNREF (w);
897 965
898void DESTROY (ev_timer *w) 966void DESTROY (ev_timer *w)
899 CODE: 967 CODE:
918 CODE: 986 CODE:
919 STOP (periodic, w); 987 STOP (periodic, w);
920 988
921void ev_periodic_again (ev_periodic *w) 989void ev_periodic_again (ev_periodic *w)
922 CODE: 990 CODE:
923 REF (w);
924 ev_periodic_again (e_loop (w), w); 991 ev_periodic_again (e_loop (w), w);
925 UNREF (w); 992 UNREF (w);
926 993
927void DESTROY (ev_periodic *w) 994void DESTROY (ev_periodic *w)
928 CODE: 995 CODE:
1209 1276
1210void ev_loop_verify (struct ev_loop *loop) 1277void ev_loop_verify (struct ev_loop *loop)
1211 1278
1212NV ev_now (struct ev_loop *loop) 1279NV ev_now (struct ev_loop *loop)
1213 1280
1281void ev_now_update (struct ev_loop *loop)
1282
1283void ev_suspend (struct ev_loop *loop)
1284
1285void ev_resume (struct ev_loop *loop)
1286
1214void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) 1287void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1215 1288
1216void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) 1289void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1217 1290
1218unsigned int ev_backend (struct ev_loop *loop) 1291unsigned int ev_backend (struct ev_loop *loop)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines