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

Comparing libev/ev.c (file contents):
Revision 1.152 by root, Wed Nov 28 11:15:55 2007 UTC vs.
Revision 1.165 by root, Fri Dec 7 18:09:38 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}
1026
1027void inline_size infy_fork (EV_P);
989 1028
990void inline_size 1029void inline_size
991loop_fork (EV_P) 1030loop_fork (EV_P)
992{ 1031{
993#if EV_USE_PORT 1032#if EV_USE_PORT
996#if EV_USE_KQUEUE 1035#if EV_USE_KQUEUE
997 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); 1036 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A);
998#endif 1037#endif
999#if EV_USE_EPOLL 1038#if EV_USE_EPOLL
1000 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); 1039 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
1040#endif
1041#if EV_USE_INOTIFY
1042 infy_fork (EV_A);
1001#endif 1043#endif
1002 1044
1003 if (ev_is_active (&sigev)) 1045 if (ev_is_active (&sigev))
1004 { 1046 {
1005 /* default loop */ 1047 /* default loop */
1120 if (backend) 1162 if (backend)
1121 postfork = 1; 1163 postfork = 1;
1122} 1164}
1123 1165
1124/*****************************************************************************/ 1166/*****************************************************************************/
1125
1126int inline_size
1127any_pending (EV_P)
1128{
1129 int pri;
1130
1131 for (pri = NUMPRI; pri--; )
1132 if (pendingcnt [pri])
1133 return 1;
1134
1135 return 0;
1136}
1137 1167
1138void inline_speed 1168void inline_speed
1139call_pending (EV_P) 1169call_pending (EV_P)
1140{ 1170{
1141 int pri; 1171 int pri;
1232 for (i = periodiccnt >> 1; i--; ) 1262 for (i = periodiccnt >> 1; i--; )
1233 downheap ((WT *)periodics, periodiccnt, i); 1263 downheap ((WT *)periodics, periodiccnt, i);
1234} 1264}
1235#endif 1265#endif
1236 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
1237int inline_size 1290int inline_size
1238time_update_monotonic (EV_P) 1291time_update_monotonic (EV_P)
1239{ 1292{
1240 mn_now = get_clock (); 1293 mn_now = get_clock ();
1241 1294
1265 ev_tstamp odiff = rtmn_diff; 1318 ev_tstamp odiff = rtmn_diff;
1266 1319
1267 /* loop a few times, before making important decisions. 1320 /* loop a few times, before making important decisions.
1268 * on the choice of "4": one iteration isn't enough, 1321 * on the choice of "4": one iteration isn't enough,
1269 * in case we get preempted during the calls to 1322 * in case we get preempted during the calls to
1270 * ev_time and get_clock. a second call is almost guarenteed 1323 * ev_time and get_clock. a second call is almost guaranteed
1271 * 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
1272 * 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
1273 * in the unlikely event of getting preempted here. 1326 * in the unlikely event of having been preempted here.
1274 */ 1327 */
1275 for (i = 4; --i; ) 1328 for (i = 4; --i; )
1276 { 1329 {
1277 rtmn_diff = ev_rt_now - mn_now; 1330 rtmn_diff = ev_rt_now - mn_now;
1278 1331
1300 { 1353 {
1301#if EV_PERIODIC_ENABLE 1354#if EV_PERIODIC_ENABLE
1302 periodics_reschedule (EV_A); 1355 periodics_reschedule (EV_A);
1303#endif 1356#endif
1304 1357
1305 /* 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 */
1306 for (i = 0; i < timercnt; ++i) 1359 for (i = 0; i < timercnt; ++i)
1307 ((WT)timers [i])->at += ev_rt_now - mn_now; 1360 ((WT)timers [i])->at += ev_rt_now - mn_now;
1308 } 1361 }
1309 1362
1310 mn_now = ev_rt_now; 1363 mn_now = ev_rt_now;
1330{ 1383{
1331 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) 1384 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)
1332 ? EVUNLOOP_ONE 1385 ? EVUNLOOP_ONE
1333 : EVUNLOOP_CANCEL; 1386 : EVUNLOOP_CANCEL;
1334 1387
1335 while (activecnt) 1388 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */
1389
1390 do
1336 { 1391 {
1337 /* 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
1338 #if EV_FORK_ENABLE 1401#if EV_FORK_ENABLE
1402 /* we might have forked, so queue fork handlers */
1339 if (expect_false (postfork)) 1403 if (expect_false (postfork))
1340 if (forkcnt) 1404 if (forkcnt)
1341 { 1405 {
1342 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 1406 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
1343 call_pending (EV_A); 1407 call_pending (EV_A);
1344 } 1408 }
1345 #endif 1409#endif
1346 1410
1347 /* queue check watchers (and execute them) */ 1411 /* queue check watchers (and execute them) */
1348 if (expect_false (preparecnt)) 1412 if (expect_false (preparecnt))
1349 { 1413 {
1350 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1414 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1351 call_pending (EV_A); 1415 call_pending (EV_A);
1352 } 1416 }
1353 1417
1418 if (expect_false (!activecnt))
1419 break;
1420
1354 /* we might have forked, so reify kernel state if necessary */ 1421 /* we might have forked, so reify kernel state if necessary */
1355 if (expect_false (postfork)) 1422 if (expect_false (postfork))
1356 loop_fork (EV_A); 1423 loop_fork (EV_A);
1357 1424
1358 /* update fd-related kernel structures */ 1425 /* update fd-related kernel structures */
1359 fd_reify (EV_A); 1426 fd_reify (EV_A);
1360 1427
1361 /* calculate blocking time */ 1428 /* calculate blocking time */
1362 { 1429 {
1363 double block; 1430 ev_tstamp block;
1364 1431
1365 if (flags & EVLOOP_NONBLOCK || idlecnt) 1432 if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt))
1366 block = 0.; /* do not block at all */ 1433 block = 0.; /* do not block at all */
1367 else 1434 else
1368 { 1435 {
1369 /* update time to cancel out callback processing overhead */ 1436 /* update time to cancel out callback processing overhead */
1370#if EV_USE_MONOTONIC 1437#if EV_USE_MONOTONIC
1394#endif 1461#endif
1395 1462
1396 if (expect_false (block < 0.)) block = 0.; 1463 if (expect_false (block < 0.)) block = 0.;
1397 } 1464 }
1398 1465
1466 ++loop_count;
1399 backend_poll (EV_A_ block); 1467 backend_poll (EV_A_ block);
1400 } 1468 }
1401 1469
1402 /* update ev_rt_now, do magic */ 1470 /* update ev_rt_now, do magic */
1403 time_update (EV_A); 1471 time_update (EV_A);
1406 timers_reify (EV_A); /* relative timers called last */ 1474 timers_reify (EV_A); /* relative timers called last */
1407#if EV_PERIODIC_ENABLE 1475#if EV_PERIODIC_ENABLE
1408 periodics_reify (EV_A); /* absolute timers called first */ 1476 periodics_reify (EV_A); /* absolute timers called first */
1409#endif 1477#endif
1410 1478
1479#if EV_IDLE_ENABLE
1411 /* queue idle watchers unless other events are pending */ 1480 /* queue idle watchers unless other events are pending */
1412 if (idlecnt && !any_pending (EV_A)) 1481 idle_reify (EV_A);
1413 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1482#endif
1414 1483
1415 /* queue check watchers, to be executed first */ 1484 /* queue check watchers, to be executed first */
1416 if (expect_false (checkcnt)) 1485 if (expect_false (checkcnt))
1417 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1486 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1418 1487
1419 call_pending (EV_A); 1488 call_pending (EV_A);
1420 1489
1421 if (expect_false (loop_done))
1422 break;
1423 } 1490 }
1491 while (expect_true (activecnt && !loop_done));
1424 1492
1425 if (loop_done == EVUNLOOP_ONE) 1493 if (loop_done == EVUNLOOP_ONE)
1426 loop_done = EVUNLOOP_CANCEL; 1494 loop_done = EVUNLOOP_CANCEL;
1427} 1495}
1428 1496
1464 pendings [ABSPRI (w)][w->pending - 1].w = 0; 1532 pendings [ABSPRI (w)][w->pending - 1].w = 0;
1465 w->pending = 0; 1533 w->pending = 0;
1466 } 1534 }
1467} 1535}
1468 1536
1537void inline_size
1538pri_adjust (EV_P_ W w)
1539{
1540 int pri = w->priority;
1541 pri = pri < EV_MINPRI ? EV_MINPRI : pri;
1542 pri = pri > EV_MAXPRI ? EV_MAXPRI : pri;
1543 w->priority = pri;
1544}
1545
1469void inline_speed 1546void inline_speed
1470ev_start (EV_P_ W w, int active) 1547ev_start (EV_P_ W w, int active)
1471{ 1548{
1472 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; 1549 pri_adjust (EV_A_ w);
1473 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI;
1474
1475 w->active = active; 1550 w->active = active;
1476 ev_ref (EV_A); 1551 ev_ref (EV_A);
1477} 1552}
1478 1553
1479void inline_size 1554void inline_size
1713# endif 1788# endif
1714 1789
1715#define DEF_STAT_INTERVAL 5.0074891 1790#define DEF_STAT_INTERVAL 5.0074891
1716#define MIN_STAT_INTERVAL 0.1074891 1791#define MIN_STAT_INTERVAL 0.1074891
1717 1792
1718void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); 1793static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents);
1719 1794
1720#if EV_USE_INOTIFY 1795#if EV_USE_INOTIFY
1721# define EV_INOTIFY_BUFSIZE ((PATH_MAX + sizeof (struct inotify_event)) + 2048) 1796# define EV_INOTIFY_BUFSIZE 8192
1722 1797
1723static void noinline 1798static void noinline
1724infy_add (EV_P_ ev_stat *w) 1799infy_add (EV_P_ ev_stat *w)
1725{ 1800{
1726 w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); 1801 w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD);
1728 if (w->wd < 0) 1803 if (w->wd < 0)
1729 { 1804 {
1730 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ 1805 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
1731 1806
1732 /* monitor some parent directory for speedup hints */ 1807 /* monitor some parent directory for speedup hints */
1733 if (errno == ENOENT || errno == EACCES) 1808 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
1734 { 1809 {
1735 char path [PATH_MAX]; 1810 char path [4096];
1736 strcpy (path, w->path); 1811 strcpy (path, w->path);
1737 1812
1738 do 1813 do
1739 { 1814 {
1740 int mask = IN_MASK_ADD | IN_DELETE_SELF | IN_MOVE_SELF 1815 int mask = IN_MASK_ADD | IN_DELETE_SELF | IN_MOVE_SELF
1744 1819
1745 if (!pend) 1820 if (!pend)
1746 break; /* whoops, no '/', complain to your admin */ 1821 break; /* whoops, no '/', complain to your admin */
1747 1822
1748 *pend = 0; 1823 *pend = 0;
1749 w->wd = inotify_add_watch (fs_fd, path, IN_DELETE_SELF | IN_CREATE | IN_MOVED_TO | IN_MASK_ADD); 1824 w->wd = inotify_add_watch (fs_fd, path, mask);
1750 } 1825 }
1751 while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); 1826 while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
1752 } 1827 }
1753 } 1828 }
1754 else 1829 else
1759} 1834}
1760 1835
1761static void noinline 1836static void noinline
1762infy_del (EV_P_ ev_stat *w) 1837infy_del (EV_P_ ev_stat *w)
1763{ 1838{
1764 WL w_;
1765 int slot; 1839 int slot;
1766 int wd = w->wd; 1840 int wd = w->wd;
1767 1841
1768 if (wd < 0) 1842 if (wd < 0)
1769 return; 1843 return;
1798 { 1872 {
1799 w->wd = -1; 1873 w->wd = -1;
1800 infy_add (EV_A_ w); /* re-add, no matter what */ 1874 infy_add (EV_A_ w); /* re-add, no matter what */
1801 } 1875 }
1802 1876
1803 stat_timer_cb (EV_P_ &w->timer, 0); 1877 stat_timer_cb (EV_A_ &w->timer, 0);
1804 } 1878 }
1805 } 1879 }
1806 } 1880 }
1807} 1881}
1808 1882
1832 ev_set_priority (&fs_w, EV_MAXPRI); 1906 ev_set_priority (&fs_w, EV_MAXPRI);
1833 ev_io_start (EV_A_ &fs_w); 1907 ev_io_start (EV_A_ &fs_w);
1834 } 1908 }
1835} 1909}
1836 1910
1911void inline_size
1912infy_fork (EV_P)
1913{
1914 int slot;
1915
1916 if (fs_fd < 0)
1917 return;
1918
1919 close (fs_fd);
1920 fs_fd = inotify_init ();
1921
1922 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot)
1923 {
1924 WL w_ = fs_hash [slot].head;
1925 fs_hash [slot].head = 0;
1926
1927 while (w_)
1928 {
1929 ev_stat *w = (ev_stat *)w_;
1930 w_ = w_->next; /* lets us add this watcher */
1931
1932 w->wd = -1;
1933
1934 if (fs_fd >= 0)
1935 infy_add (EV_A_ w); /* re-add, no matter what */
1936 else
1937 ev_timer_start (EV_A_ &w->timer);
1938 }
1939
1940 }
1941}
1942
1837#endif 1943#endif
1838 1944
1839void 1945void
1840ev_stat_stat (EV_P_ ev_stat *w) 1946ev_stat_stat (EV_P_ ev_stat *w)
1841{ 1947{
1843 w->attr.st_nlink = 0; 1949 w->attr.st_nlink = 0;
1844 else if (!w->attr.st_nlink) 1950 else if (!w->attr.st_nlink)
1845 w->attr.st_nlink = 1; 1951 w->attr.st_nlink = 1;
1846} 1952}
1847 1953
1848void noinline 1954static void noinline
1849stat_timer_cb (EV_P_ ev_timer *w_, int revents) 1955stat_timer_cb (EV_P_ ev_timer *w_, int revents)
1850{ 1956{
1851 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 1957 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
1852 1958
1853 /* we copy this here each the time so that */ 1959 /* we copy this here each the time so that */
1854 /* prev has the old value when the callback gets invoked */ 1960 /* prev has the old value when the callback gets invoked */
1855 w->prev = w->attr; 1961 w->prev = w->attr;
1856 ev_stat_stat (EV_A_ w); 1962 ev_stat_stat (EV_A_ w);
1857 1963
1858 if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata))) 1964 /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */
1965 if (
1966 w->prev.st_dev != w->attr.st_dev
1967 || w->prev.st_ino != w->attr.st_ino
1968 || w->prev.st_mode != w->attr.st_mode
1969 || w->prev.st_nlink != w->attr.st_nlink
1970 || w->prev.st_uid != w->attr.st_uid
1971 || w->prev.st_gid != w->attr.st_gid
1972 || w->prev.st_rdev != w->attr.st_rdev
1973 || w->prev.st_size != w->attr.st_size
1974 || w->prev.st_atime != w->attr.st_atime
1975 || w->prev.st_mtime != w->attr.st_mtime
1976 || w->prev.st_ctime != w->attr.st_ctime
1859 { 1977 ) {
1860 #if EV_USE_INOTIFY 1978 #if EV_USE_INOTIFY
1861 infy_del (EV_A_ w); 1979 infy_del (EV_A_ w);
1862 infy_add (EV_A_ w); 1980 infy_add (EV_A_ w);
1863 ev_stat_stat (EV_A_ w); /* avoid race... */ 1981 ev_stat_stat (EV_A_ w); /* avoid race... */
1864 #endif 1982 #endif
1911 2029
1912 ev_stop (EV_A_ (W)w); 2030 ev_stop (EV_A_ (W)w);
1913} 2031}
1914#endif 2032#endif
1915 2033
2034#if EV_IDLE_ENABLE
1916void 2035void
1917ev_idle_start (EV_P_ ev_idle *w) 2036ev_idle_start (EV_P_ ev_idle *w)
1918{ 2037{
1919 if (expect_false (ev_is_active (w))) 2038 if (expect_false (ev_is_active (w)))
1920 return; 2039 return;
1921 2040
2041 pri_adjust (EV_A_ (W)w);
2042
2043 {
2044 int active = ++idlecnt [ABSPRI (w)];
2045
2046 ++idleall;
1922 ev_start (EV_A_ (W)w, ++idlecnt); 2047 ev_start (EV_A_ (W)w, active);
2048
1923 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); 2049 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2);
1924 idles [idlecnt - 1] = w; 2050 idles [ABSPRI (w)][active - 1] = w;
2051 }
1925} 2052}
1926 2053
1927void 2054void
1928ev_idle_stop (EV_P_ ev_idle *w) 2055ev_idle_stop (EV_P_ ev_idle *w)
1929{ 2056{
1931 if (expect_false (!ev_is_active (w))) 2058 if (expect_false (!ev_is_active (w)))
1932 return; 2059 return;
1933 2060
1934 { 2061 {
1935 int active = ((W)w)->active; 2062 int active = ((W)w)->active;
1936 idles [active - 1] = idles [--idlecnt]; 2063
2064 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
1937 ((W)idles [active - 1])->active = active; 2065 ((W)idles [ABSPRI (w)][active - 1])->active = active;
2066
2067 ev_stop (EV_A_ (W)w);
2068 --idleall;
1938 } 2069 }
1939
1940 ev_stop (EV_A_ (W)w);
1941} 2070}
2071#endif
1942 2072
1943void 2073void
1944ev_prepare_start (EV_P_ ev_prepare *w) 2074ev_prepare_start (EV_P_ ev_prepare *w)
1945{ 2075{
1946 if (expect_false (ev_is_active (w))) 2076 if (expect_false (ev_is_active (w)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines