Index: runtime/vm/os_macos.cc |
diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc |
index 76d9fb68379dc5caa1e6658cd2fae223744db58f..302ff8af73774a6ceb67ff0f5afeb6f1ff5c52c7 100644 |
--- a/runtime/vm/os_macos.cc |
+++ b/runtime/vm/os_macos.cc |
@@ -131,8 +131,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; |
+ } |
} |