… | |
… | |
870 | select (0, 0, 0, 0, &tv); |
870 | select (0, 0, 0, 0, &tv); |
871 | #endif |
871 | #endif |
872 | } |
872 | } |
873 | } |
873 | } |
874 | |
874 | |
875 | inline_speed int |
|
|
876 | ev_timeout_to_ms (ev_tstamp timeout) |
|
|
877 | { |
|
|
878 | int ms = timeout * 1000. + .999999; |
|
|
879 | |
|
|
880 | return expect_true (ms) ? ms : timeout < 1e-6 ? 0 : 1; |
|
|
881 | } |
|
|
882 | |
|
|
883 | /*****************************************************************************/ |
875 | /*****************************************************************************/ |
884 | |
876 | |
885 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
877 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
886 | |
878 | |
887 | /* find a suitable new size for the given array, */ |
879 | /* find a suitable new size for the given array, */ |
… | |
… | |
1034 | for (i = 0; i < fdchangecnt; ++i) |
1026 | for (i = 0; i < fdchangecnt; ++i) |
1035 | { |
1027 | { |
1036 | int fd = fdchanges [i]; |
1028 | int fd = fdchanges [i]; |
1037 | ANFD *anfd = anfds + fd; |
1029 | ANFD *anfd = anfds + fd; |
1038 | |
1030 | |
1039 | if (anfd->reify & EV__IOFDSET) |
1031 | if (anfd->reify & EV__IOFDSET && anfd->head) |
1040 | { |
1032 | { |
1041 | SOCKET handle = EV_FD_TO_WIN32_HANDLE (fd); |
1033 | SOCKET handle = EV_FD_TO_WIN32_HANDLE (fd); |
1042 | |
1034 | |
1043 | if (handle != anfd->handle) |
1035 | if (handle != anfd->handle) |
1044 | { |
1036 | { |
… | |
… | |
2513 | { |
2505 | { |
2514 | waittime = MAX_BLOCKTIME; |
2506 | waittime = MAX_BLOCKTIME; |
2515 | |
2507 | |
2516 | if (timercnt) |
2508 | if (timercnt) |
2517 | { |
2509 | { |
2518 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
2510 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; |
2519 | if (waittime > to) waittime = to; |
2511 | if (waittime > to) waittime = to; |
2520 | } |
2512 | } |
2521 | |
2513 | |
2522 | #if EV_PERIODIC_ENABLE |
2514 | #if EV_PERIODIC_ENABLE |
2523 | if (periodiccnt) |
2515 | if (periodiccnt) |
2524 | { |
2516 | { |
2525 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
2517 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now; |
2526 | if (waittime > to) waittime = to; |
2518 | if (waittime > to) waittime = to; |
2527 | } |
2519 | } |
2528 | #endif |
2520 | #endif |
2529 | |
2521 | |
2530 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
2522 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
2531 | if (expect_false (waittime < timeout_blocktime)) |
2523 | if (expect_false (waittime < timeout_blocktime)) |
2532 | waittime = timeout_blocktime; |
2524 | waittime = timeout_blocktime; |
|
|
2525 | |
|
|
2526 | /* at this point, we NEED to wait, so we have to ensure */ |
|
|
2527 | /* to pass a minimum nonzero value to the backend */ |
|
|
2528 | if (expect_false (waittime < backend_mintime)) |
|
|
2529 | waittime = backend_mintime; |
2533 | |
2530 | |
2534 | /* extra check because io_blocktime is commonly 0 */ |
2531 | /* extra check because io_blocktime is commonly 0 */ |
2535 | if (expect_false (io_blocktime)) |
2532 | if (expect_false (io_blocktime)) |
2536 | { |
2533 | { |
2537 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
2534 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
2538 | |
2535 | |
2539 | if (sleeptime > waittime - backend_fudge) |
2536 | if (sleeptime > waittime - backend_mintime) |
2540 | sleeptime = waittime - backend_fudge; |
2537 | sleeptime = waittime - backend_mintime; |
2541 | |
2538 | |
2542 | if (expect_true (sleeptime > 0.)) |
2539 | if (expect_true (sleeptime > 0.)) |
2543 | { |
2540 | { |
2544 | ev_sleep (sleeptime); |
2541 | ev_sleep (sleeptime); |
2545 | waittime -= sleeptime; |
2542 | waittime -= sleeptime; |