diff --git a/src/xrt/auxiliary/os/CMakeLists.txt b/src/xrt/auxiliary/os/CMakeLists.txt index 18a713f8f..163b623ad 100644 --- a/src/xrt/auxiliary/os/CMakeLists.txt +++ b/src/xrt/auxiliary/os/CMakeLists.txt @@ -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. diff --git a/src/xrt/auxiliary/os/os_time.cpp b/src/xrt/auxiliary/os/os_time.cpp new file mode 100644 index 000000000..56772e7f5 --- /dev/null +++ b/src/xrt/auxiliary/os/os_time.cpp @@ -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 + * + * @ingroup aux_os + */ + +#include "xrt/xrt_config_os.h" + +#ifdef XRT_OS_WINDOWS + +#include +#include + +extern "C" uint64_t +os_realtime_get_ns(void) +{ + auto now = std::chrono::system_clock::now(); + auto nsecs = std::chrono::time_point_cast(now); + auto ret = nsecs.time_since_epoch().count(); + return ret; +} +#endif diff --git a/src/xrt/auxiliary/os/os_time.h b/src/xrt/auxiliary/os/os_time.h index e1e987595..e38a6b33e 100644 --- a/src/xrt/auxiliary/os/os_time.h +++ b/src/xrt/auxiliary/os/os_time.h @@ -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.