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

Comparing EV/EV.xs (file contents):
Revision 1.165 by root, Fri Apr 5 21:04:30 2013 UTC vs.
Revision 1.169 by root, Sat Mar 8 15:51:23 2014 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/* fix perl api breakage */ 5/* fix perl api breakage */
6#ifndef WIN32
6#undef signal 7# undef signal
7#undef sigaction 8# undef sigaction
9#endif
8 10
9#include "schmorp.h" 11#include "schmorp.h"
10 12
11/* old API compatibility */ 13/* old API compatibility */
12static int 14static int
35# define fd_mask Perl_fd_mask 37# define fd_mask Perl_fd_mask
36#endif 38#endif
37/* due to bugs in OS X we have to use libev/ explicitly here */ 39/* due to bugs in OS X we have to use libev/ explicitly here */
38#include "libev/ev.c" 40#include "libev/ev.c"
39 41
40#if !defined _WIN32 && !defined _MINIX 42#if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK
41# include <pthread.h> 43# include <pthread.h>
42#endif 44#endif
43 45
44#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) 46#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop))
45#define e_flags(w) ((ev_watcher *)(w))->e_flags 47#define e_flags(w) ((ev_watcher *)(w))->e_flags
47#define e_fh(w) ((ev_watcher *)(w))->fh 49#define e_fh(w) ((ev_watcher *)(w))->fh
48#define e_data(w) ((ev_watcher *)(w))->data 50#define e_data(w) ((ev_watcher *)(w))->data
49 51
50#define WFLAG_KEEPALIVE 1 52#define WFLAG_KEEPALIVE 1
51#define WFLAG_UNREFED 2 /* has been unref'ed */ 53#define WFLAG_UNREFED 2 /* has been unref'ed */
52#define WFLAG_NOARGS 4 /* do not pass anything to the callback */
53 54
54#define UNREF(w) \ 55#define UNREF(w) \
55 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ 56 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
56 && ev_is_active (w)) \ 57 && ev_is_active (w)) \
57 { \ 58 { \
200 /* libev might have stopped the watcher */ 201 /* libev might have stopped the watcher */
201 if (expect_false (w->e_flags & WFLAG_UNREFED) 202 if (expect_false (w->e_flags & WFLAG_UNREFED)
202 && !ev_is_active (w)) 203 && !ev_is_active (w))
203 REF (w); 204 REF (w);
204 205
205 PUSHMARK (SP); 206 if (expect_true (sv_self_cache))
206
207 if (!expect_true (e_flags (w) & WFLAG_NOARGS))
208 { 207 {
209 if (expect_true (sv_self_cache))
210 {
211 sv_self = sv_self_cache; sv_self_cache = 0; 208 sv_self = sv_self_cache; sv_self_cache = 0;
212 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); 209 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;
252 } 210 }
253 else 211 else
254 { 212 {
255 PUTBACK; 213 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */
256 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 214 SvREADONLY_on (sv_self);
257 } 215 }
216
217 if (expect_true (sv_events_cache))
218 {
219 sv_events = sv_events_cache; sv_events_cache = 0;
220 SvIV_set (sv_events, revents);
221 SvIOK_only (sv_events);
222 }
223 else
224 {
225 sv_events = newSViv (revents);
226 SvREADONLY_on (sv_events);
227 }
228
229 PUSHMARK (SP);
230 EXTEND (SP, 2);
231 PUSHs (sv_self);
232 PUSHs (sv_events);
233
234 PUTBACK;
235 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
236
237 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
238 SvREFCNT_dec (sv_self);
239 else
240 {
241 SvREFCNT_dec (SvRV (sv_self));
242 SvRV_set (sv_self, &PL_sv_undef);
243 sv_self_cache = sv_self;
244 }
245
246 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
247 SvREFCNT_dec (sv_events);
248 else
249 sv_events_cache = sv_events;
258 250
259 if (expect_false (SvTRUE (ERRSV))) 251 if (expect_false (SvTRUE (ERRSV)))
260 { 252 {
261 SPAGAIN; 253 SPAGAIN;
262 PUSHMARK (SP); 254 PUSHMARK (SP);
541 evapi.invoke = ev_invoke; 533 evapi.invoke = ev_invoke;
542 534
543 sv_setiv (sv, (IV)&evapi); 535 sv_setiv (sv, (IV)&evapi);
544 SvREADONLY_on (sv); 536 SvREADONLY_on (sv);
545 } 537 }
546#if !defined _WIN32 && !defined _MINIX 538#if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK
547#if __linux 539#if __linux
548 int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle); 540 int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
549 __register_atfork (0, 0, default_fork, 0); 541 __register_atfork (0, 0, default_fork, 0);
550#else 542#else
551 pthread_atfork (0, 0, default_fork); 543 pthread_atfork (0, 0, default_fork);
666 _ae_io = 2 658 _ae_io = 2
667 CODE: 659 CODE:
668{ 660{
669 int fd = s_fileno (fh, events & EV_WRITE); 661 int fd = s_fileno (fh, events & EV_WRITE);
670 CHECK_FD (fh, fd); 662 CHECK_FD (fh, fd);
663
664 if (ix == 2)
665 {
666 ix = 0;
667 events = events ? EV_WRITE : EV_READ;
668 }
669
671 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); 670 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
672 e_fh (RETVAL) = newSVsv (fh); 671 e_fh (RETVAL) = newSVsv (fh);
673
674 if (ix == 2)
675 {
676 events = events ? EV_WRITE : EV_READ;
677 e_flags (RETVAL) |= WFLAG_NOARGS;
678 }
679
680 ev_io_set (RETVAL, fd, events); 672 ev_io_set (RETVAL, fd, events);
681 if (ix != 1) START (io, RETVAL); 673 if (!ix) START (io, RETVAL);
682} 674}
683 OUTPUT: 675 OUTPUT:
684 RETVAL 676 RETVAL
685 677
686ev_timer *timer (NV after, NV repeat, SV *cb) 678ev_timer *timer (NV after, NV repeat, SV *cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines