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 struct timespec req; // requested. |
| 414 struct timespec rem; // remainder. |
| 415 int64_t seconds = micros / kMicrosecondsPerSecond; |
| 416 micros = micros - seconds * kMicrosecondsPerSecond; |
| 417 int64_t nanos = micros * kNanosecondsPerMicrosecond; |
| 418 req.tv_sec = seconds; |
| 419 req.tv_nsec = nanos; |
| 420 while (true) { |
| 421 int r = nanosleep(&req, &rem); |
| 422 if (r == 0) { |
| 423 break; |
| 424 } |
| 425 // We should only ever see an interrupt error. |
| 426 ASSERT(errno == EINTR); |
| 427 // Copy remainder into requested and repeat. |
| 428 req = rem; |
| 429 } |
| 430 } |
| 431 |
| 432 |
412 void OS::DebugBreak() { | 433 void OS::DebugBreak() { |
413 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) | 434 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) |
414 asm("int $3"); | 435 asm("int $3"); |
415 #elif defined(HOST_ARCH_ARM) | 436 #elif defined(HOST_ARCH_ARM) |
416 asm("svc #0x9f0001"); // __ARM_NR_breakpoint | 437 asm("svc #0x9f0001"); // __ARM_NR_breakpoint |
417 #elif defined(HOST_ARCH_MIPS) | 438 #elif defined(HOST_ARCH_MIPS) |
418 UNIMPLEMENTED(); | 439 UNIMPLEMENTED(); |
419 #else | 440 #else |
420 #error Unsupported architecture. | 441 #error Unsupported architecture. |
421 #endif | 442 #endif |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 } | 545 } |
525 | 546 |
526 | 547 |
527 void OS::Exit(int code) { | 548 void OS::Exit(int code) { |
528 exit(code); | 549 exit(code); |
529 } | 550 } |
530 | 551 |
531 } // namespace dart | 552 } // namespace dart |
532 | 553 |
533 #endif // defined(TARGET_OS_LINUX) | 554 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |