forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_point.cc
50 lines (37 loc) · 1.11 KB
/
time_point.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/time/time_point.h"
#include "flutter/fml/build_config.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/time/dart_timestamp_provider.h"
#if defined(OS_FUCHSIA)
#include <zircon/syscalls.h>
#else
#include <chrono>
#endif
namespace fml {
#if defined(OS_FUCHSIA)
// static
TimePoint TimePoint::Now() {
return TimePoint(zx_clock_get_monotonic());
}
TimePoint TimePoint::CurrentWallTime() {
return Now();
}
#else
template <typename Clock, typename Duration>
static int64_t NanosSinceEpoch(
std::chrono::time_point<Clock, Duration> time_point) {
const auto elapsed = time_point.time_since_epoch();
return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
}
TimePoint TimePoint::Now() {
return DartTimelineTicksSinceEpoch();
}
TimePoint TimePoint::CurrentWallTime() {
const int64_t nanos = NanosSinceEpoch(std::chrono::system_clock::now());
return TimePoint(nanos);
}
#endif
} // namespace fml