| 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // gettimeofday has microsecond resolution. | 389 // gettimeofday has microsecond resolution. |
| 390 struct timeval tv; | 390 struct timeval tv; |
| 391 if (gettimeofday(&tv, NULL) < 0) { | 391 if (gettimeofday(&tv, NULL) < 0) { |
| 392 UNREACHABLE(); | 392 UNREACHABLE(); |
| 393 return 0; | 393 return 0; |
| 394 } | 394 } |
| 395 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; | 395 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; |
| 396 } | 396 } |
| 397 | 397 |
| 398 | 398 |
| 399 int64_t OS::GetCurrentMonotonicMicros() { | 399 int64_t OS::GetCurrentMonotonicTicks() { |
| 400 struct timespec ts; | 400 struct timespec ts; |
| 401 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 401 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
| 402 UNREACHABLE(); | 402 UNREACHABLE(); |
| 403 return 0; | 403 return 0; |
| 404 } | 404 } |
| 405 // Convert to microseconds. | 405 // Convert to nanoseconds. |
| 406 int64_t result = ts.tv_sec; | 406 int64_t result = ts.tv_sec; |
| 407 result *= kMicrosecondsPerSecond; | 407 result *= kNanosecondsPerSecond; |
| 408 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); | 408 result += ts.tv_nsec; |
| 409 return result; | 409 return result; |
| 410 } | 410 } |
| 411 | 411 |
| 412 | 412 |
| 413 int64_t OS::GetCurrentMonotonicFrequency() { |
| 414 return kNanosecondsPerSecond; |
| 415 } |
| 416 |
| 417 |
| 418 int64_t OS::GetCurrentMonotonicMicros() { |
| 419 int64_t ticks = GetCurrentMonotonicTicks(); |
| 420 ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond); |
| 421 return ticks / kNanosecondsPerMicrosecond; |
| 422 } |
| 423 |
| 424 |
| 413 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { | 425 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { |
| 414 const int kMinimumAlignment = 16; | 426 const int kMinimumAlignment = 16; |
| 415 ASSERT(Utils::IsPowerOfTwo(alignment)); | 427 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 416 ASSERT(alignment >= kMinimumAlignment); | 428 ASSERT(alignment >= kMinimumAlignment); |
| 417 void* p = memalign(alignment, size); | 429 void* p = memalign(alignment, size); |
| 418 if (p == NULL) { | 430 if (p == NULL) { |
| 419 UNREACHABLE(); | 431 UNREACHABLE(); |
| 420 } | 432 } |
| 421 return p; | 433 return p; |
| 422 } | 434 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 } | 659 } |
| 648 | 660 |
| 649 | 661 |
| 650 void OS::Exit(int code) { | 662 void OS::Exit(int code) { |
| 651 exit(code); | 663 exit(code); |
| 652 } | 664 } |
| 653 | 665 |
| 654 } // namespace dart | 666 } // namespace dart |
| 655 | 667 |
| 656 #endif // defined(TARGET_OS_LINUX) | 668 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |