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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 struct timeval boottime; | 102 struct timeval boottime; |
103 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; | 103 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; |
104 size_t size = sizeof(boottime); | 104 size_t size = sizeof(boottime); |
105 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0); | 105 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0); |
106 ASSERT(KERN_SUCCESS == kr); | 106 ASSERT(KERN_SUCCESS == kr); |
107 int64_t now = GetCurrentTimeMicros(); | 107 int64_t now = GetCurrentTimeMicros(); |
108 int64_t origin = boottime.tv_sec * kMicrosecondsPerSecond; | 108 int64_t origin = boottime.tv_sec * kMicrosecondsPerSecond; |
109 origin += boottime.tv_usec; | 109 origin += boottime.tv_usec; |
110 return now - origin; | 110 return now - origin; |
111 #else | 111 #else |
| 112 if (timebase_info.denom == 0) { |
| 113 kern_return_t kr = mach_timebase_info(&timebase_info); |
| 114 ASSERT(KERN_SUCCESS == kr); |
| 115 } |
112 ASSERT(timebase_info.denom != 0); | 116 ASSERT(timebase_info.denom != 0); |
113 // timebase_info converts absolute time tick units into nanoseconds. | 117 // timebase_info converts absolute time tick units into nanoseconds. |
114 int64_t result = mach_absolute_time(); | 118 int64_t result = mach_absolute_time(); |
115 result *= timebase_info.numer; | 119 result *= timebase_info.numer; |
116 result /= timebase_info.denom; | 120 result /= timebase_info.denom; |
117 return result; | 121 return result; |
118 #endif // TARGET_OS_IOS | 122 #endif // TARGET_OS_IOS |
119 } | 123 } |
120 | 124 |
121 | 125 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 426 } |
423 | 427 |
424 | 428 |
425 void OS::InitOnce() { | 429 void OS::InitOnce() { |
426 // TODO(5411554): For now we check that initonce is called only once, | 430 // TODO(5411554): For now we check that initonce is called only once, |
427 // Once there is more formal mechanism to call InitOnce we can move | 431 // Once there is more formal mechanism to call InitOnce we can move |
428 // this check there. | 432 // this check there. |
429 static bool init_once_called = false; | 433 static bool init_once_called = false; |
430 ASSERT(init_once_called == false); | 434 ASSERT(init_once_called == false); |
431 init_once_called = true; | 435 init_once_called = true; |
432 kern_return_t kr = mach_timebase_info(&timebase_info); | |
433 ASSERT(KERN_SUCCESS == kr); | |
434 } | 436 } |
435 | 437 |
436 | 438 |
437 void OS::Shutdown() { | 439 void OS::Shutdown() { |
438 } | 440 } |
439 | 441 |
440 | 442 |
441 void OS::Abort() { | 443 void OS::Abort() { |
442 abort(); | 444 abort(); |
443 } | 445 } |
444 | 446 |
445 | 447 |
446 void OS::Exit(int code) { | 448 void OS::Exit(int code) { |
447 exit(code); | 449 exit(code); |
448 } | 450 } |
449 | 451 |
450 } // namespace dart | 452 } // namespace dart |
451 | 453 |
452 #endif // defined(TARGET_OS_MACOS) | 454 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |