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