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

Comparing libev/ev.c (file contents):
Revision 1.120 by root, Fri Nov 16 01:54:25 2007 UTC vs.
Revision 1.127 by root, Sun Nov 18 02:17:57 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# ifndef EV_USE_SELECT
56# if HAVE_SELECT && HAVE_SYS_SELECT_H
49# define EV_USE_SELECT 1 57# define EV_USE_SELECT 1
58# else
59# define EV_USE_SELECT 0
60# endif
50# endif 61# endif
51 62
52# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) 63# ifndef EV_USE_POLL
64# if HAVE_POLL && HAVE_POLL_H
53# define EV_USE_POLL 1 65# define EV_USE_POLL 1
66# else
67# define EV_USE_POLL 0
68# endif
54# endif 69# endif
55 70
56# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) 71# ifndef EV_USE_EPOLL
72# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
57# define EV_USE_EPOLL 1 73# define EV_USE_EPOLL 1
74# else
75# define EV_USE_EPOLL 0
76# endif
58# endif 77# endif
59 78
79# ifndef EV_USE_KQUEUE
60# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) 80# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H
61# define EV_USE_KQUEUE 1 81# define EV_USE_KQUEUE 1
82# else
83# define EV_USE_KQUEUE 0
84# endif
62# endif 85# endif
63 86
64# if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT) 87# ifndef EV_USE_PORT
88# if HAVE_PORT_H && HAVE_PORT_CREATE
65# define EV_USE_PORT 1 89# define EV_USE_PORT 1
90# else
91# define EV_USE_PORT 0
92# endif
66# endif 93# endif
67 94
68#endif 95#endif
69 96
70#include <math.h> 97#include <math.h>
94#endif 121#endif
95 122
96/**/ 123/**/
97 124
98#ifndef EV_USE_MONOTONIC 125#ifndef EV_USE_MONOTONIC
99# define EV_USE_MONOTONIC 1 126# define EV_USE_MONOTONIC 0
100#endif 127#endif
101 128
102#ifndef EV_USE_REALTIME 129#ifndef EV_USE_REALTIME
103# define EV_USE_REALTIME 1 130# define EV_USE_REALTIME 0
104#endif 131#endif
105 132
106#ifndef EV_USE_SELECT 133#ifndef EV_USE_SELECT
107# define EV_USE_SELECT 1 134# define EV_USE_SELECT 1
108# define EV_SELECT_USE_FD_SET 1
109#endif 135#endif
110 136
111#ifndef EV_USE_POLL 137#ifndef EV_USE_POLL
112# ifdef _WIN32 138# ifdef _WIN32
113# define EV_USE_POLL 0 139# define EV_USE_POLL 0
163# include "ev.h" 189# include "ev.h"
164#endif 190#endif
165 191
166#if __GNUC__ >= 3 192#if __GNUC__ >= 3
167# define expect(expr,value) __builtin_expect ((expr),(value)) 193# define expect(expr,value) __builtin_expect ((expr),(value))
168# define inline inline 194# define inline static inline
169#else 195#else
170# define expect(expr,value) (expr) 196# define expect(expr,value) (expr)
171# define inline static 197# define inline static
172#endif 198#endif
173 199
367void 393void
368ev_feed_event (EV_P_ void *w, int revents) 394ev_feed_event (EV_P_ void *w, int revents)
369{ 395{
370 W w_ = (W)w; 396 W w_ = (W)w;
371 397
372 if (w_->pending) 398 if (expect_false (w_->pending))
373 { 399 {
374 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 400 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
375 return; 401 return;
376 } 402 }
377 403
411 fd_event (EV_A_ fd, revents); 437 fd_event (EV_A_ fd, revents);
412} 438}
413 439
414/*****************************************************************************/ 440/*****************************************************************************/
415 441
416static void 442inline void
417fd_reify (EV_P) 443fd_reify (EV_P)
418{ 444{
419 int i; 445 int i;
420 446
421 for (i = 0; i < fdchangecnt; ++i) 447 for (i = 0; i < fdchangecnt; ++i)
448} 474}
449 475
450static void 476static void
451fd_change (EV_P_ int fd) 477fd_change (EV_P_ int fd)
452{ 478{
453 if (anfds [fd].reify) 479 if (expect_false (anfds [fd].reify))
454 return; 480 return;
455 481
456 anfds [fd].reify = 1; 482 anfds [fd].reify = 1;
457 483
458 ++fdchangecnt; 484 ++fdchangecnt;
470 ev_io_stop (EV_A_ w); 496 ev_io_stop (EV_A_ w);
471 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 497 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
472 } 498 }
473} 499}
474 500
475static int 501inline int
476fd_valid (int fd) 502fd_valid (int fd)
477{ 503{
478#ifdef _WIN32 504#ifdef _WIN32
479 return _get_osfhandle (fd) != -1; 505 return _get_osfhandle (fd) != -1;
480#else 506#else
649 for (signum = signalmax; signum--; ) 675 for (signum = signalmax; signum--; )
650 if (signals [signum].gotsig) 676 if (signals [signum].gotsig)
651 ev_feed_signal_event (EV_A_ signum + 1); 677 ev_feed_signal_event (EV_A_ signum + 1);
652} 678}
653 679
654inline void 680static void
655fd_intern (int fd) 681fd_intern (int fd)
656{ 682{
657#ifdef _WIN32 683#ifdef _WIN32
658 int arg = 1; 684 int arg = 1;
659 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 685 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
810 ev_init (&sigev, sigcb); 836 ev_init (&sigev, sigcb);
811 ev_set_priority (&sigev, EV_MAXPRI); 837 ev_set_priority (&sigev, EV_MAXPRI);
812 } 838 }
813} 839}
814 840
815void 841static void
816loop_destroy (EV_P) 842loop_destroy (EV_P)
817{ 843{
818 int i; 844 int i;
819 845
820#if EV_USE_PORT 846#if EV_USE_PORT
911 937
912#endif 938#endif
913 939
914#if EV_MULTIPLICITY 940#if EV_MULTIPLICITY
915struct ev_loop * 941struct ev_loop *
916ev_default_loop_ (unsigned int flags) 942ev_default_loop_init (unsigned int flags)
917#else 943#else
918int 944int
919ev_default_loop (unsigned int flags) 945ev_default_loop (unsigned int flags)
920#endif 946#endif
921{ 947{
995 return 1; 1021 return 1;
996 1022
997 return 0; 1023 return 0;
998} 1024}
999 1025
1000static void 1026inline void
1001call_pending (EV_P) 1027call_pending (EV_P)
1002{ 1028{
1003 int pri; 1029 int pri;
1004 1030
1005 for (pri = NUMPRI; pri--; ) 1031 for (pri = NUMPRI; pri--; )
1006 while (pendingcnt [pri]) 1032 while (pendingcnt [pri])
1007 { 1033 {
1008 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 1034 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
1009 1035
1010 if (p->w) 1036 if (expect_true (p->w))
1011 { 1037 {
1012 p->w->pending = 0; 1038 p->w->pending = 0;
1013 EV_CB_INVOKE (p->w, p->events); 1039 EV_CB_INVOKE (p->w, p->events);
1014 } 1040 }
1015 } 1041 }
1016} 1042}
1017 1043
1018static void 1044inline void
1019timers_reify (EV_P) 1045timers_reify (EV_P)
1020{ 1046{
1021 while (timercnt && ((WT)timers [0])->at <= mn_now) 1047 while (timercnt && ((WT)timers [0])->at <= mn_now)
1022 { 1048 {
1023 struct ev_timer *w = timers [0]; 1049 struct ev_timer *w = timers [0];
1041 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1067 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1042 } 1068 }
1043} 1069}
1044 1070
1045#if EV_PERIODICS 1071#if EV_PERIODICS
1046static void 1072inline void
1047periodics_reify (EV_P) 1073periodics_reify (EV_P)
1048{ 1074{
1049 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1075 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1050 { 1076 {
1051 struct ev_periodic *w = periodics [0]; 1077 struct ev_periodic *w = periodics [0];
1110 ev_rt_now = ev_time (); 1136 ev_rt_now = ev_time ();
1111 return 1; 1137 return 1;
1112 } 1138 }
1113} 1139}
1114 1140
1115static void 1141inline void
1116time_update (EV_P) 1142time_update (EV_P)
1117{ 1143{
1118 int i; 1144 int i;
1119 1145
1120#if EV_USE_MONOTONIC 1146#if EV_USE_MONOTONIC
1231 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; 1257 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge;
1232 if (block > to) block = to; 1258 if (block > to) block = to;
1233 } 1259 }
1234#endif 1260#endif
1235 1261
1236 if (block < 0.) block = 0.; 1262 if (expect_false (block < 0.)) block = 0.;
1237 } 1263 }
1238 1264
1239 method_poll (EV_A_ block); 1265 method_poll (EV_A_ block);
1240 1266
1241 /* update ev_rt_now, do magic */ 1267 /* update ev_rt_now, do magic */
1250 /* queue idle watchers unless io or timers are pending */ 1276 /* queue idle watchers unless io or timers are pending */
1251 if (idlecnt && !any_pending (EV_A)) 1277 if (idlecnt && !any_pending (EV_A))
1252 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1278 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1253 1279
1254 /* queue check watchers, to be executed first */ 1280 /* queue check watchers, to be executed first */
1255 if (checkcnt) 1281 if (expect_false (checkcnt))
1256 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1282 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1257 1283
1258 call_pending (EV_A); 1284 call_pending (EV_A);
1259 1285
1260 if (loop_done) 1286 if (expect_false (loop_done))
1261 break; 1287 break;
1262 } 1288 }
1263 1289
1264 if (loop_done != 2) 1290 if (loop_done != 2)
1265 loop_done = 0; 1291 loop_done = 0;
1327void 1353void
1328ev_io_start (EV_P_ struct ev_io *w) 1354ev_io_start (EV_P_ struct ev_io *w)
1329{ 1355{
1330 int fd = w->fd; 1356 int fd = w->fd;
1331 1357
1332 if (ev_is_active (w)) 1358 if (expect_false (ev_is_active (w)))
1333 return; 1359 return;
1334 1360
1335 assert (("ev_io_start called with negative fd", fd >= 0)); 1361 assert (("ev_io_start called with negative fd", fd >= 0));
1336 1362
1337 ev_start (EV_A_ (W)w, 1); 1363 ev_start (EV_A_ (W)w, 1);
1343 1369
1344void 1370void
1345ev_io_stop (EV_P_ struct ev_io *w) 1371ev_io_stop (EV_P_ struct ev_io *w)
1346{ 1372{
1347 ev_clear_pending (EV_A_ (W)w); 1373 ev_clear_pending (EV_A_ (W)w);
1348 if (!ev_is_active (w)) 1374 if (expect_false (!ev_is_active (w)))
1349 return; 1375 return;
1350 1376
1351 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 1377 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
1352 1378
1353 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 1379 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
1357} 1383}
1358 1384
1359void 1385void
1360ev_timer_start (EV_P_ struct ev_timer *w) 1386ev_timer_start (EV_P_ struct ev_timer *w)
1361{ 1387{
1362 if (ev_is_active (w)) 1388 if (expect_false (ev_is_active (w)))
1363 return; 1389 return;
1364 1390
1365 ((WT)w)->at += mn_now; 1391 ((WT)w)->at += mn_now;
1366 1392
1367 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1393 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1376 1402
1377void 1403void
1378ev_timer_stop (EV_P_ struct ev_timer *w) 1404ev_timer_stop (EV_P_ struct ev_timer *w)
1379{ 1405{
1380 ev_clear_pending (EV_A_ (W)w); 1406 ev_clear_pending (EV_A_ (W)w);
1381 if (!ev_is_active (w)) 1407 if (expect_false (!ev_is_active (w)))
1382 return; 1408 return;
1383 1409
1384 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1410 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1385 1411
1386 if (((W)w)->active < timercnt--) 1412 if (expect_true (((W)w)->active < timercnt--))
1387 { 1413 {
1388 timers [((W)w)->active - 1] = timers [timercnt]; 1414 timers [((W)w)->active - 1] = timers [timercnt];
1389 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1415 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1390 } 1416 }
1391 1417
1416 1442
1417#if EV_PERIODICS 1443#if EV_PERIODICS
1418void 1444void
1419ev_periodic_start (EV_P_ struct ev_periodic *w) 1445ev_periodic_start (EV_P_ struct ev_periodic *w)
1420{ 1446{
1421 if (ev_is_active (w)) 1447 if (expect_false (ev_is_active (w)))
1422 return; 1448 return;
1423 1449
1424 if (w->reschedule_cb) 1450 if (w->reschedule_cb)
1425 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1451 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1426 else if (w->interval) 1452 else if (w->interval)
1440 1466
1441void 1467void
1442ev_periodic_stop (EV_P_ struct ev_periodic *w) 1468ev_periodic_stop (EV_P_ struct ev_periodic *w)
1443{ 1469{
1444 ev_clear_pending (EV_A_ (W)w); 1470 ev_clear_pending (EV_A_ (W)w);
1445 if (!ev_is_active (w)) 1471 if (expect_false (!ev_is_active (w)))
1446 return; 1472 return;
1447 1473
1448 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1474 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1449 1475
1450 if (((W)w)->active < periodiccnt--) 1476 if (expect_true (((W)w)->active < periodiccnt--))
1451 { 1477 {
1452 periodics [((W)w)->active - 1] = periodics [periodiccnt]; 1478 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1453 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); 1479 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1454 } 1480 }
1455 1481
1466#endif 1492#endif
1467 1493
1468void 1494void
1469ev_idle_start (EV_P_ struct ev_idle *w) 1495ev_idle_start (EV_P_ struct ev_idle *w)
1470{ 1496{
1471 if (ev_is_active (w)) 1497 if (expect_false (ev_is_active (w)))
1472 return; 1498 return;
1473 1499
1474 ev_start (EV_A_ (W)w, ++idlecnt); 1500 ev_start (EV_A_ (W)w, ++idlecnt);
1475 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); 1501 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1476 idles [idlecnt - 1] = w; 1502 idles [idlecnt - 1] = w;
1478 1504
1479void 1505void
1480ev_idle_stop (EV_P_ struct ev_idle *w) 1506ev_idle_stop (EV_P_ struct ev_idle *w)
1481{ 1507{
1482 ev_clear_pending (EV_A_ (W)w); 1508 ev_clear_pending (EV_A_ (W)w);
1483 if (!ev_is_active (w)) 1509 if (expect_false (!ev_is_active (w)))
1484 return; 1510 return;
1485 1511
1486 idles [((W)w)->active - 1] = idles [--idlecnt]; 1512 idles [((W)w)->active - 1] = idles [--idlecnt];
1487 ev_stop (EV_A_ (W)w); 1513 ev_stop (EV_A_ (W)w);
1488} 1514}
1489 1515
1490void 1516void
1491ev_prepare_start (EV_P_ struct ev_prepare *w) 1517ev_prepare_start (EV_P_ struct ev_prepare *w)
1492{ 1518{
1493 if (ev_is_active (w)) 1519 if (expect_false (ev_is_active (w)))
1494 return; 1520 return;
1495 1521
1496 ev_start (EV_A_ (W)w, ++preparecnt); 1522 ev_start (EV_A_ (W)w, ++preparecnt);
1497 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 1523 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1498 prepares [preparecnt - 1] = w; 1524 prepares [preparecnt - 1] = w;
1500 1526
1501void 1527void
1502ev_prepare_stop (EV_P_ struct ev_prepare *w) 1528ev_prepare_stop (EV_P_ struct ev_prepare *w)
1503{ 1529{
1504 ev_clear_pending (EV_A_ (W)w); 1530 ev_clear_pending (EV_A_ (W)w);
1505 if (!ev_is_active (w)) 1531 if (expect_false (!ev_is_active (w)))
1506 return; 1532 return;
1507 1533
1508 prepares [((W)w)->active - 1] = prepares [--preparecnt]; 1534 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1509 ev_stop (EV_A_ (W)w); 1535 ev_stop (EV_A_ (W)w);
1510} 1536}
1511 1537
1512void 1538void
1513ev_check_start (EV_P_ struct ev_check *w) 1539ev_check_start (EV_P_ struct ev_check *w)
1514{ 1540{
1515 if (ev_is_active (w)) 1541 if (expect_false (ev_is_active (w)))
1516 return; 1542 return;
1517 1543
1518 ev_start (EV_A_ (W)w, ++checkcnt); 1544 ev_start (EV_A_ (W)w, ++checkcnt);
1519 array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); 1545 array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2);
1520 checks [checkcnt - 1] = w; 1546 checks [checkcnt - 1] = w;
1522 1548
1523void 1549void
1524ev_check_stop (EV_P_ struct ev_check *w) 1550ev_check_stop (EV_P_ struct ev_check *w)
1525{ 1551{
1526 ev_clear_pending (EV_A_ (W)w); 1552 ev_clear_pending (EV_A_ (W)w);
1527 if (!ev_is_active (w)) 1553 if (expect_false (!ev_is_active (w)))
1528 return; 1554 return;
1529 1555
1530 checks [((W)w)->active - 1] = checks [--checkcnt]; 1556 checks [((W)w)->active - 1] = checks [--checkcnt];
1531 ev_stop (EV_A_ (W)w); 1557 ev_stop (EV_A_ (W)w);
1532} 1558}
1539ev_signal_start (EV_P_ struct ev_signal *w) 1565ev_signal_start (EV_P_ struct ev_signal *w)
1540{ 1566{
1541#if EV_MULTIPLICITY 1567#if EV_MULTIPLICITY
1542 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1568 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1543#endif 1569#endif
1544 if (ev_is_active (w)) 1570 if (expect_false (ev_is_active (w)))
1545 return; 1571 return;
1546 1572
1547 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1573 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1548 1574
1549 ev_start (EV_A_ (W)w, 1); 1575 ev_start (EV_A_ (W)w, 1);
1566 1592
1567void 1593void
1568ev_signal_stop (EV_P_ struct ev_signal *w) 1594ev_signal_stop (EV_P_ struct ev_signal *w)
1569{ 1595{
1570 ev_clear_pending (EV_A_ (W)w); 1596 ev_clear_pending (EV_A_ (W)w);
1571 if (!ev_is_active (w)) 1597 if (expect_false (!ev_is_active (w)))
1572 return; 1598 return;
1573 1599
1574 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); 1600 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
1575 ev_stop (EV_A_ (W)w); 1601 ev_stop (EV_A_ (W)w);
1576 1602
1582ev_child_start (EV_P_ struct ev_child *w) 1608ev_child_start (EV_P_ struct ev_child *w)
1583{ 1609{
1584#if EV_MULTIPLICITY 1610#if EV_MULTIPLICITY
1585 assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1611 assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1586#endif 1612#endif
1587 if (ev_is_active (w)) 1613 if (expect_false (ev_is_active (w)))
1588 return; 1614 return;
1589 1615
1590 ev_start (EV_A_ (W)w, 1); 1616 ev_start (EV_A_ (W)w, 1);
1591 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1617 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1592} 1618}
1593 1619
1594void 1620void
1595ev_child_stop (EV_P_ struct ev_child *w) 1621ev_child_stop (EV_P_ struct ev_child *w)
1596{ 1622{
1597 ev_clear_pending (EV_A_ (W)w); 1623 ev_clear_pending (EV_A_ (W)w);
1598 if (!ev_is_active (w)) 1624 if (expect_false (!ev_is_active (w)))
1599 return; 1625 return;
1600 1626
1601 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1627 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1602 ev_stop (EV_A_ (W)w); 1628 ev_stop (EV_A_ (W)w);
1603} 1629}
1640void 1666void
1641ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1667ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1642{ 1668{
1643 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 1669 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
1644 1670
1645 if (!once) 1671 if (expect_false (!once))
1672 {
1646 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1673 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1647 else 1674 return;
1648 { 1675 }
1676
1649 once->cb = cb; 1677 once->cb = cb;
1650 once->arg = arg; 1678 once->arg = arg;
1651 1679
1652 ev_init (&once->io, once_cb_io); 1680 ev_init (&once->io, once_cb_io);
1653 if (fd >= 0) 1681 if (fd >= 0)
1654 { 1682 {
1655 ev_io_set (&once->io, fd, events); 1683 ev_io_set (&once->io, fd, events);
1656 ev_io_start (EV_A_ &once->io); 1684 ev_io_start (EV_A_ &once->io);
1657 } 1685 }
1658 1686
1659 ev_init (&once->to, once_cb_to); 1687 ev_init (&once->to, once_cb_to);
1660 if (timeout >= 0.) 1688 if (timeout >= 0.)
1661 { 1689 {
1662 ev_timer_set (&once->to, timeout, 0.); 1690 ev_timer_set (&once->to, timeout, 0.);
1663 ev_timer_start (EV_A_ &once->to); 1691 ev_timer_start (EV_A_ &once->to);
1664 }
1665 } 1692 }
1666} 1693}
1667 1694
1668#ifdef __cplusplus 1695#ifdef __cplusplus
1669} 1696}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines