| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return retval; | 397 return retval; |
| 398 } | 398 } |
| 399 | 399 |
| 400 | 400 |
| 401 int OS::NumberOfAvailableProcessors() { | 401 int OS::NumberOfAvailableProcessors() { |
| 402 return sysconf(_SC_NPROCESSORS_ONLN); | 402 return sysconf(_SC_NPROCESSORS_ONLN); |
| 403 } | 403 } |
| 404 | 404 |
| 405 | 405 |
| 406 void OS::Sleep(int64_t millis) { | 406 void OS::Sleep(int64_t millis) { |
| 407 // TODO(5411554): For now just use usleep we may have to revisit this. | 407 int64_t micros = millis * kMicrosecondsPerMillisecond; |
| 408 usleep(millis * 1000); | 408 SleepMicros(micros); |
| 409 } | 409 } |
| 410 | 410 |
| 411 | 411 |
| 412 void OS::SleepMicros(int64_t micros) { |
| 413 // We must loop here because SIGPROF will interrupt usleep. |
| 414 int64_t start = GetCurrentTimeMicros(); |
| 415 while (micros > 0) { |
| 416 usleep(micros); |
| 417 int64_t now = GetCurrentTimeMicros(); |
| 418 int64_t delta = now - start; |
| 419 ASSERT(delta >= 0); |
| 420 start = now; |
| 421 micros -= delta; |
| 422 } |
| 423 } |
| 424 |
| 425 |
| 412 void OS::DebugBreak() { | 426 void OS::DebugBreak() { |
| 413 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) | 427 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) |
| 414 asm("int $3"); | 428 asm("int $3"); |
| 415 #elif defined(HOST_ARCH_ARM) | 429 #elif defined(HOST_ARCH_ARM) |
| 416 asm("svc #0x9f0001"); // __ARM_NR_breakpoint | 430 asm("svc #0x9f0001"); // __ARM_NR_breakpoint |
| 417 #elif defined(HOST_ARCH_MIPS) | 431 #elif defined(HOST_ARCH_MIPS) |
| 418 UNIMPLEMENTED(); | 432 UNIMPLEMENTED(); |
| 419 #else | 433 #else |
| 420 #error Unsupported architecture. | 434 #error Unsupported architecture. |
| 421 #endif | 435 #endif |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 538 } |
| 525 | 539 |
| 526 | 540 |
| 527 void OS::Exit(int code) { | 541 void OS::Exit(int code) { |
| 528 exit(code); | 542 exit(code); |
| 529 } | 543 } |
| 530 | 544 |
| 531 } // namespace dart | 545 } // namespace dart |
| 532 | 546 |
| 533 #endif // defined(TARGET_OS_LINUX) | 547 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |