The open source OpenXR runtime
1// Copyright 2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Wrapper around OS native time functions.
6 *
7 * These should be preferred over directly using native OS time functions in
8 * potentially-portable code. Additionally, in most cases these are preferred
9 * over timepoints from @ref time_state for general usage in drivers, etc.
10 *
11 * @author Christoph Haag <christoph.haag@collabora.com>
12 *
13 * @ingroup aux_os
14 */
15
16#include "xrt/xrt_config_os.h"
17
18#ifdef XRT_OS_WINDOWS
19
20#include <chrono>
21
22extern "C" uint64_t
23os_realtime_get_ns(void)
24{
25 auto now = std::chrono::system_clock::now();
26 auto nsecs = std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
27 auto ret = nsecs.time_since_epoch().count();
28 return ret;
29}
30#endif