// clang-format off //===------------------------- chrono.cpp ---------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "third_party/libcxx/chrono" #include "third_party/libcxx/cerrno" // errn" #include "libc/sysv/consts/clock.h" #include "libc/time/time.h" #include "libc/sysv/consts/clock.h" #include "third_party/libcxx/system_error" // __throw_system_erro" #define _LIBCPP_USE_CLOCK_GETTIME _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono { // system_clock const bool system_clock::is_steady; system_clock::time_point system_clock::now() _NOEXCEPT { struct timespec tp; if (0 != clock_gettime(CLOCK_REALTIME, &tp)) __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed"); return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000)); } time_t system_clock::to_time_t(const time_point& t) _NOEXCEPT { return time_t(duration_cast(t.time_since_epoch()).count()); } system_clock::time_point system_clock::from_time_t(time_t t) _NOEXCEPT { return system_clock::time_point(seconds(t)); } // steady_clock // // Warning: If this is not truly steady, then it is non-conforming. It is // better for it to not exist and have the rest of libc++ use system_clock // instead. const bool steady_clock::is_steady; steady_clock::time_point steady_clock::now() _NOEXCEPT { struct timespec tp; if (0 != clock_gettime(CLOCK_MONOTONIC, &tp)) __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed"); return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec)); } } // namespace chrono _LIBCPP_END_NAMESPACE_STD