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

Comparing libev/ev.c (file contents):
Revision 1.154 by root, Wed Nov 28 11:53:37 2007 UTC vs.
Revision 1.166 by root, Sat Dec 8 03:53:36 2007 UTC

241 241
242#define expect_false(expr) expect ((expr) != 0, 0) 242#define expect_false(expr) expect ((expr) != 0, 0)
243#define expect_true(expr) expect ((expr) != 0, 1) 243#define expect_true(expr) expect ((expr) != 0, 1)
244 244
245#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 245#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
246#define ABSPRI(w) ((w)->priority - EV_MINPRI) 246#define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
247 247
248#define EMPTY0 /* required for microsofts broken pseudo-c compiler */ 248#define EMPTY /* required for microsofts broken pseudo-c compiler */
249#define EMPTY2(a,b) /* used to suppress some warnings */ 249#define EMPTY2(a,b) /* used to suppress some warnings */
250 250
251typedef ev_watcher *W; 251typedef ev_watcher *W;
252typedef ev_watcher_list *WL; 252typedef ev_watcher_list *WL;
253typedef ev_watcher_time *WT; 253typedef ev_watcher_time *WT;
281 perror (msg); 281 perror (msg);
282 abort (); 282 abort ();
283 } 283 }
284} 284}
285 285
286static void *(*alloc)(void *ptr, size_t size) = realloc; 286static void *(*alloc)(void *ptr, long size);
287 287
288void 288void
289ev_set_allocator (void *(*cb)(void *ptr, size_t size)) 289ev_set_allocator (void *(*cb)(void *ptr, long size))
290{ 290{
291 alloc = cb; 291 alloc = cb;
292} 292}
293 293
294inline_speed void * 294inline_speed void *
295ev_realloc (void *ptr, size_t size) 295ev_realloc (void *ptr, long size)
296{ 296{
297 ptr = alloc (ptr, size); 297 ptr = alloc ? alloc (ptr, size) : realloc (ptr, size);
298 298
299 if (!ptr && size) 299 if (!ptr && size)
300 { 300 {
301 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", (long)size); 301 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
302 abort (); 302 abort ();
303 } 303 }
304 304
305 return ptr; 305 return ptr;
306} 306}
324{ 324{
325 W w; 325 W w;
326 int events; 326 int events;
327} ANPENDING; 327} ANPENDING;
328 328
329#if EV_USE_INOTIFY
329typedef struct 330typedef struct
330{ 331{
331#if EV_USE_INOTIFY
332 WL head; 332 WL head;
333#endif
334} ANFS; 333} ANFS;
334#endif
335 335
336#if EV_MULTIPLICITY 336#if EV_MULTIPLICITY
337 337
338 struct ev_loop 338 struct ev_loop
339 { 339 {
396{ 396{
397 return ev_rt_now; 397 return ev_rt_now;
398} 398}
399#endif 399#endif
400 400
401#define array_roundsize(type,n) (((n) | 4) & ~3) 401int inline_size
402array_nextsize (int elem, int cur, int cnt)
403{
404 int ncur = cur + 1;
405
406 do
407 ncur <<= 1;
408 while (cnt > ncur);
409
410 /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */
411 if (elem * ncur > 4096)
412 {
413 ncur *= elem;
414 ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095;
415 ncur = ncur - sizeof (void *) * 4;
416 ncur /= elem;
417 }
418
419 return ncur;
420}
421
422inline_speed void *
423array_realloc (int elem, void *base, int *cur, int cnt)
424{
425 *cur = array_nextsize (elem, *cur, cnt);
426 return ev_realloc (base, elem * *cur);
427}
402 428
403#define array_needsize(type,base,cur,cnt,init) \ 429#define array_needsize(type,base,cur,cnt,init) \
404 if (expect_false ((cnt) > cur)) \ 430 if (expect_false ((cnt) > (cur))) \
405 { \ 431 { \
406 int newcnt = cur; \ 432 int ocur_ = (cur); \
407 do \ 433 (base) = (type *)array_realloc \
408 { \ 434 (sizeof (type), (base), &(cur), (cnt)); \
409 newcnt = array_roundsize (type, newcnt << 1); \ 435 init ((base) + (ocur_), (cur) - ocur_); \
410 } \
411 while ((cnt) > newcnt); \
412 \
413 base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
414 init (base + cur, newcnt - cur); \
415 cur = newcnt; \
416 } 436 }
417 437
438#if 0
418#define array_slim(type,stem) \ 439#define array_slim(type,stem) \
419 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 440 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
420 { \ 441 { \
421 stem ## max = array_roundsize (stem ## cnt >> 1); \ 442 stem ## max = array_roundsize (stem ## cnt >> 1); \
422 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ 443 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
423 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 444 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
424 } 445 }
446#endif
425 447
426#define array_free(stem, idx) \ 448#define array_free(stem, idx) \
427 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 449 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
428 450
429/*****************************************************************************/ 451/*****************************************************************************/
589static void noinline 611static void noinline
590fd_rearm_all (EV_P) 612fd_rearm_all (EV_P)
591{ 613{
592 int fd; 614 int fd;
593 615
594 /* this should be highly optimised to not do anything but set a flag */
595 for (fd = 0; fd < anfdmax; ++fd) 616 for (fd = 0; fd < anfdmax; ++fd)
596 if (anfds [fd].events) 617 if (anfds [fd].events)
597 { 618 {
598 anfds [fd].events = 0; 619 anfds [fd].events = 0;
599 fd_change (EV_A_ fd); 620 fd_change (EV_A_ fd);
765 ev_child *w; 786 ev_child *w;
766 787
767 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 788 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
768 if (w->pid == pid || !w->pid) 789 if (w->pid == pid || !w->pid)
769 { 790 {
770 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 791 ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */
771 w->rpid = pid; 792 w->rpid = pid;
772 w->rstatus = status; 793 w->rstatus = status;
773 ev_feed_event (EV_A_ (W)w, EV_CHILD); 794 ev_feed_event (EV_A_ (W)w, EV_CHILD);
774 } 795 }
775} 796}
776 797
777#ifndef WCONTINUED 798#ifndef WCONTINUED
887ev_backend (EV_P) 908ev_backend (EV_P)
888{ 909{
889 return backend; 910 return backend;
890} 911}
891 912
913unsigned int
914ev_loop_count (EV_P)
915{
916 return loop_count;
917}
918
892static void noinline 919static void noinline
893loop_init (EV_P_ unsigned int flags) 920loop_init (EV_P_ unsigned int flags)
894{ 921{
895 if (!backend) 922 if (!backend)
896 { 923 {
905 ev_rt_now = ev_time (); 932 ev_rt_now = ev_time ();
906 mn_now = get_clock (); 933 mn_now = get_clock ();
907 now_floor = mn_now; 934 now_floor = mn_now;
908 rtmn_diff = ev_rt_now - mn_now; 935 rtmn_diff = ev_rt_now - mn_now;
909 936
937 /* pid check not overridable via env */
938#ifndef _WIN32
939 if (flags & EVFLAG_FORKCHECK)
940 curpid = getpid ();
941#endif
942
910 if (!(flags & EVFLAG_NOENV) 943 if (!(flags & EVFLAG_NOENV)
911 && !enable_secure () 944 && !enable_secure ()
912 && getenv ("LIBEV_FLAGS")) 945 && getenv ("LIBEV_FLAGS"))
913 flags = atoi (getenv ("LIBEV_FLAGS")); 946 flags = atoi (getenv ("LIBEV_FLAGS"));
914 947
970#if EV_USE_SELECT 1003#if EV_USE_SELECT
971 if (backend == EVBACKEND_SELECT) select_destroy (EV_A); 1004 if (backend == EVBACKEND_SELECT) select_destroy (EV_A);
972#endif 1005#endif
973 1006
974 for (i = NUMPRI; i--; ) 1007 for (i = NUMPRI; i--; )
1008 {
975 array_free (pending, [i]); 1009 array_free (pending, [i]);
1010#if EV_IDLE_ENABLE
1011 array_free (idle, [i]);
1012#endif
1013 }
976 1014
977 /* have to use the microsoft-never-gets-it-right macro */ 1015 /* have to use the microsoft-never-gets-it-right macro */
978 array_free (fdchange, EMPTY0); 1016 array_free (fdchange, EMPTY);
979 array_free (timer, EMPTY0); 1017 array_free (timer, EMPTY);
980#if EV_PERIODIC_ENABLE 1018#if EV_PERIODIC_ENABLE
981 array_free (periodic, EMPTY0); 1019 array_free (periodic, EMPTY);
982#endif 1020#endif
983 array_free (idle, EMPTY0);
984 array_free (prepare, EMPTY0); 1021 array_free (prepare, EMPTY);
985 array_free (check, EMPTY0); 1022 array_free (check, EMPTY);
986 1023
987 backend = 0; 1024 backend = 0;
988} 1025}
989 1026
990void inline_size infy_fork (EV_P); 1027void inline_size infy_fork (EV_P);
1125 if (backend) 1162 if (backend)
1126 postfork = 1; 1163 postfork = 1;
1127} 1164}
1128 1165
1129/*****************************************************************************/ 1166/*****************************************************************************/
1130
1131int inline_size
1132any_pending (EV_P)
1133{
1134 int pri;
1135
1136 for (pri = NUMPRI; pri--; )
1137 if (pendingcnt [pri])
1138 return 1;
1139
1140 return 0;
1141}
1142 1167
1143void inline_speed 1168void inline_speed
1144call_pending (EV_P) 1169call_pending (EV_P)
1145{ 1170{
1146 int pri; 1171 int pri;
1237 for (i = periodiccnt >> 1; i--; ) 1262 for (i = periodiccnt >> 1; i--; )
1238 downheap ((WT *)periodics, periodiccnt, i); 1263 downheap ((WT *)periodics, periodiccnt, i);
1239} 1264}
1240#endif 1265#endif
1241 1266
1267#if EV_IDLE_ENABLE
1268void inline_size
1269idle_reify (EV_P)
1270{
1271 if (expect_false (idleall))
1272 {
1273 int pri;
1274
1275 for (pri = NUMPRI; pri--; )
1276 {
1277 if (pendingcnt [pri])
1278 break;
1279
1280 if (idlecnt [pri])
1281 {
1282 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1283 break;
1284 }
1285 }
1286 }
1287}
1288#endif
1289
1242int inline_size 1290int inline_size
1243time_update_monotonic (EV_P) 1291time_update_monotonic (EV_P)
1244{ 1292{
1245 mn_now = get_clock (); 1293 mn_now = get_clock ();
1246 1294
1270 ev_tstamp odiff = rtmn_diff; 1318 ev_tstamp odiff = rtmn_diff;
1271 1319
1272 /* loop a few times, before making important decisions. 1320 /* loop a few times, before making important decisions.
1273 * on the choice of "4": one iteration isn't enough, 1321 * on the choice of "4": one iteration isn't enough,
1274 * in case we get preempted during the calls to 1322 * in case we get preempted during the calls to
1275 * ev_time and get_clock. a second call is almost guarenteed 1323 * ev_time and get_clock. a second call is almost guaranteed
1276 * to succeed in that case, though. and looping a few more times 1324 * to succeed in that case, though. and looping a few more times
1277 * doesn't hurt either as we only do this on time-jumps or 1325 * doesn't hurt either as we only do this on time-jumps or
1278 * in the unlikely event of getting preempted here. 1326 * in the unlikely event of having been preempted here.
1279 */ 1327 */
1280 for (i = 4; --i; ) 1328 for (i = 4; --i; )
1281 { 1329 {
1282 rtmn_diff = ev_rt_now - mn_now; 1330 rtmn_diff = ev_rt_now - mn_now;
1283 1331
1305 { 1353 {
1306#if EV_PERIODIC_ENABLE 1354#if EV_PERIODIC_ENABLE
1307 periodics_reschedule (EV_A); 1355 periodics_reschedule (EV_A);
1308#endif 1356#endif
1309 1357
1310 /* adjust timers. this is easy, as the offset is the same for all */ 1358 /* adjust timers. this is easy, as the offset is the same for all of them */
1311 for (i = 0; i < timercnt; ++i) 1359 for (i = 0; i < timercnt; ++i)
1312 ((WT)timers [i])->at += ev_rt_now - mn_now; 1360 ((WT)timers [i])->at += ev_rt_now - mn_now;
1313 } 1361 }
1314 1362
1315 mn_now = ev_rt_now; 1363 mn_now = ev_rt_now;
1335{ 1383{
1336 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) 1384 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)
1337 ? EVUNLOOP_ONE 1385 ? EVUNLOOP_ONE
1338 : EVUNLOOP_CANCEL; 1386 : EVUNLOOP_CANCEL;
1339 1387
1340 while (activecnt) 1388 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */
1389
1390 do
1341 { 1391 {
1342 /* we might have forked, so reify kernel state if necessary */ 1392#ifndef _WIN32
1393 if (expect_false (curpid)) /* penalise the forking check even more */
1394 if (expect_false (getpid () != curpid))
1395 {
1396 curpid = getpid ();
1397 postfork = 1;
1398 }
1399#endif
1400
1343 #if EV_FORK_ENABLE 1401#if EV_FORK_ENABLE
1402 /* we might have forked, so queue fork handlers */
1344 if (expect_false (postfork)) 1403 if (expect_false (postfork))
1345 if (forkcnt) 1404 if (forkcnt)
1346 { 1405 {
1347 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 1406 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
1348 call_pending (EV_A); 1407 call_pending (EV_A);
1349 } 1408 }
1350 #endif 1409#endif
1351 1410
1352 /* queue check watchers (and execute them) */ 1411 /* queue check watchers (and execute them) */
1353 if (expect_false (preparecnt)) 1412 if (expect_false (preparecnt))
1354 { 1413 {
1355 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1414 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1356 call_pending (EV_A); 1415 call_pending (EV_A);
1357 } 1416 }
1358 1417
1418 if (expect_false (!activecnt))
1419 break;
1420
1359 /* we might have forked, so reify kernel state if necessary */ 1421 /* we might have forked, so reify kernel state if necessary */
1360 if (expect_false (postfork)) 1422 if (expect_false (postfork))
1361 loop_fork (EV_A); 1423 loop_fork (EV_A);
1362 1424
1363 /* update fd-related kernel structures */ 1425 /* update fd-related kernel structures */
1364 fd_reify (EV_A); 1426 fd_reify (EV_A);
1365 1427
1366 /* calculate blocking time */ 1428 /* calculate blocking time */
1367 { 1429 {
1368 double block; 1430 ev_tstamp block;
1369 1431
1370 if (flags & EVLOOP_NONBLOCK || idlecnt) 1432 if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt))
1371 block = 0.; /* do not block at all */ 1433 block = 0.; /* do not block at all */
1372 else 1434 else
1373 { 1435 {
1374 /* update time to cancel out callback processing overhead */ 1436 /* update time to cancel out callback processing overhead */
1375#if EV_USE_MONOTONIC 1437#if EV_USE_MONOTONIC
1399#endif 1461#endif
1400 1462
1401 if (expect_false (block < 0.)) block = 0.; 1463 if (expect_false (block < 0.)) block = 0.;
1402 } 1464 }
1403 1465
1466 ++loop_count;
1404 backend_poll (EV_A_ block); 1467 backend_poll (EV_A_ block);
1405 } 1468 }
1406 1469
1407 /* update ev_rt_now, do magic */ 1470 /* update ev_rt_now, do magic */
1408 time_update (EV_A); 1471 time_update (EV_A);
1411 timers_reify (EV_A); /* relative timers called last */ 1474 timers_reify (EV_A); /* relative timers called last */
1412#if EV_PERIODIC_ENABLE 1475#if EV_PERIODIC_ENABLE
1413 periodics_reify (EV_A); /* absolute timers called first */ 1476 periodics_reify (EV_A); /* absolute timers called first */
1414#endif 1477#endif
1415 1478
1479#if EV_IDLE_ENABLE
1416 /* queue idle watchers unless other events are pending */ 1480 /* queue idle watchers unless other events are pending */
1417 if (idlecnt && !any_pending (EV_A)) 1481 idle_reify (EV_A);
1418 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1482#endif
1419 1483
1420 /* queue check watchers, to be executed first */ 1484 /* queue check watchers, to be executed first */
1421 if (expect_false (checkcnt)) 1485 if (expect_false (checkcnt))
1422 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1486 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1423 1487
1424 call_pending (EV_A); 1488 call_pending (EV_A);
1425 1489
1426 if (expect_false (loop_done))
1427 break;
1428 } 1490 }
1491 while (expect_true (activecnt && !loop_done));
1429 1492
1430 if (loop_done == EVUNLOOP_ONE) 1493 if (loop_done == EVUNLOOP_ONE)
1431 loop_done = EVUNLOOP_CANCEL; 1494 loop_done = EVUNLOOP_CANCEL;
1432} 1495}
1433 1496
1460 head = &(*head)->next; 1523 head = &(*head)->next;
1461 } 1524 }
1462} 1525}
1463 1526
1464void inline_speed 1527void inline_speed
1465ev_clear_pending (EV_P_ W w) 1528clear_pending (EV_P_ W w)
1466{ 1529{
1467 if (w->pending) 1530 if (w->pending)
1468 { 1531 {
1469 pendings [ABSPRI (w)][w->pending - 1].w = 0; 1532 pendings [ABSPRI (w)][w->pending - 1].w = 0;
1470 w->pending = 0; 1533 w->pending = 0;
1471 } 1534 }
1472} 1535}
1473 1536
1537void
1538ev_clear_pending (EV_P_ void *w, int invoke)
1539{
1540 W w_ = (W)w;
1541 int pending = w_->pending;
1542
1543 if (pending)
1544 {
1545 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
1546
1547 w_->pending = 0;
1548 p->w = 0;
1549
1550 if (invoke)
1551 EV_CB_INVOKE (w_, p->events);
1552 }
1553}
1554
1555void inline_size
1556pri_adjust (EV_P_ W w)
1557{
1558 int pri = w->priority;
1559 pri = pri < EV_MINPRI ? EV_MINPRI : pri;
1560 pri = pri > EV_MAXPRI ? EV_MAXPRI : pri;
1561 w->priority = pri;
1562}
1563
1474void inline_speed 1564void inline_speed
1475ev_start (EV_P_ W w, int active) 1565ev_start (EV_P_ W w, int active)
1476{ 1566{
1477 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; 1567 pri_adjust (EV_A_ w);
1478 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI;
1479
1480 w->active = active; 1568 w->active = active;
1481 ev_ref (EV_A); 1569 ev_ref (EV_A);
1482} 1570}
1483 1571
1484void inline_size 1572void inline_size
1508} 1596}
1509 1597
1510void 1598void
1511ev_io_stop (EV_P_ ev_io *w) 1599ev_io_stop (EV_P_ ev_io *w)
1512{ 1600{
1513 ev_clear_pending (EV_A_ (W)w); 1601 clear_pending (EV_A_ (W)w);
1514 if (expect_false (!ev_is_active (w))) 1602 if (expect_false (!ev_is_active (w)))
1515 return; 1603 return;
1516 1604
1517 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 1605 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
1518 1606
1541} 1629}
1542 1630
1543void 1631void
1544ev_timer_stop (EV_P_ ev_timer *w) 1632ev_timer_stop (EV_P_ ev_timer *w)
1545{ 1633{
1546 ev_clear_pending (EV_A_ (W)w); 1634 clear_pending (EV_A_ (W)w);
1547 if (expect_false (!ev_is_active (w))) 1635 if (expect_false (!ev_is_active (w)))
1548 return; 1636 return;
1549 1637
1550 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1638 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1551 1639
1609} 1697}
1610 1698
1611void 1699void
1612ev_periodic_stop (EV_P_ ev_periodic *w) 1700ev_periodic_stop (EV_P_ ev_periodic *w)
1613{ 1701{
1614 ev_clear_pending (EV_A_ (W)w); 1702 clear_pending (EV_A_ (W)w);
1615 if (expect_false (!ev_is_active (w))) 1703 if (expect_false (!ev_is_active (w)))
1616 return; 1704 return;
1617 1705
1618 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1706 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1619 1707
1673} 1761}
1674 1762
1675void 1763void
1676ev_signal_stop (EV_P_ ev_signal *w) 1764ev_signal_stop (EV_P_ ev_signal *w)
1677{ 1765{
1678 ev_clear_pending (EV_A_ (W)w); 1766 clear_pending (EV_A_ (W)w);
1679 if (expect_false (!ev_is_active (w))) 1767 if (expect_false (!ev_is_active (w)))
1680 return; 1768 return;
1681 1769
1682 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); 1770 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
1683 ev_stop (EV_A_ (W)w); 1771 ev_stop (EV_A_ (W)w);
1700} 1788}
1701 1789
1702void 1790void
1703ev_child_stop (EV_P_ ev_child *w) 1791ev_child_stop (EV_P_ ev_child *w)
1704{ 1792{
1705 ev_clear_pending (EV_A_ (W)w); 1793 clear_pending (EV_A_ (W)w);
1706 if (expect_false (!ev_is_active (w))) 1794 if (expect_false (!ev_is_active (w)))
1707 return; 1795 return;
1708 1796
1709 wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 1797 wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1710 ev_stop (EV_A_ (W)w); 1798 ev_stop (EV_A_ (W)w);
1718# endif 1806# endif
1719 1807
1720#define DEF_STAT_INTERVAL 5.0074891 1808#define DEF_STAT_INTERVAL 5.0074891
1721#define MIN_STAT_INTERVAL 0.1074891 1809#define MIN_STAT_INTERVAL 0.1074891
1722 1810
1723void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); 1811static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents);
1724 1812
1725#if EV_USE_INOTIFY 1813#if EV_USE_INOTIFY
1726# define EV_INOTIFY_BUFSIZE 8192 1814# define EV_INOTIFY_BUFSIZE 8192
1727 1815
1728static void noinline 1816static void noinline
1879 w->attr.st_nlink = 0; 1967 w->attr.st_nlink = 0;
1880 else if (!w->attr.st_nlink) 1968 else if (!w->attr.st_nlink)
1881 w->attr.st_nlink = 1; 1969 w->attr.st_nlink = 1;
1882} 1970}
1883 1971
1884void noinline 1972static void noinline
1885stat_timer_cb (EV_P_ ev_timer *w_, int revents) 1973stat_timer_cb (EV_P_ ev_timer *w_, int revents)
1886{ 1974{
1887 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 1975 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
1888 1976
1889 /* we copy this here each the time so that */ 1977 /* we copy this here each the time so that */
1890 /* prev has the old value when the callback gets invoked */ 1978 /* prev has the old value when the callback gets invoked */
1891 w->prev = w->attr; 1979 w->prev = w->attr;
1892 ev_stat_stat (EV_A_ w); 1980 ev_stat_stat (EV_A_ w);
1893 1981
1894 if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata))) 1982 /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */
1983 if (
1984 w->prev.st_dev != w->attr.st_dev
1985 || w->prev.st_ino != w->attr.st_ino
1986 || w->prev.st_mode != w->attr.st_mode
1987 || w->prev.st_nlink != w->attr.st_nlink
1988 || w->prev.st_uid != w->attr.st_uid
1989 || w->prev.st_gid != w->attr.st_gid
1990 || w->prev.st_rdev != w->attr.st_rdev
1991 || w->prev.st_size != w->attr.st_size
1992 || w->prev.st_atime != w->attr.st_atime
1993 || w->prev.st_mtime != w->attr.st_mtime
1994 || w->prev.st_ctime != w->attr.st_ctime
1895 { 1995 ) {
1896 #if EV_USE_INOTIFY 1996 #if EV_USE_INOTIFY
1897 infy_del (EV_A_ w); 1997 infy_del (EV_A_ w);
1898 infy_add (EV_A_ w); 1998 infy_add (EV_A_ w);
1899 ev_stat_stat (EV_A_ w); /* avoid race... */ 1999 ev_stat_stat (EV_A_ w); /* avoid race... */
1900 #endif 2000 #endif
1934} 2034}
1935 2035
1936void 2036void
1937ev_stat_stop (EV_P_ ev_stat *w) 2037ev_stat_stop (EV_P_ ev_stat *w)
1938{ 2038{
1939 ev_clear_pending (EV_A_ (W)w); 2039 clear_pending (EV_A_ (W)w);
1940 if (expect_false (!ev_is_active (w))) 2040 if (expect_false (!ev_is_active (w)))
1941 return; 2041 return;
1942 2042
1943#if EV_USE_INOTIFY 2043#if EV_USE_INOTIFY
1944 infy_del (EV_A_ w); 2044 infy_del (EV_A_ w);
1947 2047
1948 ev_stop (EV_A_ (W)w); 2048 ev_stop (EV_A_ (W)w);
1949} 2049}
1950#endif 2050#endif
1951 2051
2052#if EV_IDLE_ENABLE
1952void 2053void
1953ev_idle_start (EV_P_ ev_idle *w) 2054ev_idle_start (EV_P_ ev_idle *w)
1954{ 2055{
1955 if (expect_false (ev_is_active (w))) 2056 if (expect_false (ev_is_active (w)))
1956 return; 2057 return;
1957 2058
2059 pri_adjust (EV_A_ (W)w);
2060
2061 {
2062 int active = ++idlecnt [ABSPRI (w)];
2063
2064 ++idleall;
1958 ev_start (EV_A_ (W)w, ++idlecnt); 2065 ev_start (EV_A_ (W)w, active);
2066
1959 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); 2067 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2);
1960 idles [idlecnt - 1] = w; 2068 idles [ABSPRI (w)][active - 1] = w;
2069 }
1961} 2070}
1962 2071
1963void 2072void
1964ev_idle_stop (EV_P_ ev_idle *w) 2073ev_idle_stop (EV_P_ ev_idle *w)
1965{ 2074{
1966 ev_clear_pending (EV_A_ (W)w); 2075 clear_pending (EV_A_ (W)w);
1967 if (expect_false (!ev_is_active (w))) 2076 if (expect_false (!ev_is_active (w)))
1968 return; 2077 return;
1969 2078
1970 { 2079 {
1971 int active = ((W)w)->active; 2080 int active = ((W)w)->active;
1972 idles [active - 1] = idles [--idlecnt]; 2081
2082 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
1973 ((W)idles [active - 1])->active = active; 2083 ((W)idles [ABSPRI (w)][active - 1])->active = active;
2084
2085 ev_stop (EV_A_ (W)w);
2086 --idleall;
1974 } 2087 }
1975
1976 ev_stop (EV_A_ (W)w);
1977} 2088}
2089#endif
1978 2090
1979void 2091void
1980ev_prepare_start (EV_P_ ev_prepare *w) 2092ev_prepare_start (EV_P_ ev_prepare *w)
1981{ 2093{
1982 if (expect_false (ev_is_active (w))) 2094 if (expect_false (ev_is_active (w)))
1988} 2100}
1989 2101
1990void 2102void
1991ev_prepare_stop (EV_P_ ev_prepare *w) 2103ev_prepare_stop (EV_P_ ev_prepare *w)
1992{ 2104{
1993 ev_clear_pending (EV_A_ (W)w); 2105 clear_pending (EV_A_ (W)w);
1994 if (expect_false (!ev_is_active (w))) 2106 if (expect_false (!ev_is_active (w)))
1995 return; 2107 return;
1996 2108
1997 { 2109 {
1998 int active = ((W)w)->active; 2110 int active = ((W)w)->active;
2015} 2127}
2016 2128
2017void 2129void
2018ev_check_stop (EV_P_ ev_check *w) 2130ev_check_stop (EV_P_ ev_check *w)
2019{ 2131{
2020 ev_clear_pending (EV_A_ (W)w); 2132 clear_pending (EV_A_ (W)w);
2021 if (expect_false (!ev_is_active (w))) 2133 if (expect_false (!ev_is_active (w)))
2022 return; 2134 return;
2023 2135
2024 { 2136 {
2025 int active = ((W)w)->active; 2137 int active = ((W)w)->active;
2067} 2179}
2068 2180
2069void 2181void
2070ev_embed_stop (EV_P_ ev_embed *w) 2182ev_embed_stop (EV_P_ ev_embed *w)
2071{ 2183{
2072 ev_clear_pending (EV_A_ (W)w); 2184 clear_pending (EV_A_ (W)w);
2073 if (expect_false (!ev_is_active (w))) 2185 if (expect_false (!ev_is_active (w)))
2074 return; 2186 return;
2075 2187
2076 ev_io_stop (EV_A_ &w->io); 2188 ev_io_stop (EV_A_ &w->io);
2077 2189
2092} 2204}
2093 2205
2094void 2206void
2095ev_fork_stop (EV_P_ ev_fork *w) 2207ev_fork_stop (EV_P_ ev_fork *w)
2096{ 2208{
2097 ev_clear_pending (EV_A_ (W)w); 2209 clear_pending (EV_A_ (W)w);
2098 if (expect_false (!ev_is_active (w))) 2210 if (expect_false (!ev_is_active (w)))
2099 return; 2211 return;
2100 2212
2101 { 2213 {
2102 int active = ((W)w)->active; 2214 int active = ((W)w)->active;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines