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

Comparing EV/EV.xs (file contents):
Revision 1.160 by root, Sun May 6 16:30:27 2012 UTC vs.
Revision 1.165 by root, Fri Apr 5 21:04:30 2013 UTC

13sv_fileno (SV *fh) 13sv_fileno (SV *fh)
14{ 14{
15 return s_fileno (fh, 0); 15 return s_fileno (fh, 0);
16} 16}
17 17
18#ifndef GvCV_set
19# define GvCV_set(gv,cv) GvCV (gv) = cv
20#endif
21
18#define EV_STANDALONE 1 22#define EV_STANDALONE 1
19#define EV_PROTOTYPES 1 23#define EV_PROTOTYPES 1
20#define EV_USE_CLOCK_SYSCALL 0 /* as long as we need pthreads anyways... */
21#define EV_USE_NANOSLEEP EV_USE_MONOTONIC 24#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
22#define EV_USE_FLOOR 1 25#define EV_USE_FLOOR 1
23#define EV_API_STATIC 26#define EV_API_STATIC
24#define EV_H <ev.h> 27#define EV_H <ev.h>
25#define EV_CONFIG_H error 28#define EV_CONFIG_H error
44#define e_fh(w) ((ev_watcher *)(w))->fh 47#define e_fh(w) ((ev_watcher *)(w))->fh
45#define e_data(w) ((ev_watcher *)(w))->data 48#define e_data(w) ((ev_watcher *)(w))->data
46 49
47#define WFLAG_KEEPALIVE 1 50#define WFLAG_KEEPALIVE 1
48#define WFLAG_UNREFED 2 /* has been unref'ed */ 51#define WFLAG_UNREFED 2 /* has been unref'ed */
52#define WFLAG_NOARGS 4 /* do not pass anything to the callback */
49 53
50#define UNREF(w) \ 54#define UNREF(w) \
51 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ 55 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
52 && ev_is_active (w)) \ 56 && ev_is_active (w)) \
53 { \ 57 { \
196 /* libev might have stopped the watcher */ 200 /* libev might have stopped the watcher */
197 if (expect_false (w->e_flags & WFLAG_UNREFED) 201 if (expect_false (w->e_flags & WFLAG_UNREFED)
198 && !ev_is_active (w)) 202 && !ev_is_active (w))
199 REF (w); 203 REF (w);
200 204
201 if (expect_true (sv_self_cache)) 205 PUSHMARK (SP);
206
207 if (!expect_true (e_flags (w) & WFLAG_NOARGS))
202 { 208 {
209 if (expect_true (sv_self_cache))
210 {
203 sv_self = sv_self_cache; sv_self_cache = 0; 211 sv_self = sv_self_cache; sv_self_cache = 0;
204 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); 212 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
213 }
214 else
215 {
216 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */
217 SvREADONLY_on (sv_self);
218 }
219
220 if (expect_true (sv_events_cache))
221 {
222 sv_events = sv_events_cache; sv_events_cache = 0;
223 SvIV_set (sv_events, revents);
224 SvIOK_only (sv_events);
225 }
226 else
227 {
228 sv_events = newSViv (revents);
229 SvREADONLY_on (sv_events);
230 }
231
232 EXTEND (SP, 2);
233 PUSHs (sv_self);
234 PUSHs (sv_events);
235
236 PUTBACK;
237 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
238
239 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
240 SvREFCNT_dec (sv_self);
241 else
242 {
243 SvREFCNT_dec (SvRV (sv_self));
244 SvRV_set (sv_self, &PL_sv_undef);
245 sv_self_cache = sv_self;
246 }
247
248 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
249 SvREFCNT_dec (sv_events);
250 else
251 sv_events_cache = sv_events;
205 } 252 }
206 else 253 else
207 { 254 {
208 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ 255 PUTBACK;
209 SvREADONLY_on (sv_self); 256 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
210 } 257 }
211
212 if (expect_true (sv_events_cache))
213 {
214 sv_events = sv_events_cache; sv_events_cache = 0;
215 SvIV_set (sv_events, revents);
216 SvIOK_only (sv_events);
217 }
218 else
219 {
220 sv_events = newSViv (revents);
221 SvREADONLY_on (sv_events);
222 }
223
224 PUSHMARK (SP);
225 EXTEND (SP, 2);
226 PUSHs (sv_self);
227 PUSHs (sv_events);
228
229 PUTBACK;
230 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
231
232 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
233 SvREFCNT_dec (sv_self);
234 else
235 {
236 SvREFCNT_dec (SvRV (sv_self));
237 SvRV_set (sv_self, &PL_sv_undef);
238 sv_self_cache = sv_self;
239 }
240
241 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
242 SvREFCNT_dec (sv_events);
243 else
244 sv_events_cache = sv_events;
245 258
246 if (expect_false (SvTRUE (ERRSV))) 259 if (expect_false (SvTRUE (ERRSV)))
247 { 260 {
248 SPAGAIN; 261 SPAGAIN;
249 PUSHMARK (SP); 262 PUSHMARK (SP);
382 const_iv (EV_, SIGNAL) 395 const_iv (EV_, SIGNAL)
383 const_iv (EV_, CHILD) 396 const_iv (EV_, CHILD)
384 const_iv (EV_, STAT) 397 const_iv (EV_, STAT)
385 const_iv (EV_, IDLE) 398 const_iv (EV_, IDLE)
386 const_iv (EV_, PREPARE) 399 const_iv (EV_, PREPARE)
387 const_iv (EV_, CHECK) 400 /*const_iv (EV_, CHECK) needs special tretament */
388 const_iv (EV_, EMBED) 401 const_iv (EV_, EMBED)
389 const_iv (EV_, FORK) 402 const_iv (EV_, FORK)
390 const_iv (EV_, CLEANUP) 403 const_iv (EV_, CLEANUP)
391 const_iv (EV_, ASYNC) 404 const_iv (EV_, ASYNC)
392 const_iv (EV_, CUSTOM) 405 const_iv (EV_, CUSTOM)
426#endif 439#endif
427 }; 440 };
428 441
429 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 442 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
430 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 443 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
444
445 /* since this clashes with perl CHECK blocks, */
446 /* but we are interested in constants, */
447 /* and not blocks, we treat CHECK specially. */
448 {
449 /* the local $^W = 0 takes care of the warning */
450 CV *cv = newCONSTSUB (stash, "CHECK", newSViv (EV_CHECK));
451 /* now we need to re-set the gv, in case it was hijacked */
452 GvCV_set (gv_fetchpv ("EV::CHECK", GV_ADD, SVt_PVCV), cv);
453 }
431 454
432 stash_loop = gv_stashpv ("EV::Loop" , 1); 455 stash_loop = gv_stashpv ("EV::Loop" , 1);
433 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 456 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
434 stash_io = gv_stashpv ("EV::IO" , 1); 457 stash_io = gv_stashpv ("EV::IO" , 1);
435 stash_timer = gv_stashpv ("EV::Timer" , 1); 458 stash_timer = gv_stashpv ("EV::Timer" , 1);
519 542
520 sv_setiv (sv, (IV)&evapi); 543 sv_setiv (sv, (IV)&evapi);
521 SvREADONLY_on (sv); 544 SvREADONLY_on (sv);
522 } 545 }
523#if !defined _WIN32 && !defined _MINIX 546#if !defined _WIN32 && !defined _MINIX
547#if __linux
548 int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
549 __register_atfork (0, 0, default_fork, 0);
550#else
524 pthread_atfork (0, 0, default_fork); 551 pthread_atfork (0, 0, default_fork);
552#endif
525#endif 553#endif
526} 554}
527 555
528SV *ev_default_loop (unsigned int flags = 0) 556SV *ev_default_loop (unsigned int flags = 0)
529 CODE: 557 CODE:
618 C_ARGS: evapi.default_loop, fd, revents 646 C_ARGS: evapi.default_loop, fd, revents
619 647
620void ev_feed_signal_event (SV *signal) 648void ev_feed_signal_event (SV *signal)
621 CODE: 649 CODE:
622{ 650{
623 Signal signum = s_signum (signal); 651 Signal signum = s_signum (signal);
624 CHECK_SIG (signal, signum); 652 CHECK_SIG (signal, signum);
625 653
626 ev_feed_signal_event (evapi.default_loop, signum); 654 ev_feed_signal_event (evapi.default_loop, signum);
627} 655}
628 656
638 _ae_io = 2 666 _ae_io = 2
639 CODE: 667 CODE:
640{ 668{
641 int fd = s_fileno (fh, events & EV_WRITE); 669 int fd = s_fileno (fh, events & EV_WRITE);
642 CHECK_FD (fh, fd); 670 CHECK_FD (fh, fd);
671 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
672 e_fh (RETVAL) = newSVsv (fh);
643 673
644 if (ix == 2) 674 if (ix == 2)
645 { 675 {
646 ix = 0;
647 events = events ? EV_WRITE : EV_READ; 676 events = events ? EV_WRITE : EV_READ;
677 e_flags (RETVAL) |= WFLAG_NOARGS;
648 } 678 }
649 679
650 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
651 e_fh (RETVAL) = newSVsv (fh);
652 ev_io_set (RETVAL, fd, events); 680 ev_io_set (RETVAL, fd, events);
653 if (!ix) START (io, RETVAL); 681 if (ix != 1) START (io, RETVAL);
654} 682}
655 OUTPUT: 683 OUTPUT:
656 RETVAL 684 RETVAL
657 685
658ev_timer *timer (NV after, NV repeat, SV *cb) 686ev_timer *timer (NV after, NV repeat, SV *cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines