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