… | |
… | |
886 | ev_backend (EV_P) |
886 | ev_backend (EV_P) |
887 | { |
887 | { |
888 | return backend; |
888 | return backend; |
889 | } |
889 | } |
890 | |
890 | |
|
|
891 | unsigned int |
|
|
892 | ev_loop_count (EV_P) |
|
|
893 | { |
|
|
894 | return loop_count; |
|
|
895 | } |
|
|
896 | |
891 | static void noinline |
897 | static void noinline |
892 | loop_init (EV_P_ unsigned int flags) |
898 | loop_init (EV_P_ unsigned int flags) |
893 | { |
899 | { |
894 | if (!backend) |
900 | if (!backend) |
895 | { |
901 | { |
… | |
… | |
903 | |
909 | |
904 | ev_rt_now = ev_time (); |
910 | ev_rt_now = ev_time (); |
905 | mn_now = get_clock (); |
911 | mn_now = get_clock (); |
906 | now_floor = mn_now; |
912 | now_floor = mn_now; |
907 | 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 |
908 | |
920 | |
909 | if (!(flags & EVFLAG_NOENV) |
921 | if (!(flags & EVFLAG_NOENV) |
910 | && !enable_secure () |
922 | && !enable_secure () |
911 | && getenv ("LIBEV_FLAGS")) |
923 | && getenv ("LIBEV_FLAGS")) |
912 | flags = atoi (getenv ("LIBEV_FLAGS")); |
924 | flags = atoi (getenv ("LIBEV_FLAGS")); |
… | |
… | |
1334 | { |
1346 | { |
1335 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1347 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1336 | ? EVUNLOOP_ONE |
1348 | ? EVUNLOOP_ONE |
1337 | : EVUNLOOP_CANCEL; |
1349 | : EVUNLOOP_CANCEL; |
1338 | |
1350 | |
1339 | while (activecnt) |
1351 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
|
|
1352 | |
|
|
1353 | do |
1340 | { |
1354 | { |
|
|
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 | |
1341 | #if EV_FORK_ENABLE |
1364 | #if EV_FORK_ENABLE |
1342 | /* we might have forked, so queue fork handlers */ |
1365 | /* we might have forked, so queue fork handlers */ |
1343 | if (expect_false (postfork)) |
1366 | if (expect_false (postfork)) |
1344 | if (forkcnt) |
1367 | if (forkcnt) |
1345 | { |
1368 | { |
… | |
… | |
1353 | { |
1376 | { |
1354 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1377 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1355 | call_pending (EV_A); |
1378 | call_pending (EV_A); |
1356 | } |
1379 | } |
1357 | |
1380 | |
|
|
1381 | if (expect_false (!activecnt)) |
|
|
1382 | break; |
|
|
1383 | |
1358 | /* we might have forked, so reify kernel state if necessary */ |
1384 | /* we might have forked, so reify kernel state if necessary */ |
1359 | if (expect_false (postfork)) |
1385 | if (expect_false (postfork)) |
1360 | loop_fork (EV_A); |
1386 | loop_fork (EV_A); |
1361 | |
1387 | |
1362 | /* update fd-related kernel structures */ |
1388 | /* update fd-related kernel structures */ |
… | |
… | |
1364 | |
1390 | |
1365 | /* calculate blocking time */ |
1391 | /* calculate blocking time */ |
1366 | { |
1392 | { |
1367 | ev_tstamp block; |
1393 | ev_tstamp block; |
1368 | |
1394 | |
1369 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
1395 | if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) |
1370 | block = 0.; /* do not block at all */ |
1396 | block = 0.; /* do not block at all */ |
1371 | else |
1397 | else |
1372 | { |
1398 | { |
1373 | /* update time to cancel out callback processing overhead */ |
1399 | /* update time to cancel out callback processing overhead */ |
1374 | #if EV_USE_MONOTONIC |
1400 | #if EV_USE_MONOTONIC |
… | |
… | |
1398 | #endif |
1424 | #endif |
1399 | |
1425 | |
1400 | if (expect_false (block < 0.)) block = 0.; |
1426 | if (expect_false (block < 0.)) block = 0.; |
1401 | } |
1427 | } |
1402 | |
1428 | |
|
|
1429 | ++loop_count; |
1403 | backend_poll (EV_A_ block); |
1430 | backend_poll (EV_A_ block); |
1404 | } |
1431 | } |
1405 | |
1432 | |
1406 | /* update ev_rt_now, do magic */ |
1433 | /* update ev_rt_now, do magic */ |
1407 | time_update (EV_A); |
1434 | time_update (EV_A); |
… | |
… | |
1420 | if (expect_false (checkcnt)) |
1447 | if (expect_false (checkcnt)) |
1421 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1448 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1422 | |
1449 | |
1423 | call_pending (EV_A); |
1450 | call_pending (EV_A); |
1424 | |
1451 | |
1425 | if (expect_false (loop_done)) |
|
|
1426 | break; |
|
|
1427 | } |
1452 | } |
|
|
1453 | while (expect_true (activecnt && !loop_done)); |
1428 | |
1454 | |
1429 | if (loop_done == EVUNLOOP_ONE) |
1455 | if (loop_done == EVUNLOOP_ONE) |
1430 | loop_done = EVUNLOOP_CANCEL; |
1456 | loop_done = EVUNLOOP_CANCEL; |
1431 | } |
1457 | } |
1432 | |
1458 | |