ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.116 by root, Thu Nov 15 09:19:42 2007 UTC vs.
Revision 1.126 by root, Sun Nov 18 01:25:23 2007 UTC

41# define EV_USE_MONOTONIC 1 41# define EV_USE_MONOTONIC 1
42# endif 42# endif
43# ifndef EV_USE_REALTIME 43# ifndef EV_USE_REALTIME
44# define EV_USE_REALTIME 1 44# define EV_USE_REALTIME 1
45# endif 45# endif
46# else
47# ifndef EV_USE_MONOTONIC
48# define EV_USE_MONOTONIC 0
49# endif
50# ifndef EV_USE_REALTIME
51# define EV_USE_REALTIME 0
52# endif
46# endif 53# endif
47 54
48# if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) 55# if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT)
49# define EV_USE_SELECT 1 56# define EV_USE_SELECT 1
57# else
58# define EV_USE_SELECT 0
50# endif 59# endif
51 60
52# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) 61# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL)
53# define EV_USE_POLL 1 62# define EV_USE_POLL 1
63# else
64# define EV_USE_POLL 0
54# endif 65# endif
55 66
56# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) 67# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL)
57# define EV_USE_EPOLL 1 68# define EV_USE_EPOLL 1
69# else
70# define EV_USE_EPOLL 0
58# endif 71# endif
59 72
60# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) 73# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE)
61# define EV_USE_KQUEUE 1 74# define EV_USE_KQUEUE 1
75# else
76# define EV_USE_KQUEUE 0
77# endif
78
79# if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT)
80# define EV_USE_PORT 1
81# else
82# define EV_USE_PORT 0
62# endif 83# endif
63 84
64#endif 85#endif
65 86
66#include <math.h> 87#include <math.h>
90#endif 111#endif
91 112
92/**/ 113/**/
93 114
94#ifndef EV_USE_MONOTONIC 115#ifndef EV_USE_MONOTONIC
95# define EV_USE_MONOTONIC 1 116# define EV_USE_MONOTONIC 0
117#endif
118
119#ifndef EV_USE_REALTIME
120# define EV_USE_REALTIME 0
96#endif 121#endif
97 122
98#ifndef EV_USE_SELECT 123#ifndef EV_USE_SELECT
99# define EV_USE_SELECT 1 124# define EV_USE_SELECT 1
100# define EV_SELECT_USE_FD_SET 1
101#endif 125#endif
102 126
103#ifndef EV_USE_POLL 127#ifndef EV_USE_POLL
104# ifdef _WIN32 128# ifdef _WIN32
105# define EV_USE_POLL 0 129# define EV_USE_POLL 0
114 138
115#ifndef EV_USE_KQUEUE 139#ifndef EV_USE_KQUEUE
116# define EV_USE_KQUEUE 0 140# define EV_USE_KQUEUE 0
117#endif 141#endif
118 142
119#ifndef EV_USE_REALTIME 143#ifndef EV_USE_PORT
120# define EV_USE_REALTIME 1 144# define EV_USE_PORT 0
121#endif 145#endif
122 146
123/**/ 147/**/
124 148
125/* darwin simply cannot be helped */ 149/* darwin simply cannot be helped */
143#endif 167#endif
144 168
145/**/ 169/**/
146 170
147#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 171#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
148#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 172#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
149#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 173#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
150/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 174/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
151 175
152#ifdef EV_H 176#ifdef EV_H
153# include EV_H 177# include EV_H
154#else 178#else
155# include "ev.h" 179# include "ev.h"
156#endif 180#endif
157 181
158#if __GNUC__ >= 3 182#if __GNUC__ >= 3
159# define expect(expr,value) __builtin_expect ((expr),(value)) 183# define expect(expr,value) __builtin_expect ((expr),(value))
160# define inline inline 184# define inline static inline
161#else 185#else
162# define expect(expr,value) (expr) 186# define expect(expr,value) (expr)
163# define inline static 187# define inline static
164#endif 188#endif
165 189
359void 383void
360ev_feed_event (EV_P_ void *w, int revents) 384ev_feed_event (EV_P_ void *w, int revents)
361{ 385{
362 W w_ = (W)w; 386 W w_ = (W)w;
363 387
364 if (w_->pending) 388 if (expect_false (w_->pending))
365 { 389 {
366 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 390 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
367 return; 391 return;
368 } 392 }
369 393
403 fd_event (EV_A_ fd, revents); 427 fd_event (EV_A_ fd, revents);
404} 428}
405 429
406/*****************************************************************************/ 430/*****************************************************************************/
407 431
408static void 432inline void
409fd_reify (EV_P) 433fd_reify (EV_P)
410{ 434{
411 int i; 435 int i;
412 436
413 for (i = 0; i < fdchangecnt; ++i) 437 for (i = 0; i < fdchangecnt; ++i)
440} 464}
441 465
442static void 466static void
443fd_change (EV_P_ int fd) 467fd_change (EV_P_ int fd)
444{ 468{
445 if (anfds [fd].reify) 469 if (expect_false (anfds [fd].reify))
446 return; 470 return;
447 471
448 anfds [fd].reify = 1; 472 anfds [fd].reify = 1;
449 473
450 ++fdchangecnt; 474 ++fdchangecnt;
462 ev_io_stop (EV_A_ w); 486 ev_io_stop (EV_A_ w);
463 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 487 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
464 } 488 }
465} 489}
466 490
467static int 491inline int
468fd_valid (int fd) 492fd_valid (int fd)
469{ 493{
470#ifdef _WIN32 494#ifdef _WIN32
471 return _get_osfhandle (fd) != -1; 495 return _get_osfhandle (fd) != -1;
472#else 496#else
641 for (signum = signalmax; signum--; ) 665 for (signum = signalmax; signum--; )
642 if (signals [signum].gotsig) 666 if (signals [signum].gotsig)
643 ev_feed_signal_event (EV_A_ signum + 1); 667 ev_feed_signal_event (EV_A_ signum + 1);
644} 668}
645 669
646inline void 670static void
647fd_intern (int fd) 671fd_intern (int fd)
648{ 672{
649#ifdef _WIN32 673#ifdef _WIN32
650 int arg = 1; 674 int arg = 1;
651 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 675 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
710 734
711#endif 735#endif
712 736
713/*****************************************************************************/ 737/*****************************************************************************/
714 738
739#if EV_USE_PORT
740# include "ev_port.c"
741#endif
715#if EV_USE_KQUEUE 742#if EV_USE_KQUEUE
716# include "ev_kqueue.c" 743# include "ev_kqueue.c"
717#endif 744#endif
718#if EV_USE_EPOLL 745#if EV_USE_EPOLL
719# include "ev_epoll.c" 746# include "ev_epoll.c"
778 805
779 if (!(flags & 0x0000ffff)) 806 if (!(flags & 0x0000ffff))
780 flags |= 0x0000ffff; 807 flags |= 0x0000ffff;
781 808
782 method = 0; 809 method = 0;
810#if EV_USE_PORT
811 if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags);
812#endif
783#if EV_USE_KQUEUE 813#if EV_USE_KQUEUE
784 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); 814 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags);
785#endif 815#endif
786#if EV_USE_EPOLL 816#if EV_USE_EPOLL
787 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); 817 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags);
796 ev_init (&sigev, sigcb); 826 ev_init (&sigev, sigcb);
797 ev_set_priority (&sigev, EV_MAXPRI); 827 ev_set_priority (&sigev, EV_MAXPRI);
798 } 828 }
799} 829}
800 830
801void 831static void
802loop_destroy (EV_P) 832loop_destroy (EV_P)
803{ 833{
804 int i; 834 int i;
805 835
836#if EV_USE_PORT
837 if (method == EVMETHOD_PORT ) port_destroy (EV_A);
838#endif
806#if EV_USE_KQUEUE 839#if EV_USE_KQUEUE
807 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 840 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
808#endif 841#endif
809#if EV_USE_EPOLL 842#if EV_USE_EPOLL
810 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 843 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
833} 866}
834 867
835static void 868static void
836loop_fork (EV_P) 869loop_fork (EV_P)
837{ 870{
871#if EV_USE_PORT
872 if (method == EVMETHOD_PORT ) port_fork (EV_A);
873#endif
874#if EV_USE_KQUEUE
875 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
876#endif
838#if EV_USE_EPOLL 877#if EV_USE_EPOLL
839 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 878 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
840#endif
841#if EV_USE_KQUEUE
842 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
843#endif 879#endif
844 880
845 if (ev_is_active (&sigev)) 881 if (ev_is_active (&sigev))
846 { 882 {
847 /* default loop */ 883 /* default loop */
891 927
892#endif 928#endif
893 929
894#if EV_MULTIPLICITY 930#if EV_MULTIPLICITY
895struct ev_loop * 931struct ev_loop *
896ev_default_loop_ (unsigned int flags) 932ev_default_loop_init (unsigned int flags)
897#else 933#else
898int 934int
899ev_default_loop (unsigned int flags) 935ev_default_loop (unsigned int flags)
900#endif 936#endif
901{ 937{
906 if (!ev_default_loop_ptr) 942 if (!ev_default_loop_ptr)
907 { 943 {
908#if EV_MULTIPLICITY 944#if EV_MULTIPLICITY
909 struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; 945 struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct;
910#else 946#else
911 ev_default_default_loop_ptr = 1; 947 ev_default_loop_ptr = 1;
912#endif 948#endif
913 949
914 loop_init (EV_A_ flags); 950 loop_init (EV_A_ flags);
915 951
916 if (ev_method (EV_A)) 952 if (ev_method (EV_A))
975 return 1; 1011 return 1;
976 1012
977 return 0; 1013 return 0;
978} 1014}
979 1015
980static void 1016inline void
981call_pending (EV_P) 1017call_pending (EV_P)
982{ 1018{
983 int pri; 1019 int pri;
984 1020
985 for (pri = NUMPRI; pri--; ) 1021 for (pri = NUMPRI; pri--; )
986 while (pendingcnt [pri]) 1022 while (pendingcnt [pri])
987 { 1023 {
988 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 1024 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
989 1025
990 if (p->w) 1026 if (expect_true (p->w))
991 { 1027 {
992 p->w->pending = 0; 1028 p->w->pending = 0;
993 EV_CB_INVOKE (p->w, p->events); 1029 EV_CB_INVOKE (p->w, p->events);
994 } 1030 }
995 } 1031 }
996} 1032}
997 1033
998static void 1034inline void
999timers_reify (EV_P) 1035timers_reify (EV_P)
1000{ 1036{
1001 while (timercnt && ((WT)timers [0])->at <= mn_now) 1037 while (timercnt && ((WT)timers [0])->at <= mn_now)
1002 { 1038 {
1003 struct ev_timer *w = timers [0]; 1039 struct ev_timer *w = timers [0];
1021 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1057 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1022 } 1058 }
1023} 1059}
1024 1060
1025#if EV_PERIODICS 1061#if EV_PERIODICS
1026static void 1062inline void
1027periodics_reify (EV_P) 1063periodics_reify (EV_P)
1028{ 1064{
1029 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1065 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1030 { 1066 {
1031 struct ev_periodic *w = periodics [0]; 1067 struct ev_periodic *w = periodics [0];
1090 ev_rt_now = ev_time (); 1126 ev_rt_now = ev_time ();
1091 return 1; 1127 return 1;
1092 } 1128 }
1093} 1129}
1094 1130
1095static void 1131inline void
1096time_update (EV_P) 1132time_update (EV_P)
1097{ 1133{
1098 int i; 1134 int i;
1099 1135
1100#if EV_USE_MONOTONIC 1136#if EV_USE_MONOTONIC
1211 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; 1247 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge;
1212 if (block > to) block = to; 1248 if (block > to) block = to;
1213 } 1249 }
1214#endif 1250#endif
1215 1251
1216 if (block < 0.) block = 0.; 1252 if (expect_false (block < 0.)) block = 0.;
1217 } 1253 }
1218 1254
1219 method_poll (EV_A_ block); 1255 method_poll (EV_A_ block);
1220 1256
1221 /* update ev_rt_now, do magic */ 1257 /* update ev_rt_now, do magic */
1230 /* queue idle watchers unless io or timers are pending */ 1266 /* queue idle watchers unless io or timers are pending */
1231 if (idlecnt && !any_pending (EV_A)) 1267 if (idlecnt && !any_pending (EV_A))
1232 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1268 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1233 1269
1234 /* queue check watchers, to be executed first */ 1270 /* queue check watchers, to be executed first */
1235 if (checkcnt) 1271 if (expect_false (checkcnt))
1236 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1272 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1237 1273
1238 call_pending (EV_A); 1274 call_pending (EV_A);
1239 1275
1240 if (loop_done) 1276 if (expect_false (loop_done))
1241 break; 1277 break;
1242 } 1278 }
1243 1279
1244 if (loop_done != 2) 1280 if (loop_done != 2)
1245 loop_done = 0; 1281 loop_done = 0;
1307void 1343void
1308ev_io_start (EV_P_ struct ev_io *w) 1344ev_io_start (EV_P_ struct ev_io *w)
1309{ 1345{
1310 int fd = w->fd; 1346 int fd = w->fd;
1311 1347
1312 if (ev_is_active (w)) 1348 if (expect_false (ev_is_active (w)))
1313 return; 1349 return;
1314 1350
1315 assert (("ev_io_start called with negative fd", fd >= 0)); 1351 assert (("ev_io_start called with negative fd", fd >= 0));
1316 1352
1317 ev_start (EV_A_ (W)w, 1); 1353 ev_start (EV_A_ (W)w, 1);
1323 1359
1324void 1360void
1325ev_io_stop (EV_P_ struct ev_io *w) 1361ev_io_stop (EV_P_ struct ev_io *w)
1326{ 1362{
1327 ev_clear_pending (EV_A_ (W)w); 1363 ev_clear_pending (EV_A_ (W)w);
1328 if (!ev_is_active (w)) 1364 if (expect_false (!ev_is_active (w)))
1329 return; 1365 return;
1330 1366
1331 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 1367 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
1332 1368
1333 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 1369 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
1337} 1373}
1338 1374
1339void 1375void
1340ev_timer_start (EV_P_ struct ev_timer *w) 1376ev_timer_start (EV_P_ struct ev_timer *w)
1341{ 1377{
1342 if (ev_is_active (w)) 1378 if (expect_false (ev_is_active (w)))
1343 return; 1379 return;
1344 1380
1345 ((WT)w)->at += mn_now; 1381 ((WT)w)->at += mn_now;
1346 1382
1347 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1383 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1356 1392
1357void 1393void
1358ev_timer_stop (EV_P_ struct ev_timer *w) 1394ev_timer_stop (EV_P_ struct ev_timer *w)
1359{ 1395{
1360 ev_clear_pending (EV_A_ (W)w); 1396 ev_clear_pending (EV_A_ (W)w);
1361 if (!ev_is_active (w)) 1397 if (expect_false (!ev_is_active (w)))
1362 return; 1398 return;
1363 1399
1364 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1400 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1365 1401
1366 if (((W)w)->active < timercnt--) 1402 if (expect_true (((W)w)->active < timercnt--))
1367 { 1403 {
1368 timers [((W)w)->active - 1] = timers [timercnt]; 1404 timers [((W)w)->active - 1] = timers [timercnt];
1369 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1405 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1370 } 1406 }
1371 1407
1396 1432
1397#if EV_PERIODICS 1433#if EV_PERIODICS
1398void 1434void
1399ev_periodic_start (EV_P_ struct ev_periodic *w) 1435ev_periodic_start (EV_P_ struct ev_periodic *w)
1400{ 1436{
1401 if (ev_is_active (w)) 1437 if (expect_false (ev_is_active (w)))
1402 return; 1438 return;
1403 1439
1404 if (w->reschedule_cb) 1440 if (w->reschedule_cb)
1405 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1441 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1406 else if (w->interval) 1442 else if (w->interval)
1420 1456
1421void 1457void
1422ev_periodic_stop (EV_P_ struct ev_periodic *w) 1458ev_periodic_stop (EV_P_ struct ev_periodic *w)
1423{ 1459{
1424 ev_clear_pending (EV_A_ (W)w); 1460 ev_clear_pending (EV_A_ (W)w);
1425 if (!ev_is_active (w)) 1461 if (expect_false (!ev_is_active (w)))
1426 return; 1462 return;
1427 1463
1428 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1464 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1429 1465
1430 if (((W)w)->active < periodiccnt--) 1466 if (expect_true (((W)w)->active < periodiccnt--))
1431 { 1467 {
1432 periodics [((W)w)->active - 1] = periodics [periodiccnt]; 1468 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1433 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); 1469 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1434 } 1470 }
1435 1471
1446#endif 1482#endif
1447 1483
1448void 1484void
1449ev_idle_start (EV_P_ struct ev_idle *w) 1485ev_idle_start (EV_P_ struct ev_idle *w)
1450{ 1486{
1451 if (ev_is_active (w)) 1487 if (expect_false (ev_is_active (w)))
1452 return; 1488 return;
1453 1489
1454 ev_start (EV_A_ (W)w, ++idlecnt); 1490 ev_start (EV_A_ (W)w, ++idlecnt);
1455 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); 1491 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1456 idles [idlecnt - 1] = w; 1492 idles [idlecnt - 1] = w;
1458 1494
1459void 1495void
1460ev_idle_stop (EV_P_ struct ev_idle *w) 1496ev_idle_stop (EV_P_ struct ev_idle *w)
1461{ 1497{
1462 ev_clear_pending (EV_A_ (W)w); 1498 ev_clear_pending (EV_A_ (W)w);
1463 if (!ev_is_active (w)) 1499 if (expect_false (!ev_is_active (w)))
1464 return; 1500 return;
1465 1501
1466 idles [((W)w)->active - 1] = idles [--idlecnt]; 1502 idles [((W)w)->active - 1] = idles [--idlecnt];
1467 ev_stop (EV_A_ (W)w); 1503 ev_stop (EV_A_ (W)w);
1468} 1504}
1469 1505
1470void 1506void
1471ev_prepare_start (EV_P_ struct ev_prepare *w) 1507ev_prepare_start (EV_P_ struct ev_prepare *w)
1472{ 1508{
1473 if (ev_is_active (w)) 1509 if (expect_false (ev_is_active (w)))
1474 return; 1510 return;
1475 1511
1476 ev_start (EV_A_ (W)w, ++preparecnt); 1512 ev_start (EV_A_ (W)w, ++preparecnt);
1477 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 1513 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1478 prepares [preparecnt - 1] = w; 1514 prepares [preparecnt - 1] = w;
1480 1516
1481void 1517void
1482ev_prepare_stop (EV_P_ struct ev_prepare *w) 1518ev_prepare_stop (EV_P_ struct ev_prepare *w)
1483{ 1519{
1484 ev_clear_pending (EV_A_ (W)w); 1520 ev_clear_pending (EV_A_ (W)w);
1485 if (!ev_is_active (w)) 1521 if (expect_false (!ev_is_active (w)))
1486 return; 1522 return;
1487 1523
1488 prepares [((W)w)->active - 1] = prepares [--preparecnt]; 1524 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1489 ev_stop (EV_A_ (W)w); 1525 ev_stop (EV_A_ (W)w);
1490} 1526}
1491 1527
1492void 1528void
1493ev_check_start (EV_P_ struct ev_check *w) 1529ev_check_start (EV_P_ struct ev_check *w)
1494{ 1530{
1495 if (ev_is_active (w)) 1531 if (expect_false (ev_is_active (w)))
1496 return; 1532 return;
1497 1533
1498 ev_start (EV_A_ (W)w, ++checkcnt); 1534 ev_start (EV_A_ (W)w, ++checkcnt);
1499 array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); 1535 array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2);
1500 checks [checkcnt - 1] = w; 1536 checks [checkcnt - 1] = w;
1502 1538
1503void 1539void
1504ev_check_stop (EV_P_ struct ev_check *w) 1540ev_check_stop (EV_P_ struct ev_check *w)
1505{ 1541{
1506 ev_clear_pending (EV_A_ (W)w); 1542 ev_clear_pending (EV_A_ (W)w);
1507 if (!ev_is_active (w)) 1543 if (expect_false (!ev_is_active (w)))
1508 return; 1544 return;
1509 1545
1510 checks [((W)w)->active - 1] = checks [--checkcnt]; 1546 checks [((W)w)->active - 1] = checks [--checkcnt];
1511 ev_stop (EV_A_ (W)w); 1547 ev_stop (EV_A_ (W)w);
1512} 1548}
1519ev_signal_start (EV_P_ struct ev_signal *w) 1555ev_signal_start (EV_P_ struct ev_signal *w)
1520{ 1556{
1521#if EV_MULTIPLICITY 1557#if EV_MULTIPLICITY
1522 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1558 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1523#endif 1559#endif
1524 if (ev_is_active (w)) 1560 if (expect_false (ev_is_active (w)))
1525 return; 1561 return;
1526 1562
1527 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1563 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1528 1564
1529 ev_start (EV_A_ (W)w, 1); 1565 ev_start (EV_A_ (W)w, 1);
1546 1582
1547void 1583void
1548ev_signal_stop (EV_P_ struct ev_signal *w) 1584ev_signal_stop (EV_P_ struct ev_signal *w)
1549{ 1585{
1550 ev_clear_pending (EV_A_ (W)w); 1586 ev_clear_pending (EV_A_ (W)w);
1551 if (!ev_is_active (w)) 1587 if (expect_false (!ev_is_active (w)))
1552 return; 1588 return;
1553 1589
1554 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); 1590 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
1555 ev_stop (EV_A_ (W)w); 1591 ev_stop (EV_A_ (W)w);
1556 1592
1562ev_child_start (EV_P_ struct ev_child *w) 1598ev_child_start (EV_P_ struct ev_child *w)
1563{ 1599{
1564#if EV_MULTIPLICITY 1600#if EV_MULTIPLICITY
1565 assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1601 assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1566#endif 1602#endif
1567 if (ev_is_active (w)) 1603 if (expect_false (ev_is_active (w)))
1568 return; 1604 return;
1569 1605
1570 ev_start (EV_A_ (W)w, 1); 1606 ev_start (EV_A_ (W)w, 1);
1571 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1607 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1572} 1608}
1573 1609
1574void 1610void
1575ev_child_stop (EV_P_ struct ev_child *w) 1611ev_child_stop (EV_P_ struct ev_child *w)
1576{ 1612{
1577 ev_clear_pending (EV_A_ (W)w); 1613 ev_clear_pending (EV_A_ (W)w);
1578 if (!ev_is_active (w)) 1614 if (expect_false (!ev_is_active (w)))
1579 return; 1615 return;
1580 1616
1581 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1617 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1582 ev_stop (EV_A_ (W)w); 1618 ev_stop (EV_A_ (W)w);
1583} 1619}
1620void 1656void
1621ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1657ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1622{ 1658{
1623 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 1659 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
1624 1660
1625 if (!once) 1661 if (expect_false (!once))
1662 {
1626 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1663 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1627 else 1664 return;
1628 { 1665 }
1666
1629 once->cb = cb; 1667 once->cb = cb;
1630 once->arg = arg; 1668 once->arg = arg;
1631 1669
1632 ev_init (&once->io, once_cb_io); 1670 ev_init (&once->io, once_cb_io);
1633 if (fd >= 0) 1671 if (fd >= 0)
1634 { 1672 {
1635 ev_io_set (&once->io, fd, events); 1673 ev_io_set (&once->io, fd, events);
1636 ev_io_start (EV_A_ &once->io); 1674 ev_io_start (EV_A_ &once->io);
1637 } 1675 }
1638 1676
1639 ev_init (&once->to, once_cb_to); 1677 ev_init (&once->to, once_cb_to);
1640 if (timeout >= 0.) 1678 if (timeout >= 0.)
1641 { 1679 {
1642 ev_timer_set (&once->to, timeout, 0.); 1680 ev_timer_set (&once->to, timeout, 0.);
1643 ev_timer_start (EV_A_ &once->to); 1681 ev_timer_start (EV_A_ &once->to);
1644 }
1645 } 1682 }
1646} 1683}
1647 1684
1648#ifdef __cplusplus 1685#ifdef __cplusplus
1649} 1686}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines