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

Comparing EV/EV.xs (file contents):
Revision 1.154 by root, Tue Jan 11 02:31:24 2011 UTC vs.
Revision 1.166 by root, Sat Apr 6 00:05:45 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
25#define EV_USE_FLOOR 1
26#define EV_API_STATIC
22#define EV_H <ev.h> 27#define EV_H <ev.h>
23#define EV_CONFIG_H error 28#define EV_CONFIG_H error
24#include "EV/EVAPI.h" 29#include "EV/EVAPI.h"
25 30
26#define EV_SELECT_IS_WINSOCKET 0 31#define EV_SELECT_IS_WINSOCKET 0
30# define fd_mask Perl_fd_mask 35# define fd_mask Perl_fd_mask
31#endif 36#endif
32/* due to bugs in OS X we have to use libev/ explicitly here */ 37/* due to bugs in OS X we have to use libev/ explicitly here */
33#include "libev/ev.c" 38#include "libev/ev.c"
34 39
35#if !defined(_WIN32) && !defined(_MINIX) 40#if !defined _WIN32 && !defined _MINIX
36# include <pthread.h> 41# include <pthread.h>
37#endif 42#endif
38 43
39#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) 44#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop))
40#define e_flags(w) ((ev_watcher *)(w))->e_flags 45#define e_flags(w) ((ev_watcher *)(w))->e_flags
129///////////////////////////////////////////////////////////////////////////// 134/////////////////////////////////////////////////////////////////////////////
130// Event 135// Event
131 136
132static void e_cb (EV_P_ ev_watcher *w, int revents); 137static void e_cb (EV_P_ ev_watcher *w, int revents);
133 138
134void * 139static void *
135e_new (int size, SV *cb_sv, SV *loop) 140e_new (int size, SV *cb_sv, SV *loop)
136{ 141{
137 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0; 142 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0;
138 ev_watcher *w; 143 ev_watcher *w;
139 SV *self = NEWSV (0, size); 144 SV *self = NEWSV (0, size);
380 const_iv (EV_, SIGNAL) 385 const_iv (EV_, SIGNAL)
381 const_iv (EV_, CHILD) 386 const_iv (EV_, CHILD)
382 const_iv (EV_, STAT) 387 const_iv (EV_, STAT)
383 const_iv (EV_, IDLE) 388 const_iv (EV_, IDLE)
384 const_iv (EV_, PREPARE) 389 const_iv (EV_, PREPARE)
385 const_iv (EV_, CHECK) 390 /*const_iv (EV_, CHECK) needs special tretament */
386 const_iv (EV_, EMBED) 391 const_iv (EV_, EMBED)
387 const_iv (EV_, FORK) 392 const_iv (EV_, FORK)
388 const_iv (EV_, CLEANUP) 393 const_iv (EV_, CLEANUP)
389 const_iv (EV_, ASYNC) 394 const_iv (EV_, ASYNC)
390 const_iv (EV_, CUSTOM) 395 const_iv (EV_, CUSTOM)
422 const_iv (EV, UNLOOP_ONE) 427 const_iv (EV, UNLOOP_ONE)
423 const_iv (EV, UNLOOP_ALL) 428 const_iv (EV, UNLOOP_ALL)
424#endif 429#endif
425 }; 430 };
426 431
427 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 432 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
428 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 433 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
434
435 /* since this clashes with perl CHECK blocks, */
436 /* but we are interested in constants, */
437 /* and not blocks, we treat CHECK specially. */
438 {
439 /* the local $^W = 0 takes care of the warning */
440 CV *cv = newCONSTSUB (stash, "CHECK", newSViv (EV_CHECK));
441 /* now we need to re-set the gv, in case it was hijacked */
442 GvCV_set (gv_fetchpv ("EV::CHECK", GV_ADD, SVt_PVCV), cv);
443 }
429 444
430 stash_loop = gv_stashpv ("EV::Loop" , 1); 445 stash_loop = gv_stashpv ("EV::Loop" , 1);
431 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 446 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
432 stash_io = gv_stashpv ("EV::IO" , 1); 447 stash_io = gv_stashpv ("EV::IO" , 1);
433 stash_timer = gv_stashpv ("EV::Timer" , 1); 448 stash_timer = gv_stashpv ("EV::Timer" , 1);
516 evapi.invoke = ev_invoke; 531 evapi.invoke = ev_invoke;
517 532
518 sv_setiv (sv, (IV)&evapi); 533 sv_setiv (sv, (IV)&evapi);
519 SvREADONLY_on (sv); 534 SvREADONLY_on (sv);
520 } 535 }
521#if !defined(_WIN32) && !defined(_MINIX) 536#if !defined _WIN32 && !defined _MINIX
537#if __linux
538 int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
539 __register_atfork (0, 0, default_fork, 0);
540#else
522 pthread_atfork (0, 0, default_fork); 541 pthread_atfork (0, 0, default_fork);
542#endif
523#endif 543#endif
524} 544}
525 545
526SV *ev_default_loop (unsigned int flags = 0) 546SV *ev_default_loop (unsigned int flags = 0)
527 CODE: 547 CODE:
600 C_ARGS: evapi.default_loop, interval 620 C_ARGS: evapi.default_loop, interval
601 621
602void ev_set_timeout_collect_interval (NV interval) 622void ev_set_timeout_collect_interval (NV interval)
603 C_ARGS: evapi.default_loop, interval 623 C_ARGS: evapi.default_loop, interval
604 624
605void ev_run (int flags = 0) 625int ev_run (int flags = 0)
606 ALIAS: 626 ALIAS:
607 loop = 1 627 loop = 1
608 C_ARGS: evapi.default_loop, flags 628 C_ARGS: evapi.default_loop, flags
609 629
610void ev_break (int how = EVBREAK_ONE) 630void ev_break (int how = EVBREAK_ONE)
616 C_ARGS: evapi.default_loop, fd, revents 636 C_ARGS: evapi.default_loop, fd, revents
617 637
618void ev_feed_signal_event (SV *signal) 638void ev_feed_signal_event (SV *signal)
619 CODE: 639 CODE:
620{ 640{
621 Signal signum = s_signum (signal); 641 Signal signum = s_signum (signal);
622 CHECK_SIG (signal, signum); 642 CHECK_SIG (signal, signum);
623 643
624 ev_feed_signal_event (evapi.default_loop, signum); 644 ev_feed_signal_event (evapi.default_loop, signum);
625} 645}
626 646
735 ev_fork_set (RETVAL); 755 ev_fork_set (RETVAL);
736 if (!ix) START (fork, RETVAL); 756 if (!ix) START (fork, RETVAL);
737 OUTPUT: 757 OUTPUT:
738 RETVAL 758 RETVAL
739 759
760#if CLEANUP_ENABLED
761
740ev_cleanup *cleanup (SV *cb) 762ev_cleanup *cleanup (SV *cb)
741 ALIAS: 763 ALIAS:
742 cleanup_ns = 1 764 cleanup_ns = 1
743 CODE: 765 CODE:
744 RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv); 766 RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
767 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
745 ev_cleanup_set (RETVAL); 768 ev_cleanup_set (RETVAL);
746 if (!ix) START (cleanup, RETVAL); 769 if (!ix) START (cleanup, RETVAL);
747 OUTPUT: 770 OUTPUT:
748 RETVAL 771 RETVAL
772
773#endif
749 774
750ev_child *child (int pid, int trace, SV *cb) 775ev_child *child (int pid, int trace, SV *cb)
751 ALIAS: 776 ALIAS:
752 child_ns = 1 777 child_ns = 1
753 CODE: 778 CODE:
1138void DESTROY (ev_fork *w) 1163void DESTROY (ev_fork *w)
1139 CODE: 1164 CODE:
1140 STOP (fork, w); 1165 STOP (fork, w);
1141 e_destroy (w); 1166 e_destroy (w);
1142 1167
1168#if CLEANUP_ENABLED
1169
1143MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_ 1170MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1144 1171
1145void ev_cleanup_start (ev_cleanup *w) 1172void ev_cleanup_start (ev_cleanup *w)
1146 CODE: 1173 CODE:
1147 START (cleanup, w); 1174 START (cleanup, w);
1151 STOP (cleanup, w); 1178 STOP (cleanup, w);
1152 1179
1153void DESTROY (ev_cleanup *w) 1180void DESTROY (ev_cleanup *w)
1154 CODE: 1181 CODE:
1155 STOP (cleanup, w); 1182 STOP (cleanup, w);
1183 SvREFCNT_inc (w->loop); /* has been dec'ed on creation */
1156 e_destroy (w); 1184 e_destroy (w);
1157 1185
1158int keepalive (ev_watcher *w, int new_value = 0) 1186int keepalive (ev_watcher *w, SV *new_value = 0)
1159 CODE: 1187 CODE:
1160 RETVAL = 0; 1188 RETVAL = 1;
1161 OUTPUT: 1189 OUTPUT:
1162 RETVAL 1190 RETVAL
1191
1192#endif
1163 1193
1164MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 1194MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1165 1195
1166#if EV_CHILD_ENABLE 1196#if EV_CHILD_ENABLE
1167 1197
1361 OUTPUT: 1391 OUTPUT:
1362 RETVAL 1392 RETVAL
1363 1393
1364void DESTROY (struct ev_loop *loop) 1394void DESTROY (struct ev_loop *loop)
1365 CODE: 1395 CODE:
1366 /* 1. the default loop shouldn't be freed by destroying it'S pelr loop object */ 1396 /* 1. the default loop shouldn't be freed by destroying it's perl loop object */
1367 /* 2. not doing so helps avoid many global destruction bugs in perl, too */ 1397 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1368 if (loop != evapi.default_loop) 1398 if (loop != evapi.default_loop)
1369 ev_loop_destroy (loop); 1399 ev_loop_destroy (loop);
1370 1400
1371void ev_loop_fork (struct ev_loop *loop) 1401void ev_loop_fork (struct ev_loop *loop)
1394 1424
1395unsigned int ev_depth (struct ev_loop *loop) 1425unsigned int ev_depth (struct ev_loop *loop)
1396 ALIAS: 1426 ALIAS:
1397 loop_depth = 1 1427 loop_depth = 1
1398 1428
1399void ev_run (struct ev_loop *loop, int flags = 0) 1429int ev_run (struct ev_loop *loop, int flags = 0)
1400 ALIAS: 1430 ALIAS:
1401 loop = 1 1431 loop = 1
1402 1432
1403void ev_break (struct ev_loop *loop, int how = 1) 1433void ev_break (struct ev_loop *loop, int how = 1)
1404 ALIAS: 1434 ALIAS:
1413#if 0 1443#if 0
1414 1444
1415void ev_feed_signal_event (struct ev_loop *loop, SV *signal) 1445void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1416 CODE: 1446 CODE:
1417{ 1447{
1418 Signal signum = s_signum (signal); 1448 Signal signum = s_signum (signal);
1419 CHECK_SIG (signal, signum); 1449 CHECK_SIG (signal, signum);
1420 1450
1421 ev_feed_signal_event (loop, signum); 1451 ev_feed_signal_event (loop, signum);
1422} 1452}
1423 1453
1456 periodic_ns = 1 1486 periodic_ns = 1
1457 INIT: 1487 INIT:
1458 CHECK_REPEAT (interval); 1488 CHECK_REPEAT (interval);
1459 CODE: 1489 CODE:
1460{ 1490{
1461 ev_periodic *w; 1491 ev_periodic *w;
1462 w = e_new (sizeof (ev_periodic), cb, ST (0)); 1492 w = e_new (sizeof (ev_periodic), cb, ST (0));
1463 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 1493 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1464 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); 1494 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
1465 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 1495 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1466 if (!ix) START (periodic, w); 1496 if (!ix) START (periodic, w);
1471ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) 1501ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1472 ALIAS: 1502 ALIAS:
1473 signal_ns = 1 1503 signal_ns = 1
1474 CODE: 1504 CODE:
1475{ 1505{
1476 Signal signum = s_signum (signal); 1506 Signal signum = s_signum (signal);
1477 CHECK_SIG (signal, signum); 1507 CHECK_SIG (signal, signum);
1478 1508
1479 RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); 1509 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1480 ev_signal_set (RETVAL, signum); 1510 ev_signal_set (RETVAL, signum);
1481 if (!ix) START_SIGNAL (RETVAL); 1511 if (!ix) START_SIGNAL (RETVAL);
1521 ev_fork_set (RETVAL); 1551 ev_fork_set (RETVAL);
1522 if (!ix) START (fork, RETVAL); 1552 if (!ix) START (fork, RETVAL);
1523 OUTPUT: 1553 OUTPUT:
1524 RETVAL 1554 RETVAL
1525 1555
1556#if CLEANUP_ENABLED
1557
1526ev_cleanup *cleanup (struct ev_loop *loop, SV *cb) 1558ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1527 ALIAS: 1559 ALIAS:
1528 cleanup_ns = 1 1560 cleanup_ns = 1
1529 CODE: 1561 CODE:
1530 RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0)); 1562 RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1563 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
1531 ev_cleanup_set (RETVAL); 1564 ev_cleanup_set (RETVAL);
1532 if (!ix) START (cleanup, RETVAL); 1565 if (!ix) START (cleanup, RETVAL);
1533 OUTPUT: 1566 OUTPUT:
1534 RETVAL 1567 RETVAL
1568
1569#endif
1535 1570
1536ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) 1571ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1537 ALIAS: 1572 ALIAS:
1538 child_ns = 1 1573 child_ns = 1
1539 CODE: 1574 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines