The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

os/time: Add windows impl of os_realtime_get_ns

authored by

Christoph Haag and committed by
Jakob Bornecrantz
1451bd99 c91928f3

+49 -1
+8 -1
src/xrt/auxiliary/os/CMakeLists.txt
··· 9 9 # by applications like the OpenXR runtime library. 10 10 # 11 11 12 - add_library(aux_os STATIC os_documentation.h os_hid.h os_hid_hidraw.c os_threading.h) 12 + add_library( 13 + aux_os STATIC 14 + os_documentation.h 15 + os_hid.h 16 + os_hid_hidraw.c 17 + os_threading.h 18 + os_time.cpp 19 + ) 13 20 target_link_libraries(aux_os PUBLIC aux-includes xrt-pthreads) 14 21 15 22 # Only uses normal Windows libraries, doesn't add anything extra.
+31
src/xrt/auxiliary/os/os_time.cpp
··· 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 <inttypes.h> 21 + #include <chrono> 22 + 23 + extern "C" uint64_t 24 + os_realtime_get_ns(void) 25 + { 26 + auto now = std::chrono::system_clock::now(); 27 + auto nsecs = std::chrono::time_point_cast<std::chrono::nanoseconds>(now); 28 + auto ret = nsecs.time_since_epoch().count(); 29 + return ret; 30 + } 31 + #endif
+10
src/xrt/auxiliary/os/os_time.h
··· 165 165 os_realtime_get_ns(void); 166 166 #endif 167 167 168 + #if defined(XRT_OS_WINDOWS) 169 + /*! 170 + * Return a realtime clock in nanoseconds 171 + * 172 + * @ingroup aux_os_time_extra 173 + */ 174 + uint64_t 175 + os_realtime_get_ns(void); 176 + #endif 177 + 168 178 #if defined(XRT_OS_WINDOWS) || defined(XRT_DOXYGEN) 169 179 /*! 170 180 * @brief Return a qpc freq in nanoseconds.