| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return retval; | 124 return retval; |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 int OS::NumberOfAvailableProcessors() { | 128 int OS::NumberOfAvailableProcessors() { |
| 129 return sysconf(_SC_NPROCESSORS_ONLN); | 129 return sysconf(_SC_NPROCESSORS_ONLN); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 void OS::Sleep(int64_t millis) { | 133 void OS::Sleep(int64_t millis) { |
| 134 // TODO(5411554): For now just use usleep we may have to revisit this. | 134 int64_t micros = millis * kMicrosecondsPerMillisecond; |
| 135 usleep(millis * 1000); | 135 SleepMicros(micros); |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 void OS::SleepMicros(int64_t micros) { |
| 140 struct timespec req; // requested. |
| 141 struct timespec rem; // remainder. |
| 142 int64_t seconds = micros / kMicrosecondsPerSecond; |
| 143 micros = micros - seconds * kMicrosecondsPerSecond; |
| 144 int64_t nanos = micros * kNanosecondsPerMicrosecond; |
| 145 req.tv_sec = seconds; |
| 146 req.tv_nsec = nanos; |
| 147 while (true) { |
| 148 int r = nanosleep(&req, &rem); |
| 149 if (r == 0) { |
| 150 break; |
| 151 } |
| 152 // We should only ever see an interrupt error. |
| 153 ASSERT(errno == EINTR); |
| 154 // Copy remainder into requested and repeat. |
| 155 req = rem; |
| 156 } |
| 157 } |
| 158 |
| 159 |
| 139 void OS::DebugBreak() { | 160 void OS::DebugBreak() { |
| 140 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) | 161 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) |
| 141 asm("int $3"); | 162 asm("int $3"); |
| 142 #else | 163 #else |
| 143 #error Unsupported architecture. | 164 #error Unsupported architecture. |
| 144 #endif | 165 #endif |
| 145 } | 166 } |
| 146 | 167 |
| 147 | 168 |
| 148 char* OS::StrNDup(const char* s, intptr_t n) { | 169 char* OS::StrNDup(const char* s, intptr_t n) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 272 } |
| 252 | 273 |
| 253 | 274 |
| 254 void OS::Exit(int code) { | 275 void OS::Exit(int code) { |
| 255 exit(code); | 276 exit(code); |
| 256 } | 277 } |
| 257 | 278 |
| 258 } // namespace dart | 279 } // namespace dart |
| 259 | 280 |
| 260 #endif // defined(TARGET_OS_MACOS) | 281 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |