… | |
… | |
589 | static void noinline |
589 | static void noinline |
590 | fd_rearm_all (EV_P) |
590 | fd_rearm_all (EV_P) |
591 | { |
591 | { |
592 | int fd; |
592 | int fd; |
593 | |
593 | |
594 | /* this should be highly optimised to not do anything but set a flag */ |
|
|
595 | for (fd = 0; fd < anfdmax; ++fd) |
594 | for (fd = 0; fd < anfdmax; ++fd) |
596 | if (anfds [fd].events) |
595 | if (anfds [fd].events) |
597 | { |
596 | { |
598 | anfds [fd].events = 0; |
597 | anfds [fd].events = 0; |
599 | fd_change (EV_A_ fd); |
598 | fd_change (EV_A_ fd); |
… | |
… | |
887 | ev_backend (EV_P) |
886 | ev_backend (EV_P) |
888 | { |
887 | { |
889 | return backend; |
888 | return backend; |
890 | } |
889 | } |
891 | |
890 | |
|
|
891 | unsigned int |
|
|
892 | ev_loop_count (EV_P) |
|
|
893 | { |
|
|
894 | return loop_count; |
|
|
895 | } |
|
|
896 | |
892 | static void noinline |
897 | static void noinline |
893 | loop_init (EV_P_ unsigned int flags) |
898 | loop_init (EV_P_ unsigned int flags) |
894 | { |
899 | { |
895 | if (!backend) |
900 | if (!backend) |
896 | { |
901 | { |
… | |
… | |
904 | |
909 | |
905 | ev_rt_now = ev_time (); |
910 | ev_rt_now = ev_time (); |
906 | mn_now = get_clock (); |
911 | mn_now = get_clock (); |
907 | now_floor = mn_now; |
912 | now_floor = mn_now; |
908 | rtmn_diff = ev_rt_now - mn_now; |
913 | rtmn_diff = ev_rt_now - mn_now; |
|
|
914 | |
|
|
915 | /* pid check not overridable via env */ |
|
|
916 | #ifndef _WIN32 |
|
|
917 | if (flags & EVFLAG_FORKCHECK) |
|
|
918 | curpid = getpid (); |
|
|
919 | #endif |
909 | |
920 | |
910 | if (!(flags & EVFLAG_NOENV) |
921 | if (!(flags & EVFLAG_NOENV) |
911 | && !enable_secure () |
922 | && !enable_secure () |
912 | && getenv ("LIBEV_FLAGS")) |
923 | && getenv ("LIBEV_FLAGS")) |
913 | flags = atoi (getenv ("LIBEV_FLAGS")); |
924 | flags = atoi (getenv ("LIBEV_FLAGS")); |
… | |
… | |
1270 | ev_tstamp odiff = rtmn_diff; |
1281 | ev_tstamp odiff = rtmn_diff; |
1271 | |
1282 | |
1272 | /* loop a few times, before making important decisions. |
1283 | /* loop a few times, before making important decisions. |
1273 | * on the choice of "4": one iteration isn't enough, |
1284 | * on the choice of "4": one iteration isn't enough, |
1274 | * in case we get preempted during the calls to |
1285 | * in case we get preempted during the calls to |
1275 | * ev_time and get_clock. a second call is almost guarenteed |
1286 | * ev_time and get_clock. a second call is almost guaranteed |
1276 | * to succeed in that case, though. and looping a few more times |
1287 | * 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 |
1288 | * doesn't hurt either as we only do this on time-jumps or |
1278 | * in the unlikely event of getting preempted here. |
1289 | * in the unlikely event of having been preempted here. |
1279 | */ |
1290 | */ |
1280 | for (i = 4; --i; ) |
1291 | for (i = 4; --i; ) |
1281 | { |
1292 | { |
1282 | rtmn_diff = ev_rt_now - mn_now; |
1293 | rtmn_diff = ev_rt_now - mn_now; |
1283 | |
1294 | |
… | |
… | |
1305 | { |
1316 | { |
1306 | #if EV_PERIODIC_ENABLE |
1317 | #if EV_PERIODIC_ENABLE |
1307 | periodics_reschedule (EV_A); |
1318 | periodics_reschedule (EV_A); |
1308 | #endif |
1319 | #endif |
1309 | |
1320 | |
1310 | /* adjust timers. this is easy, as the offset is the same for all */ |
1321 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1311 | for (i = 0; i < timercnt; ++i) |
1322 | for (i = 0; i < timercnt; ++i) |
1312 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1323 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1313 | } |
1324 | } |
1314 | |
1325 | |
1315 | mn_now = ev_rt_now; |
1326 | mn_now = ev_rt_now; |
… | |
… | |
1335 | { |
1346 | { |
1336 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1347 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1337 | ? EVUNLOOP_ONE |
1348 | ? EVUNLOOP_ONE |
1338 | : EVUNLOOP_CANCEL; |
1349 | : EVUNLOOP_CANCEL; |
1339 | |
1350 | |
1340 | while (activecnt) |
1351 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
|
|
1352 | |
|
|
1353 | do |
1341 | { |
1354 | { |
1342 | /* we might have forked, so reify kernel state if necessary */ |
1355 | #ifndef _WIN32 |
|
|
1356 | if (expect_false (curpid)) /* penalise the forking check even more */ |
|
|
1357 | if (expect_false (getpid () != curpid)) |
|
|
1358 | { |
|
|
1359 | curpid = getpid (); |
|
|
1360 | postfork = 1; |
|
|
1361 | } |
|
|
1362 | #endif |
|
|
1363 | |
1343 | #if EV_FORK_ENABLE |
1364 | #if EV_FORK_ENABLE |
|
|
1365 | /* we might have forked, so queue fork handlers */ |
1344 | if (expect_false (postfork)) |
1366 | if (expect_false (postfork)) |
1345 | if (forkcnt) |
1367 | if (forkcnt) |
1346 | { |
1368 | { |
1347 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
1369 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
1348 | call_pending (EV_A); |
1370 | call_pending (EV_A); |
1349 | } |
1371 | } |
1350 | #endif |
1372 | #endif |
1351 | |
1373 | |
1352 | /* queue check watchers (and execute them) */ |
1374 | /* queue check watchers (and execute them) */ |
1353 | if (expect_false (preparecnt)) |
1375 | if (expect_false (preparecnt)) |
1354 | { |
1376 | { |
1355 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1377 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1356 | call_pending (EV_A); |
1378 | call_pending (EV_A); |
1357 | } |
1379 | } |
1358 | |
1380 | |
|
|
1381 | if (expect_false (!activecnt)) |
|
|
1382 | break; |
|
|
1383 | |
1359 | /* we might have forked, so reify kernel state if necessary */ |
1384 | /* we might have forked, so reify kernel state if necessary */ |
1360 | if (expect_false (postfork)) |
1385 | if (expect_false (postfork)) |
1361 | loop_fork (EV_A); |
1386 | loop_fork (EV_A); |
1362 | |
1387 | |
1363 | /* update fd-related kernel structures */ |
1388 | /* update fd-related kernel structures */ |
1364 | fd_reify (EV_A); |
1389 | fd_reify (EV_A); |
1365 | |
1390 | |
1366 | /* calculate blocking time */ |
1391 | /* calculate blocking time */ |
1367 | { |
1392 | { |
1368 | double block; |
1393 | ev_tstamp block; |
1369 | |
1394 | |
1370 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
1395 | if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) |
1371 | block = 0.; /* do not block at all */ |
1396 | block = 0.; /* do not block at all */ |
1372 | else |
1397 | else |
1373 | { |
1398 | { |
1374 | /* update time to cancel out callback processing overhead */ |
1399 | /* update time to cancel out callback processing overhead */ |
1375 | #if EV_USE_MONOTONIC |
1400 | #if EV_USE_MONOTONIC |
… | |
… | |
1399 | #endif |
1424 | #endif |
1400 | |
1425 | |
1401 | if (expect_false (block < 0.)) block = 0.; |
1426 | if (expect_false (block < 0.)) block = 0.; |
1402 | } |
1427 | } |
1403 | |
1428 | |
|
|
1429 | ++loop_count; |
1404 | backend_poll (EV_A_ block); |
1430 | backend_poll (EV_A_ block); |
1405 | } |
1431 | } |
1406 | |
1432 | |
1407 | /* update ev_rt_now, do magic */ |
1433 | /* update ev_rt_now, do magic */ |
1408 | time_update (EV_A); |
1434 | time_update (EV_A); |
… | |
… | |
1421 | if (expect_false (checkcnt)) |
1447 | if (expect_false (checkcnt)) |
1422 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1448 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1423 | |
1449 | |
1424 | call_pending (EV_A); |
1450 | call_pending (EV_A); |
1425 | |
1451 | |
1426 | if (expect_false (loop_done)) |
|
|
1427 | break; |
|
|
1428 | } |
1452 | } |
|
|
1453 | while (expect_true (activecnt && !loop_done)); |
1429 | |
1454 | |
1430 | if (loop_done == EVUNLOOP_ONE) |
1455 | if (loop_done == EVUNLOOP_ONE) |
1431 | loop_done = EVUNLOOP_CANCEL; |
1456 | loop_done = EVUNLOOP_CANCEL; |
1432 | } |
1457 | } |
1433 | |
1458 | |
… | |
… | |
1718 | # endif |
1743 | # endif |
1719 | |
1744 | |
1720 | #define DEF_STAT_INTERVAL 5.0074891 |
1745 | #define DEF_STAT_INTERVAL 5.0074891 |
1721 | #define MIN_STAT_INTERVAL 0.1074891 |
1746 | #define MIN_STAT_INTERVAL 0.1074891 |
1722 | |
1747 | |
1723 | void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
1748 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
1724 | |
1749 | |
1725 | #if EV_USE_INOTIFY |
1750 | #if EV_USE_INOTIFY |
1726 | # define EV_INOTIFY_BUFSIZE 8192 |
1751 | # define EV_INOTIFY_BUFSIZE 8192 |
1727 | |
1752 | |
1728 | static void noinline |
1753 | static void noinline |
… | |
… | |
1879 | w->attr.st_nlink = 0; |
1904 | w->attr.st_nlink = 0; |
1880 | else if (!w->attr.st_nlink) |
1905 | else if (!w->attr.st_nlink) |
1881 | w->attr.st_nlink = 1; |
1906 | w->attr.st_nlink = 1; |
1882 | } |
1907 | } |
1883 | |
1908 | |
1884 | void noinline |
1909 | static void noinline |
1885 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
1910 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
1886 | { |
1911 | { |
1887 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
1912 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
1888 | |
1913 | |
1889 | /* we copy this here each the time so that */ |
1914 | /* we copy this here each the time so that */ |