Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
utils_linux.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/globals.h"
6#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
7
8#include <errno.h> // NOLINT
9#include <netdb.h> // NOLINT
10#include <sys/time.h> // NOLINT
11#include <time.h> // NOLINT
12
13#include "bin/utils.h"
14#include "platform/assert.h"
15#include "platform/utils.h"
16
17namespace dart {
18namespace bin {
19
20OSError::OSError() : sub_system_(kSystem), code_(0), message_(nullptr) {
21 Reload();
22}
23
24void OSError::Reload() {
25 SetCodeAndMessage(kSystem, errno);
26}
27
28void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
29 set_sub_system(sub_system);
30 set_code(code);
31 if (sub_system == kSystem) {
32 const int kBufferSize = 1024;
33 char error_buf[kBufferSize];
34 SetMessage(Utils::StrError(code, error_buf, kBufferSize));
35 } else if (sub_system == kGetAddressInfo) {
36 SetMessage(gai_strerror(code));
37 } else {
39 }
40}
41
42const char* StringUtils::ConsoleStringToUtf8(const char* str,
43 intptr_t len,
44 intptr_t* result_len) {
45 return nullptr;
46}
47
48const char* StringUtils::Utf8ToConsoleString(const char* utf8,
49 intptr_t len,
50 intptr_t* result_len) {
51 return nullptr;
52}
53
54char* StringUtils::ConsoleStringToUtf8(char* str,
55 intptr_t len,
56 intptr_t* result_len) {
57 return nullptr;
58}
59
60char* StringUtils::Utf8ToConsoleString(char* utf8,
61 intptr_t len,
62 intptr_t* result_len) {
63 return nullptr;
64}
65
66bool ShellUtils::GetUtf8Argv(int argc, char** argv) {
67 return false;
68}
69
70void TimerUtils::InitOnce() {}
71
72int64_t TimerUtils::GetCurrentMonotonicMillis() {
73 return GetCurrentMonotonicMicros() / 1000;
74}
75
76int64_t TimerUtils::GetCurrentMonotonicMicros() {
77 struct timespec ts;
78 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
80 return 0;
81 }
82 // Convert to microseconds.
83 int64_t result = ts.tv_sec;
85 result += (ts.tv_nsec / kNanosecondsPerMicrosecond);
86 return result;
87}
88
89void TimerUtils::Sleep(int64_t millis) {
90 struct timespec req; // requested.
91 struct timespec rem; // remainder.
92 int64_t micros = millis * kMicrosecondsPerMillisecond;
93 int64_t seconds = micros / kMicrosecondsPerSecond;
94 micros = micros - seconds * kMicrosecondsPerSecond;
95 int64_t nanos = micros * kNanosecondsPerMicrosecond;
96 req.tv_sec = seconds;
97 req.tv_nsec = nanos;
98 while (true) {
99 int r = nanosleep(&req, &rem);
100 if (r == 0) {
101 break;
102 }
103 // We should only ever see an interrupt error.
104 ASSERT(errno == EINTR);
105 // Copy remainder into requested and repeat.
106 req = rem;
107 }
108}
109
110} // namespace bin
111} // namespace dart
112
113#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
static const size_t kBufferSize
Definition SkString.cpp:27
#define UNREACHABLE()
Definition assert.h:248
#define ASSERT(E)
constexpr uint64_t kMicrosecondsPerMillisecond
GAsyncResult * result
static constexpr int kMicrosecondsPerSecond
constexpr intptr_t kNanosecondsPerMicrosecond
Definition globals.h:564