mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 19:16:21 +00:00
os/time: Add windows impl of os_realtime_get_ns
This commit is contained in:
parent
c91928f39e
commit
1451bd9993
|
@ -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.
|
||||
|
|
31
src/xrt/auxiliary/os/os_time.cpp
Normal file
31
src/xrt/auxiliary/os/os_time.cpp
Normal 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
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue