Use busy-waiting instead of short Sleep on Windows.
This commit is contained in:
parent
7a233f25eb
commit
e87e18c8be
@ -14,14 +14,23 @@
|
|||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
|
#include "td/utils/port/Clocks.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
void usleep_for(int32 microseconds) {
|
void usleep_for(int32 microseconds) {
|
||||||
#if TD_PORT_WINDOWS
|
#if TD_PORT_WINDOWS
|
||||||
int32 milliseconds = microseconds / 1000 + (microseconds % 1000 ? 1 : 0);
|
if (microseconds < 2000) {
|
||||||
Sleep(milliseconds);
|
auto end_time = Clocks::monotonic() + microseconds * 1e-6;
|
||||||
|
do {
|
||||||
|
SwitchToThread();
|
||||||
|
} while (Clocks::monotonic() < end_time);
|
||||||
|
} else {
|
||||||
|
int32 milliseconds = microseconds / 1000 + (microseconds % 1000 ? 1 : 0);
|
||||||
|
Sleep(milliseconds);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#if _POSIX_C_SOURCE >= 199309L
|
#if _POSIX_C_SOURCE >= 199309L
|
||||||
timespec ts;
|
timespec ts;
|
||||||
|
Loading…
Reference in New Issue
Block a user