os/time: Add windows impl of os_realtime_get_ns

This commit is contained in:
Christoph Haag 2023-03-10 02:56:28 +01:00 committed by Jakob Bornecrantz
parent c91928f39e
commit 1451bd9993
3 changed files with 49 additions and 1 deletions

View file

@ -9,7 +9,14 @@
# by applications like the OpenXR runtime library.
#
add_library(aux_os STATIC os_documentation.h os_hid.h os_hid_hidraw.c os_threading.h)
add_library(
aux_os STATIC
os_documentation.h
os_hid.h
os_hid_hidraw.c
os_threading.h
os_time.cpp
)
target_link_libraries(aux_os PUBLIC aux-includes xrt-pthreads)
# Only uses normal Windows libraries, doesn't add anything extra.

View file

@ -0,0 +1,31 @@
// Copyright 2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Wrapper around OS native time functions.
*
* These should be preferred over directly using native OS time functions in
* potentially-portable code. Additionally, in most cases these are preferred
* over timepoints from @ref time_state for general usage in drivers, etc.
*
* @author Christoph Haag <christoph.haag@collabora.com>
*
* @ingroup aux_os
*/
#include "xrt/xrt_config_os.h"
#ifdef XRT_OS_WINDOWS
#include <inttypes.h>
#include <chrono>
extern "C" uint64_t
os_realtime_get_ns(void)
{
auto now = std::chrono::system_clock::now();
auto nsecs = std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
auto ret = nsecs.time_since_epoch().count();
return ret;
}
#endif

View file

@ -165,6 +165,16 @@ static inline uint64_t
os_realtime_get_ns(void);
#endif
#if defined(XRT_OS_WINDOWS)
/*!
* Return a realtime clock in nanoseconds
*
* @ingroup aux_os_time_extra
*/
uint64_t
os_realtime_get_ns(void);
#endif
#if defined(XRT_OS_WINDOWS) || defined(XRT_DOXYGEN)
/*!
* @brief Return a qpc freq in nanoseconds.