@@ -42,14 +42,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
42
42
namespace chrono
43
43
{
44
44
45
+ //
45
46
// system_clock
47
+ //
46
48
47
- const bool system_clock::is_steady;
48
-
49
- system_clock::time_point
50
- system_clock::now () _NOEXCEPT
51
- {
52
49
#if defined(_LIBCPP_WIN32API)
50
+
51
+ static system_clock::time_point __libcpp_system_clock_now () {
53
52
// FILETIME is in 100ns units
54
53
using filetime_duration =
55
54
_VSTD::chrono::duration<__int64,
@@ -60,31 +59,42 @@ system_clock::now() _NOEXCEPT
60
59
static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600 };
61
60
62
61
FILETIME ft;
63
- #if _WIN32_WINNT >= _WIN32_WINNT_WIN8
64
- #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
62
+ #if _WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
65
63
GetSystemTimePreciseAsFileTime (&ft);
66
- #else
67
- GetSystemTimeAsFileTime (&ft);
68
- #endif
69
64
#else
70
65
GetSystemTimeAsFileTime (&ft);
71
66
#endif
72
67
73
68
filetime_duration d{(static_cast <__int64>(ft.dwHighDateTime ) << 32 ) |
74
69
static_cast <__int64>(ft.dwLowDateTime )};
75
- return time_point (duration_cast<duration>(d - nt_to_unix_epoch));
76
- #else
77
- #if defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
70
+ return system_clock::time_point (duration_cast<system_clock::duration>(d - nt_to_unix_epoch));
71
+ }
72
+
73
+ #elif defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
74
+
75
+ static system_clock::time_point __libcpp_system_clock_now () {
78
76
struct timespec tp;
79
77
if (0 != clock_gettime (CLOCK_REALTIME, &tp))
80
78
__throw_system_error (errno, " clock_gettime(CLOCK_REALTIME) failed" );
81
- return time_point (seconds (tp.tv_sec ) + microseconds (tp.tv_nsec / 1000 ));
79
+ return system_clock::time_point (seconds (tp.tv_sec ) + microseconds (tp.tv_nsec / 1000 ));
80
+ }
81
+
82
82
#else
83
+
84
+ static system_clock::time_point __libcpp_system_clock_now () {
83
85
timeval tv;
84
86
gettimeofday (&tv, 0 );
85
- return time_point (seconds (tv.tv_sec ) + microseconds (tv.tv_usec ));
86
- #endif
87
+ return system_clock::time_point (seconds (tv.tv_sec ) + microseconds (tv.tv_usec ));
88
+ }
89
+
87
90
#endif
91
+
92
+ const bool system_clock::is_steady;
93
+
94
+ system_clock::time_point
95
+ system_clock::now () _NOEXCEPT
96
+ {
97
+ return __libcpp_system_clock_now ();
88
98
}
89
99
90
100
time_t
@@ -99,33 +109,28 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
99
109
return system_clock::time_point (seconds (t));
100
110
}
101
111
102
- # ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
112
+ //
103
113
// steady_clock
104
114
//
105
115
// Warning: If this is not truly steady, then it is non-conforming. It is
106
116
// better for it to not exist and have the rest of libc++ use system_clock
107
117
// instead.
118
+ //
108
119
109
- const bool steady_clock::is_steady;
120
+ # ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
110
121
111
122
#if defined(__APPLE__)
112
123
113
- #if !defined(CLOCK_MONOTONIC_RAW)
114
- # error "Building libc++ on Apple platforms requires CLOCK_MONOTONIC_RAW"
115
- #endif
116
-
117
124
// On Apple platforms, only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or
118
125
// mach_absolute_time are able to time functions in the nanosecond range.
119
126
// Furthermore, only CLOCK_MONOTONIC_RAW is truly monotonic, because it
120
127
// also counts cycles when the system is asleep. Thus, it is the only
121
128
// acceptable implementation of steady_clock.
122
- steady_clock::time_point
123
- steady_clock::now () _NOEXCEPT
124
- {
129
+ static steady_clock::time_point __libcpp_steady_clock_now () {
125
130
struct timespec tp;
126
131
if (0 != clock_gettime (CLOCK_MONOTONIC_RAW, &tp))
127
132
__throw_system_error (errno, " clock_gettime(CLOCK_MONOTONIC_RAW) failed" );
128
- return time_point (seconds (tp.tv_sec ) + nanoseconds (tp.tv_nsec ));
133
+ return steady_clock:: time_point (seconds (tp.tv_sec ) + nanoseconds (tp.tv_nsec ));
129
134
}
130
135
131
136
#elif defined(_LIBCPP_WIN32API)
@@ -138,36 +143,40 @@ steady_clock::now() _NOEXCEPT
138
143
static LARGE_INTEGER
139
144
__QueryPerformanceFrequency ()
140
145
{
141
- LARGE_INTEGER val;
142
- (void ) QueryPerformanceFrequency (&val);
143
- return val;
146
+ LARGE_INTEGER val;
147
+ (void ) QueryPerformanceFrequency (&val);
148
+ return val;
144
149
}
145
150
146
- steady_clock::time_point
147
- steady_clock::now () _NOEXCEPT
148
- {
151
+ static steady_clock::time_point __libcpp_steady_clock_now () {
149
152
static const LARGE_INTEGER freq = __QueryPerformanceFrequency ();
150
153
151
154
LARGE_INTEGER counter;
152
155
(void ) QueryPerformanceCounter (&counter);
153
- return time_point (duration (counter.QuadPart * nano::den / freq.QuadPart ));
156
+ return steady_clock:: time_point (steady_clock:: duration (counter.QuadPart * nano::den / freq.QuadPart ));
154
157
}
155
158
156
159
#elif defined(CLOCK_MONOTONIC)
157
160
158
- steady_clock::time_point
159
- steady_clock::now () _NOEXCEPT
160
- {
161
+ static steady_clock::time_point __libcpp_steady_clock_now () {
161
162
struct timespec tp;
162
163
if (0 != clock_gettime (CLOCK_MONOTONIC, &tp))
163
164
__throw_system_error (errno, " clock_gettime(CLOCK_MONOTONIC) failed" );
164
- return time_point (seconds (tp.tv_sec ) + nanoseconds (tp.tv_nsec ));
165
+ return steady_clock:: time_point (seconds (tp.tv_sec ) + nanoseconds (tp.tv_nsec ));
165
166
}
166
167
167
168
#else
168
- # error "Monotonic clock not implemented"
169
+ # error "Monotonic clock not implemented on this platform "
169
170
#endif
170
171
172
+ const bool steady_clock::is_steady;
173
+
174
+ steady_clock::time_point
175
+ steady_clock::now () _NOEXCEPT
176
+ {
177
+ return __libcpp_steady_clock_now ();
178
+ }
179
+
171
180
#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
172
181
173
182
}
0 commit comments