Index: runtime/vm/os_linux.cc |
diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc |
index ed1d6685f627a660510662893cb7e3d61354d1e6..f3e0fc9f1c1431b98f3d49fe30eb90ab13fcf73d 100644 |
--- a/runtime/vm/os_linux.cc |
+++ b/runtime/vm/os_linux.cc |
@@ -404,8 +404,22 @@ int OS::NumberOfAvailableProcessors() { |
void OS::Sleep(int64_t millis) { |
- // TODO(5411554): For now just use usleep we may have to revisit this. |
- usleep(millis * 1000); |
+ int64_t micros = millis * kMicrosecondsPerMillisecond; |
+ SleepMicros(micros); |
+} |
+ |
+ |
+void OS::SleepMicros(int64_t micros) { |
+ // We must loop here because SIGPROF will interrupt usleep. |
+ int64_t start = GetCurrentTimeMicros(); |
+ while (micros > 0) { |
+ usleep(micros); |
+ int64_t now = GetCurrentTimeMicros(); |
+ int64_t delta = now - start; |
+ ASSERT(delta >= 0); |
+ start = now; |
+ micros -= delta; |
+ } |
} |