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