1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
14 #if defined(_LIBCPP_WIN32API)
15 # include "time_utils.h"
18 #if defined(_LIBCPP_WIN32API)
19 # define WIN32_LEAN_AND_MEAN
24 #if __has_include(<unistd.h>)
25 # include <unistd.h> // _POSIX_TIMERS
28 #if __has_include(<sys/time.h>)
29 # include <sys/time.h> // for gettimeofday and timeval
32 #if defined(__APPLE__) || defined (__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
33 # define _LIBCPP_HAS_CLOCK_GETTIME
36 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
38 const bool _FilesystemClock::is_steady
;
40 _FilesystemClock::time_point
_FilesystemClock::now() noexcept
{
41 typedef chrono::duration
<rep
> __secs
;
42 #if defined(_LIBCPP_WIN32API)
43 typedef chrono::duration
<rep
, nano
> __nsecs
;
45 GetSystemTimeAsFileTime(&time
);
46 detail::TimeSpec tp
= detail::filetime_to_timespec(time
);
47 return time_point(__secs(tp
.tv_sec
) +
48 chrono::duration_cast
<duration
>(__nsecs(tp
.tv_nsec
)));
49 #elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
50 typedef chrono::duration
<rep
, nano
> __nsecs
;
52 if (0 != clock_gettime(CLOCK_REALTIME
, &tp
))
53 __throw_system_error(errno
, "clock_gettime(CLOCK_REALTIME) failed");
54 return time_point(__secs(tp
.tv_sec
) +
55 chrono::duration_cast
<duration
>(__nsecs(tp
.tv_nsec
)));
57 typedef chrono::duration
<rep
, micro
> __microsecs
;
60 return time_point(__secs(tv
.tv_sec
) + __microsecs(tv
.tv_usec
));
64 _LIBCPP_END_NAMESPACE_FILESYSTEM