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

Comparing EV/EV.xs (file contents):
Revision 1.136 by root, Tue Mar 16 17:11:48 2010 UTC vs.
Revision 1.138 by root, Wed Apr 14 00:17:22 2010 UTC

33 33
34#ifndef _WIN32 34#ifndef _WIN32
35# include <pthread.h> 35# include <pthread.h>
36#endif 36#endif
37 37
38#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 38#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop))
39#define e_flags(w) ((ev_watcher *)(w))->e_flags
40#define e_self(w) ((ev_watcher *)(w))->self
41#define e_fh(w) ((ev_watcher *)(w))->fh
42#define e_data(w) ((ev_watcher *)(w))->data
39 43
40#define WFLAG_KEEPALIVE 1 44#define WFLAG_KEEPALIVE 1
41#define WFLAG_UNREFED 2 /* has been unref'ed */ 45#define WFLAG_UNREFED 2 /* has been unref'ed */
42 46
43#define UNREF(w) \ 47#define UNREF(w) \
44 if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ 48 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
45 && ev_is_active (w)) \ 49 && ev_is_active (w)) \
46 { \ 50 { \
47 ev_unref (e_loop (w)); \ 51 ev_unref (e_loop (w)); \
48 (w)->e_flags |= WFLAG_UNREFED; \ 52 e_flags (w) |= WFLAG_UNREFED; \
49 } 53 }
50 54
51#define REF(w) \ 55#define REF(w) \
52 if ((w)->e_flags & WFLAG_UNREFED) \ 56 if (e_flags (w) & WFLAG_UNREFED) \
53 { \ 57 { \
54 (w)->e_flags &= ~WFLAG_UNREFED; \ 58 e_flags (w) &= ~WFLAG_UNREFED; \
55 ev_ref (e_loop (w)); \ 59 ev_ref (e_loop (w)); \
56 } 60 }
57 61
58#define START(type,w) \ 62#define START(type,w) \
59 do { \ 63 do { \
123///////////////////////////////////////////////////////////////////////////// 127/////////////////////////////////////////////////////////////////////////////
124// Event 128// Event
125 129
126static void e_cb (EV_P_ ev_watcher *w, int revents); 130static void e_cb (EV_P_ ev_watcher *w, int revents);
127 131
128static void * 132void *
129e_new (int size, SV *cb_sv, SV *loop) 133e_new (int size, SV *cb_sv, SV *loop)
130{ 134{
131 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0; 135 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0;
132 ev_watcher *w; 136 ev_watcher *w;
133 SV *self = NEWSV (0, size); 137 SV *self = NEWSV (0, size);
195 sv_self = sv_self_cache; sv_self_cache = 0; 199 sv_self = sv_self_cache; sv_self_cache = 0;
196 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); 200 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
197 } 201 }
198 else 202 else
199 { 203 {
200 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 204 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */
201 SvREADONLY_on (sv_self); 205 SvREADONLY_on (sv_self);
202 } 206 }
203 207
204 if (expect_true (sv_events_cache)) 208 if (expect_true (sv_events_cache))
205 { 209 {
296 ENTER; 300 ENTER;
297 SAVETMPS; 301 SAVETMPS;
298 302
299 PUSHMARK (SP); 303 PUSHMARK (SP);
300 EXTEND (SP, 2); 304 EXTEND (SP, 2);
301 PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */ 305 PUSHs (newRV_inc (e_self (w))); /* e_self (w) MUST be blessed by now */
302 PUSHs (newSVnv (now)); 306 PUSHs (newSVnv (now));
303 307
304 PUTBACK; 308 PUTBACK;
305 count = call_sv (w->fh, G_SCALAR | G_EVAL); 309 count = call_sv (w->fh, G_SCALAR | G_EVAL);
306 SPAGAIN; 310 SPAGAIN;
435 evapi.time_ = ev_time; 439 evapi.time_ = ev_time;
436 evapi.sleep_ = ev_sleep; 440 evapi.sleep_ = ev_sleep;
437 evapi.loop_new = ev_loop_new; 441 evapi.loop_new = ev_loop_new;
438 evapi.loop_destroy = ev_loop_destroy; 442 evapi.loop_destroy = ev_loop_destroy;
439 evapi.loop_fork = ev_loop_fork; 443 evapi.loop_fork = ev_loop_fork;
440 evapi.loop_count = ev_loop_count; 444 evapi.iteration = ev_iteration;
441 evapi.loop_depth = ev_loop_depth; 445 evapi.depth = ev_depth;
442 evapi.set_userdata = ev_set_userdata; 446 evapi.set_userdata = ev_set_userdata;
443 evapi.userdata = ev_userdata; 447 evapi.userdata = ev_userdata;
444 evapi.now = ev_now; 448 evapi.now = ev_now;
445 evapi.now_update = ev_now_update; 449 evapi.now_update = ev_now_update;
446 evapi.suspend = ev_suspend; 450 evapi.suspend = ev_suspend;
447 evapi.resume = ev_resume; 451 evapi.resume = ev_resume;
448 evapi.backend = ev_backend; 452 evapi.backend = ev_backend;
449 evapi.unloop = ev_unloop; 453 evapi.unloop = ev_unloop;
450 evapi.invoke_pending = ev_invoke_pending; 454 evapi.invoke_pending = ev_invoke_pending;
451 evapi.pending_count = ev_pending_count; 455 evapi.pending_count = ev_pending_count;
456 evapi.verify = ev_verify;
452 evapi.set_loop_release_cb = ev_set_loop_release_cb; 457 evapi.set_loop_release_cb = ev_set_loop_release_cb;
453 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; 458 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
454 evapi.ref = ev_ref; 459 evapi.ref = ev_ref;
455 evapi.unref = ev_unref; 460 evapi.unref = ev_unref;
456 evapi.loop = ev_loop; 461 evapi.loop = ev_loop;
542 C_ARGS: evapi.default_loop 547 C_ARGS: evapi.default_loop
543 548
544unsigned int ev_backend () 549unsigned int ev_backend ()
545 C_ARGS: evapi.default_loop 550 C_ARGS: evapi.default_loop
546 551
547void ev_loop_verify () 552void ev_verify ()
548 C_ARGS: evapi.default_loop 553 C_ARGS: evapi.default_loop
549 554
550unsigned int ev_loop_count () 555unsigned int ev_iteration ()
551 C_ARGS: evapi.default_loop 556 C_ARGS: evapi.default_loop
552 557
553unsigned int ev_loop_depth () 558unsigned int ev_depth ()
554 C_ARGS: evapi.default_loop 559 C_ARGS: evapi.default_loop
555 560
556void ev_set_io_collect_interval (NV interval) 561void ev_set_io_collect_interval (NV interval)
557 C_ARGS: evapi.default_loop, interval 562 C_ARGS: evapi.default_loop, interval
558 563
597 ix = 0; 602 ix = 0;
598 events = events ? EV_WRITE : EV_READ; 603 events = events ? EV_WRITE : EV_READ;
599 } 604 }
600 605
601 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); 606 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
602 RETVAL->fh = newSVsv (fh); 607 e_fh (RETVAL) = newSVsv (fh);
603 ev_io_set (RETVAL, fd, events); 608 ev_io_set (RETVAL, fd, events);
604 if (!ix) START (io, RETVAL); 609 if (!ix) START (io, RETVAL);
605} 610}
606 OUTPUT: 611 OUTPUT:
607 RETVAL 612 RETVAL
625 CHECK_REPEAT (interval); 630 CHECK_REPEAT (interval);
626 CODE: 631 CODE:
627{ 632{
628 ev_periodic *w; 633 ev_periodic *w;
629 w = e_new (sizeof (ev_periodic), cb, default_loop_sv); 634 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
630 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 635 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
631 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 636 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
632 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 637 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
633 if (!ix) START (periodic, w); 638 if (!ix) START (periodic, w);
634} 639}
635 OUTPUT: 640 OUTPUT:
636 RETVAL 641 RETVAL
703ev_stat *stat (SV *path, NV interval, SV *cb) 708ev_stat *stat (SV *path, NV interval, SV *cb)
704 ALIAS: 709 ALIAS:
705 stat_ns = 1 710 stat_ns = 1
706 CODE: 711 CODE:
707 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv); 712 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
708 RETVAL->fh = newSVsv (path); 713 e_fh (RETVAL) = newSVsv (path);
709 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 714 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
710 if (!ix) START (stat, RETVAL); 715 if (!ix) START (stat, RETVAL);
711 OUTPUT: 716 OUTPUT:
712 RETVAL 717 RETVAL
713 718
714ev_embed *embed (struct ev_loop *loop, SV *cb = 0) 719ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
718{ 723{
719 if (!(ev_backend (loop) & ev_embeddable_backends ())) 724 if (!(ev_backend (loop) & ev_embeddable_backends ()))
720 croak ("passed loop is not embeddable via EV::embed,"); 725 croak ("passed loop is not embeddable via EV::embed,");
721 726
722 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); 727 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
723 RETVAL->fh = newSVsv (ST (0)); 728 e_fh (RETVAL) = newSVsv (ST (0));
724 ev_embed_set (RETVAL, loop); 729 ev_embed_set (RETVAL, loop);
725 if (!ix) START (embed, RETVAL); 730 if (!ix) START (embed, RETVAL);
726} 731}
727 OUTPUT: 732 OUTPUT:
728 RETVAL 733 RETVAL
866 CODE: 871 CODE:
867{ 872{
868 int fd = s_fileno (fh, events & EV_WRITE); 873 int fd = s_fileno (fh, events & EV_WRITE);
869 CHECK_FD (fh, fd); 874 CHECK_FD (fh, fd);
870 875
871 sv_setsv (w->fh, fh); 876 sv_setsv (e_fh (w), fh);
872 RESET (io, w, (w, fd, events)); 877 RESET (io, w, (w, fd, events));
873} 878}
874 879
875SV *fh (ev_io *w, SV *new_fh = 0) 880SV *fh (ev_io *w, SV *new_fh = 0)
876 CODE: 881 CODE:
878 if (items > 1) 883 if (items > 1)
879 { 884 {
880 int fd = s_fileno (new_fh, w->events & EV_WRITE); 885 int fd = s_fileno (new_fh, w->events & EV_WRITE);
881 CHECK_FD (new_fh, fd); 886 CHECK_FD (new_fh, fd);
882 887
883 RETVAL = w->fh; 888 RETVAL = e_fh (w);
884 w->fh = newSVsv (new_fh); 889 e_fh (w) = newSVsv (new_fh);
885 890
886 RESET (io, w, (w, fd, w->events)); 891 RESET (io, w, (w, fd, w->events));
887 } 892 }
888 else 893 else
889 RETVAL = newSVsv (w->fh); 894 RETVAL = newSVsv (e_fh (w));
890} 895}
891 OUTPUT: 896 OUTPUT:
892 RETVAL 897 RETVAL
893 898
894int events (ev_io *w, int new_events = EV_UNDEF) 899int events (ev_io *w, int new_events = EV_UNDEF)
1000void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) 1005void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
1001 INIT: 1006 INIT:
1002 CHECK_REPEAT (interval); 1007 CHECK_REPEAT (interval);
1003 CODE: 1008 CODE:
1004{ 1009{
1005 SvREFCNT_dec (w->fh); 1010 SvREFCNT_dec (e_fh (w));
1006 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 1011 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1007 1012
1008 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 1013 RESET (periodic, w, (w, at, interval, e_fh (w) ? e_periodic_cb : 0));
1009} 1014}
1010 1015
1011NV at (ev_periodic *w) 1016NV at (ev_periodic *w)
1012 CODE: 1017 CODE:
1013 RETVAL = ev_periodic_at (w); 1018 RETVAL = ev_periodic_at (w);
1120 e_destroy (w); 1125 e_destroy (w);
1121 1126
1122void set (ev_stat *w, SV *path, NV interval) 1127void set (ev_stat *w, SV *path, NV interval)
1123 CODE: 1128 CODE:
1124{ 1129{
1125 sv_setsv (w->fh, path); 1130 sv_setsv (e_fh (w), path);
1126 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval)); 1131 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval));
1127} 1132}
1128 1133
1129SV *path (ev_stat *w, SV *new_path = 0) 1134SV *path (ev_stat *w, SV *new_path = 0)
1130 CODE: 1135 CODE:
1131{ 1136{
1132 RETVAL = SvREFCNT_inc (w->fh); 1137 RETVAL = SvREFCNT_inc (e_fh (w));
1133 1138
1134 if (items > 1) 1139 if (items > 1)
1135 { 1140 {
1136 SvREFCNT_dec (w->fh); 1141 SvREFCNT_dec (e_fh (w));
1137 w->fh = newSVsv (new_path); 1142 e_fh (w) = newSVsv (new_path);
1138 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval)); 1143 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval));
1139 } 1144 }
1140} 1145}
1141 OUTPUT: 1146 OUTPUT:
1142 RETVAL 1147 RETVAL
1143 1148
1145 CODE: 1150 CODE:
1146{ 1151{
1147 RETVAL = w->interval; 1152 RETVAL = w->interval;
1148 1153
1149 if (items > 1) 1154 if (items > 1)
1150 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); 1155 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), new_interval));
1151} 1156}
1152 OUTPUT: 1157 OUTPUT:
1153 RETVAL 1158 RETVAL
1154 1159
1155void prev (ev_stat *w) 1160void prev (ev_stat *w)
1214 e_destroy (w); 1219 e_destroy (w);
1215 1220
1216void set (ev_embed *w, struct ev_loop *loop) 1221void set (ev_embed *w, struct ev_loop *loop)
1217 CODE: 1222 CODE:
1218{ 1223{
1219 sv_setsv (w->fh, ST (1)); 1224 sv_setsv (e_fh (w), ST (1));
1220 RESET (embed, w, (w, loop)); 1225 RESET (embed, w, (w, loop));
1221} 1226}
1222 1227
1223SV *other (ev_embed *w) 1228SV *other (ev_embed *w)
1224 CODE: 1229 CODE:
1225 RETVAL = newSVsv (w->fh); 1230 RETVAL = newSVsv (e_fh (w));
1226 OUTPUT: 1231 OUTPUT:
1227 RETVAL 1232 RETVAL
1228 1233
1229void ev_embed_sweep (ev_embed *w) 1234void ev_embed_sweep (ev_embed *w)
1230 C_ARGS: e_loop (w), w 1235 C_ARGS: e_loop (w), w
1273 if (loop != evapi.default_loop) /* global destruction sucks */ 1278 if (loop != evapi.default_loop) /* global destruction sucks */
1274 ev_loop_destroy (loop); 1279 ev_loop_destroy (loop);
1275 1280
1276void ev_loop_fork (struct ev_loop *loop) 1281void ev_loop_fork (struct ev_loop *loop)
1277 1282
1278void ev_loop_verify (struct ev_loop *loop) 1283void ev_verify (struct ev_loop *loop)
1279 1284
1280NV ev_now (struct ev_loop *loop) 1285NV ev_now (struct ev_loop *loop)
1281 1286
1282void ev_now_update (struct ev_loop *loop) 1287void ev_now_update (struct ev_loop *loop)
1283 1288
1289 1294
1290void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) 1295void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1291 1296
1292unsigned int ev_backend (struct ev_loop *loop) 1297unsigned int ev_backend (struct ev_loop *loop)
1293 1298
1294unsigned int ev_loop_count (struct ev_loop *loop) 1299unsigned int ev_iteration (struct ev_loop *loop)
1295 1300
1296unsigned int ev_loop_depth (struct ev_loop *loop) 1301unsigned int ev_depth (struct ev_loop *loop)
1297 1302
1298void ev_loop (struct ev_loop *loop, int flags = 0) 1303void ev_loop (struct ev_loop *loop, int flags = 0)
1299 1304
1300void ev_unloop (struct ev_loop *loop, int how = 1) 1305void ev_unloop (struct ev_loop *loop, int how = 1)
1301 1306
1325{ 1330{
1326 int fd = s_fileno (fh, events & EV_WRITE); 1331 int fd = s_fileno (fh, events & EV_WRITE);
1327 CHECK_FD (fh, fd); 1332 CHECK_FD (fh, fd);
1328 1333
1329 RETVAL = e_new (sizeof (ev_io), cb, ST (0)); 1334 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1330 RETVAL->fh = newSVsv (fh); 1335 e_fh (RETVAL) = newSVsv (fh);
1331 ev_io_set (RETVAL, fd, events); 1336 ev_io_set (RETVAL, fd, events);
1332 if (!ix) START (io, RETVAL); 1337 if (!ix) START (io, RETVAL);
1333} 1338}
1334 OUTPUT: 1339 OUTPUT:
1335 RETVAL 1340 RETVAL
1353 CHECK_REPEAT (interval); 1358 CHECK_REPEAT (interval);
1354 CODE: 1359 CODE:
1355{ 1360{
1356 ev_periodic *w; 1361 ev_periodic *w;
1357 w = e_new (sizeof (ev_periodic), cb, ST (0)); 1362 w = e_new (sizeof (ev_periodic), cb, ST (0));
1358 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 1363 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1359 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 1364 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
1360 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 1365 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1361 if (!ix) START (periodic, w); 1366 if (!ix) START (periodic, w);
1362} 1367}
1363 OUTPUT: 1368 OUTPUT:
1364 RETVAL 1369 RETVAL
1431ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1436ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1432 ALIAS: 1437 ALIAS:
1433 stat_ns = 1 1438 stat_ns = 1
1434 CODE: 1439 CODE:
1435 RETVAL = e_new (sizeof (ev_stat), cb, ST (0)); 1440 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1436 RETVAL->fh = newSVsv (path); 1441 e_fh (RETVAL) = newSVsv (path);
1437 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 1442 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
1438 if (!ix) START (stat, RETVAL); 1443 if (!ix) START (stat, RETVAL);
1439 OUTPUT: 1444 OUTPUT:
1440 RETVAL 1445 RETVAL
1441 1446
1442ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0) 1447ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1446{ 1451{
1447 if (!(ev_backend (other) & ev_embeddable_backends ())) 1452 if (!(ev_backend (other) & ev_embeddable_backends ()))
1448 croak ("passed loop is not embeddable via EV::embed,"); 1453 croak ("passed loop is not embeddable via EV::embed,");
1449 1454
1450 RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); 1455 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1451 RETVAL->fh = newSVsv (ST (1)); 1456 e_fh (RETVAL) = newSVsv (ST (1));
1452 ev_embed_set (RETVAL, other); 1457 ev_embed_set (RETVAL, other);
1453 if (!ix) START (embed, RETVAL); 1458 if (!ix) START (embed, RETVAL);
1454} 1459}
1455 OUTPUT: 1460 OUTPUT:
1456 RETVAL 1461 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines