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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
7 | 7 |
8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
9 #include <netdb.h> // NOLINT | 9 #include <netdb.h> // NOLINT |
10 #include <sys/time.h> // NOLINT | 10 #include <sys/time.h> // NOLINT |
11 #include <time.h> // NOLINT | 11 #include <time.h> // NOLINT |
12 | 12 |
13 #include "bin/utils.h" | 13 #include "bin/utils.h" |
14 #include "platform/assert.h" | 14 #include "platform/assert.h" |
15 #include "platform/utils.h" | 15 #include "platform/utils.h" |
16 | 16 |
17 | |
18 namespace dart { | 17 namespace dart { |
19 namespace bin { | 18 namespace bin { |
20 | 19 |
21 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { | 20 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { |
22 set_sub_system(kSystem); | 21 set_sub_system(kSystem); |
23 set_code(errno); | 22 set_code(errno); |
24 const int kBufferSize = 1024; | 23 const int kBufferSize = 1024; |
25 char error_message[kBufferSize]; | 24 char error_message[kBufferSize]; |
26 Utils::StrError(errno, error_message, kBufferSize); | 25 Utils::StrError(errno, error_message, kBufferSize); |
27 SetMessage(error_message); | 26 SetMessage(error_message); |
28 } | 27 } |
29 | 28 |
30 | 29 |
31 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) { | 30 void OSError::SetCodeAndMessage(SubSystem sub_system, int code) { |
32 set_sub_system(sub_system); | 31 set_sub_system(sub_system); |
33 set_code(code); | 32 set_code(code); |
34 if (sub_system == kSystem) { | 33 if (sub_system == kSystem) { |
35 const int kBufferSize = 1024; | 34 const int kBufferSize = 1024; |
36 char error_message[kBufferSize]; | 35 char error_message[kBufferSize]; |
37 Utils::StrError(code, error_message, kBufferSize); | 36 Utils::StrError(code, error_message, kBufferSize); |
38 SetMessage(error_message); | 37 SetMessage(error_message); |
39 } else if (sub_system == kGetAddressInfo) { | 38 } else if (sub_system == kGetAddressInfo) { |
40 SetMessage(gai_strerror(code)); | 39 SetMessage(gai_strerror(code)); |
41 } else { | 40 } else { |
42 UNREACHABLE(); | 41 UNREACHABLE(); |
43 } | 42 } |
44 } | 43 } |
45 | 44 |
| 45 |
46 const char* StringUtils::ConsoleStringToUtf8( | 46 const char* StringUtils::ConsoleStringToUtf8( |
47 const char* str, intptr_t len, intptr_t* result_len) { | 47 const char* str, intptr_t len, intptr_t* result_len) { |
48 UNIMPLEMENTED(); | 48 UNIMPLEMENTED(); |
49 return NULL; | 49 return NULL; |
50 } | 50 } |
51 | 51 |
| 52 |
52 const char* StringUtils::Utf8ToConsoleString( | 53 const char* StringUtils::Utf8ToConsoleString( |
53 const char* utf8, intptr_t len, intptr_t* result_len) { | 54 const char* utf8, intptr_t len, intptr_t* result_len) { |
54 UNIMPLEMENTED(); | 55 UNIMPLEMENTED(); |
55 return NULL; | 56 return NULL; |
56 } | 57 } |
57 | 58 |
| 59 |
58 char* StringUtils::ConsoleStringToUtf8( | 60 char* StringUtils::ConsoleStringToUtf8( |
59 char* str, intptr_t len, intptr_t* result_len) { | 61 char* str, intptr_t len, intptr_t* result_len) { |
60 UNIMPLEMENTED(); | 62 UNIMPLEMENTED(); |
61 return NULL; | 63 return NULL; |
62 } | 64 } |
63 | 65 |
| 66 |
64 char* StringUtils::Utf8ToConsoleString( | 67 char* StringUtils::Utf8ToConsoleString( |
65 char* utf8, intptr_t len, intptr_t* result_len) { | 68 char* utf8, intptr_t len, intptr_t* result_len) { |
66 UNIMPLEMENTED(); | 69 UNIMPLEMENTED(); |
67 return NULL; | 70 return NULL; |
68 } | 71 } |
69 | 72 |
| 73 |
70 bool ShellUtils::GetUtf8Argv(int argc, char** argv) { | 74 bool ShellUtils::GetUtf8Argv(int argc, char** argv) { |
71 return false; | 75 return false; |
72 } | 76 } |
73 | 77 |
| 78 |
74 void TimerUtils::InitOnce() { | 79 void TimerUtils::InitOnce() { |
75 } | 80 } |
76 | 81 |
| 82 |
77 int64_t TimerUtils::GetCurrentMonotonicMillis() { | 83 int64_t TimerUtils::GetCurrentMonotonicMillis() { |
78 return GetCurrentMonotonicMicros() / 1000; | 84 return GetCurrentMonotonicMicros() / 1000; |
79 } | 85 } |
80 | 86 |
| 87 |
81 int64_t TimerUtils::GetCurrentMonotonicMicros() { | 88 int64_t TimerUtils::GetCurrentMonotonicMicros() { |
82 struct timespec ts; | 89 struct timespec ts; |
83 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 90 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
84 UNREACHABLE(); | 91 UNREACHABLE(); |
85 return 0; | 92 return 0; |
86 } | 93 } |
87 // Convert to microseconds. | 94 // Convert to microseconds. |
88 int64_t result = ts.tv_sec; | 95 int64_t result = ts.tv_sec; |
89 result *= kMicrosecondsPerSecond; | 96 result *= kMicrosecondsPerSecond; |
90 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); | 97 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); |
91 return result; | 98 return result; |
92 } | 99 } |
93 | 100 |
| 101 |
94 void TimerUtils::Sleep(int64_t millis) { | 102 void TimerUtils::Sleep(int64_t millis) { |
95 struct timespec req; // requested. | 103 struct timespec req; // requested. |
96 struct timespec rem; // remainder. | 104 struct timespec rem; // remainder. |
97 int64_t micros = millis * kMicrosecondsPerMillisecond; | 105 int64_t micros = millis * kMicrosecondsPerMillisecond; |
98 int64_t seconds = micros / kMicrosecondsPerSecond; | 106 int64_t seconds = micros / kMicrosecondsPerSecond; |
99 micros = micros - seconds * kMicrosecondsPerSecond; | 107 micros = micros - seconds * kMicrosecondsPerSecond; |
100 int64_t nanos = micros * kNanosecondsPerMicrosecond; | 108 int64_t nanos = micros * kNanosecondsPerMicrosecond; |
101 req.tv_sec = seconds; | 109 req.tv_sec = seconds; |
102 req.tv_nsec = nanos; | 110 req.tv_nsec = nanos; |
103 while (true) { | 111 while (true) { |
104 int r = nanosleep(&req, &rem); | 112 int r = nanosleep(&req, &rem); |
105 if (r == 0) { | 113 if (r == 0) { |
106 break; | 114 break; |
107 } | 115 } |
108 // We should only ever see an interrupt error. | 116 // We should only ever see an interrupt error. |
109 ASSERT(errno == EINTR); | 117 ASSERT(errno == EINTR); |
110 // Copy remainder into requested and repeat. | 118 // Copy remainder into requested and repeat. |
111 req = rem; | 119 req = rem; |
112 } | 120 } |
113 } | 121 } |
114 | 122 |
115 } // namespace bin | 123 } // namespace bin |
116 } // namespace dart | 124 } // namespace dart |
117 | 125 |
118 #endif // defined(TARGET_OS_ANDROID) | 126 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |