Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: runtime/bin/utils_fuchsia.cc

Issue 2168193002: Fuchsia: Build standalone VM. Make it run "Hello, World!". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/stdio_fuchsia.cc ('k') | runtime/bin/vmservice/vmservice_io.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_FUCHSIA)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h>
9 #include <netdb.h> // NOLINT 9 #include <magenta/syscalls.h>
10 #include <sys/time.h> // NOLINT 10 #include <magenta/types.h>
11 #include <time.h> // NOLINT
12 11
13 #include "bin/utils.h" 12 #include "bin/utils.h"
14 #include "platform/assert.h" 13 #include "platform/assert.h"
15 #include "platform/utils.h" 14 #include "platform/utils.h"
16 15
17 namespace dart { 16 namespace dart {
18 namespace bin { 17 namespace bin {
19 18
20 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { 19 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) {
21 set_sub_system(kSystem); 20 set_sub_system(kSystem);
22 set_code(errno); 21 set_code(errno);
23 const int kBufferSize = 1024; 22 const int kBufferSize = 1024;
24 char error_buf[kBufferSize]; 23 char error_buf[kBufferSize];
25 SetMessage(Utils::StrError(errno, error_buf, kBufferSize)); 24 SetMessage(Utils::StrError(errno, error_buf, kBufferSize));
26 } 25 }
27 26
28 27
29 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) { 28 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
30 set_sub_system(sub_system); 29 set_sub_system(sub_system);
31 set_code(code); 30 set_code(code);
32 if (sub_system == kSystem) { 31 if (sub_system == kSystem) {
33 const int kBufferSize = 1024; 32 const int kBufferSize = 1024;
34 char error_buf[kBufferSize]; 33 char error_buf[kBufferSize];
35 SetMessage(Utils::StrError(code, error_buf, kBufferSize)); 34 SetMessage(Utils::StrError(code, error_buf, kBufferSize));
36 } else if (sub_system == kGetAddressInfo) { 35 } else if (sub_system == kGetAddressInfo) {
37 SetMessage(gai_strerror(code)); 36 UNIMPLEMENTED();
38 } else { 37 } else {
39 UNREACHABLE(); 38 UNREACHABLE();
40 } 39 }
41 } 40 }
42 41
43 42
44 const char* StringUtils::ConsoleStringToUtf8( 43 const char* StringUtils::ConsoleStringToUtf8(
45 const char* str, intptr_t len, intptr_t* result_len) { 44 const char* str, intptr_t len, intptr_t* result_len) {
46 UNIMPLEMENTED(); 45 UNIMPLEMENTED();
47 return NULL; 46 return NULL;
(...skipping 29 matching lines...) Expand all
77 void TimerUtils::InitOnce() { 76 void TimerUtils::InitOnce() {
78 } 77 }
79 78
80 79
81 int64_t TimerUtils::GetCurrentMonotonicMillis() { 80 int64_t TimerUtils::GetCurrentMonotonicMillis() {
82 return GetCurrentMonotonicMicros() / 1000; 81 return GetCurrentMonotonicMicros() / 1000;
83 } 82 }
84 83
85 84
86 int64_t TimerUtils::GetCurrentMonotonicMicros() { 85 int64_t TimerUtils::GetCurrentMonotonicMicros() {
87 struct timespec ts; 86 int64_t ticks = mx_current_time();
88 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { 87 return ticks / kNanosecondsPerMicrosecond;
89 UNREACHABLE();
90 return 0;
91 }
92 // Convert to microseconds.
93 int64_t result = ts.tv_sec;
94 result *= kMicrosecondsPerSecond;
95 result += (ts.tv_nsec / kNanosecondsPerMicrosecond);
96 return result;
97 } 88 }
98 89
99 90
100 void TimerUtils::Sleep(int64_t millis) { 91 void TimerUtils::Sleep(int64_t millis) {
101 struct timespec req; // requested. 92 mx_nanosleep(
102 struct timespec rem; // remainder. 93 millis * kMicrosecondsPerMillisecond * kNanosecondsPerMicrosecond);
103 int64_t micros = millis * kMicrosecondsPerMillisecond;
104 int64_t seconds = micros / kMicrosecondsPerSecond;
105 micros = micros - seconds * kMicrosecondsPerSecond;
106 int64_t nanos = micros * kNanosecondsPerMicrosecond;
107 req.tv_sec = seconds;
108 req.tv_nsec = nanos;
109 while (true) {
110 int r = nanosleep(&req, &rem);
111 if (r == 0) {
112 break;
113 }
114 // We should only ever see an interrupt error.
115 ASSERT(errno == EINTR);
116 // Copy remainder into requested and repeat.
117 req = rem;
118 }
119 } 94 }
120 95
121 } // namespace bin 96 } // namespace bin
122 } // namespace dart 97 } // namespace dart
123 98
124 #endif // defined(TARGET_OS_LINUX) 99 #endif // defined(TARGET_OS_FUCHSIA)
OLDNEW
« no previous file with comments | « runtime/bin/stdio_fuchsia.cc ('k') | runtime/bin/vmservice/vmservice_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698