From: Nicolai Hähnle Date: Sun, 22 Oct 2017 15:38:44 +0000 (+0200) Subject: util: move os_time.[ch] to src/util X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=222a2fb9;p=mesa.git util: move os_time.[ch] to src/util Reviewed-by: Marek Olšák --- diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources index 0502a2c44f8..4fb7a30613a 100644 --- a/src/gallium/auxiliary/Makefile.sources +++ b/src/gallium/auxiliary/Makefile.sources @@ -83,8 +83,6 @@ C_SOURCES := \ os/os_process.c \ os/os_process.h \ os/os_thread.h \ - os/os_time.c \ - os/os_time.h \ pipebuffer/pb_buffer_fenced.c \ pipebuffer/pb_buffer_fenced.h \ pipebuffer/pb_buffer.h \ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c index c456a97eb62..6ddc509a813 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c @@ -32,7 +32,7 @@ #include "util/u_debug.h" #include "util/u_memory.h" #include "util/simple_list.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "lp_bld.h" #include "lp_bld_debug.h" #include "lp_bld_misc.h" diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c index 4caaab6977e..581dad6df04 100644 --- a/src/gallium/auxiliary/hud/hud_cpu.c +++ b/src/gallium/auxiliary/hud/hud_cpu.c @@ -29,7 +29,7 @@ */ #include "hud/hud_private.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "os/os_thread.h" #include "util/u_memory.h" #include "util/u_queue.h" diff --git a/src/gallium/auxiliary/hud/hud_cpufreq.c b/src/gallium/auxiliary/hud/hud_cpufreq.c index abb930d7e28..2b881a850e3 100644 --- a/src/gallium/auxiliary/hud/hud_cpufreq.c +++ b/src/gallium/auxiliary/hud/hud_cpufreq.c @@ -35,7 +35,7 @@ #include "hud/hud_private.h" #include "util/list.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "os/os_thread.h" #include "util/u_memory.h" #include diff --git a/src/gallium/auxiliary/hud/hud_diskstat.c b/src/gallium/auxiliary/hud/hud_diskstat.c index df86abd12d8..53b32baef22 100644 --- a/src/gallium/auxiliary/hud/hud_diskstat.c +++ b/src/gallium/auxiliary/hud/hud_diskstat.c @@ -34,7 +34,7 @@ #include "hud/hud_private.h" #include "util/list.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "os/os_thread.h" #include "util/u_memory.h" #include diff --git a/src/gallium/auxiliary/hud/hud_driver_query.c b/src/gallium/auxiliary/hud/hud_driver_query.c index 76104b5b497..8b1e4e104a7 100644 --- a/src/gallium/auxiliary/hud/hud_driver_query.c +++ b/src/gallium/auxiliary/hud/hud_driver_query.c @@ -33,7 +33,7 @@ #include "hud/hud_private.h" #include "pipe/p_screen.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "util/u_math.h" #include "util/u_memory.h" #include diff --git a/src/gallium/auxiliary/hud/hud_fps.c b/src/gallium/auxiliary/hud/hud_fps.c index 8aa7a665a30..aecbaf0f6b4 100644 --- a/src/gallium/auxiliary/hud/hud_fps.c +++ b/src/gallium/auxiliary/hud/hud_fps.c @@ -29,7 +29,7 @@ */ #include "hud/hud_private.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "util/u_memory.h" struct fps_info { diff --git a/src/gallium/auxiliary/hud/hud_nic.c b/src/gallium/auxiliary/hud/hud_nic.c index 835f92e2e04..bb29a90dbca 100644 --- a/src/gallium/auxiliary/hud/hud_nic.c +++ b/src/gallium/auxiliary/hud/hud_nic.c @@ -34,7 +34,7 @@ #include "hud/hud_private.h" #include "util/list.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "os/os_thread.h" #include "util/u_memory.h" #include diff --git a/src/gallium/auxiliary/hud/hud_sensors_temp.c b/src/gallium/auxiliary/hud/hud_sensors_temp.c index 29ee257ce86..7ae6f71b55c 100644 --- a/src/gallium/auxiliary/hud/hud_sensors_temp.c +++ b/src/gallium/auxiliary/hud/hud_sensors_temp.c @@ -31,7 +31,7 @@ #include "hud/hud_private.h" #include "util/list.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "os/os_thread.h" #include "util/u_memory.h" #include diff --git a/src/gallium/auxiliary/meson.build b/src/gallium/auxiliary/meson.build index 948fb86b3b2..d8fdd3510f1 100644 --- a/src/gallium/auxiliary/meson.build +++ b/src/gallium/auxiliary/meson.build @@ -103,8 +103,6 @@ files_libgallium = files( 'os/os_process.c', 'os/os_process.h', 'os/os_thread.h', - 'os/os_time.c', - 'os/os_time.h', 'pipebuffer/pb_buffer_fenced.c', 'pipebuffer/pb_buffer_fenced.h', 'pipebuffer/pb_buffer.h', diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c deleted file mode 100644 index e4a1cae641a..00000000000 --- a/src/gallium/auxiliary/os/os_time.c +++ /dev/null @@ -1,190 +0,0 @@ -/************************************************************************** - * - * Copyright 2008-2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * @file - * OS independent time-manipulation functions. - * - * @author Jose Fonseca - */ - - -#include "pipe/p_defines.h" -#include "util/u_atomic.h" - -#if defined(PIPE_OS_UNIX) -# include /* timeval */ -# include /* timeval */ -# include /* sched_yield */ -# include -#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) -# include -#else -# error Unsupported OS -#endif - -#include "os_time.h" - - -int64_t -os_time_get_nano(void) -{ -#if defined(PIPE_OS_LINUX) - - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - return tv.tv_nsec + tv.tv_sec*INT64_C(1000000000); - -#elif defined(PIPE_OS_UNIX) - - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_usec*INT64_C(1000) + tv.tv_sec*INT64_C(1000000000); - -#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) - - static LARGE_INTEGER frequency; - LARGE_INTEGER counter; - int64_t secs, nanosecs; - if(!frequency.QuadPart) - QueryPerformanceFrequency(&frequency); - QueryPerformanceCounter(&counter); - /* Compute seconds and nanoseconds parts separately to - * reduce severity of precision loss. - */ - secs = counter.QuadPart / frequency.QuadPart; - nanosecs = (counter.QuadPart % frequency.QuadPart) * INT64_C(1000000000) - / frequency.QuadPart; - return secs*INT64_C(1000000000) + nanosecs; - -#else - -#error Unsupported OS - -#endif -} - - - -void -os_time_sleep(int64_t usecs) -{ -#if defined(PIPE_OS_LINUX) - struct timespec time; - time.tv_sec = usecs / 1000000; - time.tv_nsec = (usecs % 1000000) * 1000; - while (clock_nanosleep(CLOCK_MONOTONIC, 0, &time, &time) == EINTR); - -#elif defined(PIPE_OS_UNIX) - usleep(usecs); - -#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) - DWORD dwMilliseconds = (DWORD) ((usecs + 999) / 1000); - /* Avoid Sleep(O) as that would cause to sleep for an undetermined duration */ - if (dwMilliseconds) { - Sleep(dwMilliseconds); - } -#else -# error Unsupported OS -#endif -} - - - -int64_t -os_time_get_absolute_timeout(uint64_t timeout) -{ - int64_t time, abs_timeout; - - /* Also check for the type upper bound. */ - if (timeout == PIPE_TIMEOUT_INFINITE || timeout > INT64_MAX) - return PIPE_TIMEOUT_INFINITE; - - time = os_time_get_nano(); - abs_timeout = time + (int64_t)timeout; - - /* Check for overflow. */ - if (abs_timeout < time) - return PIPE_TIMEOUT_INFINITE; - - return abs_timeout; -} - - -bool -os_wait_until_zero(volatile int *var, uint64_t timeout) -{ - if (!p_atomic_read(var)) - return true; - - if (!timeout) - return false; - - if (timeout == PIPE_TIMEOUT_INFINITE) { - while (p_atomic_read(var)) { -#if defined(PIPE_OS_UNIX) - sched_yield(); -#endif - } - return true; - } - else { - int64_t start_time = os_time_get_nano(); - int64_t end_time = start_time + timeout; - - while (p_atomic_read(var)) { - if (os_time_timeout(start_time, end_time, os_time_get_nano())) - return false; - -#if defined(PIPE_OS_UNIX) - sched_yield(); -#endif - } - return true; - } -} - - -bool -os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout) -{ - if (!p_atomic_read(var)) - return true; - - if (timeout == PIPE_TIMEOUT_INFINITE) - return os_wait_until_zero(var, PIPE_TIMEOUT_INFINITE); - - while (p_atomic_read(var)) { - if (os_time_get_nano() >= timeout) - return false; - -#if defined(PIPE_OS_UNIX) - sched_yield(); -#endif - } - return true; -} diff --git a/src/gallium/auxiliary/os/os_time.h b/src/gallium/auxiliary/os/os_time.h deleted file mode 100644 index ca0bdd5a0c4..00000000000 --- a/src/gallium/auxiliary/os/os_time.h +++ /dev/null @@ -1,135 +0,0 @@ -/************************************************************************** - * - * Copyright 2008-2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * @file - * OS independent time-manipulation functions. - * - * @author Jose Fonseca - */ - -#ifndef _OS_TIME_H_ -#define _OS_TIME_H_ - - -#include "pipe/p_config.h" - -#if defined(PIPE_OS_UNIX) -# include /* usleep */ -#endif - -#include "pipe/p_compiler.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -/* - * Get the current time in nanoseconds from an unknown base. - */ -int64_t -os_time_get_nano(void); - - -/* - * Get the current time in microseconds from an unknown base. - */ -static inline int64_t -os_time_get(void) -{ - return os_time_get_nano() / 1000; -} - - -/* - * Sleep. - */ -void -os_time_sleep(int64_t usecs); - - -/* - * Helper function for detecting time outs, taking in account overflow. - * - * Returns true if the current time has elapsed beyond the specified interval. - */ -static inline boolean -os_time_timeout(int64_t start, - int64_t end, - int64_t curr) -{ - if (start <= end) - return !(start <= curr && curr < end); - else - return !((start <= curr) || (curr < end)); -} - - -/** - * Convert a relative timeout in nanoseconds into an absolute timeout, - * in other words, it returns current time + timeout. - * os_time_get_nano() must be monotonic. - * PIPE_TIMEOUT_INFINITE is passed through unchanged. If the calculation - * overflows, PIPE_TIMEOUT_INFINITE is returned. - */ -int64_t -os_time_get_absolute_timeout(uint64_t timeout); - - -/** - * Wait until the variable at the given memory location is zero. - * - * \param var variable - * \param timeout timeout in ns, can be anything from 0 (no wait) to - * PIPE_TIME_INFINITE (wait forever) - * \return true if the variable is zero - */ -bool -os_wait_until_zero(volatile int *var, uint64_t timeout); - - -/** - * Wait until the variable at the given memory location is zero. - * The timeout is the absolute time when the waiting should stop. If it is - * less than or equal to the current time, it only returns the status and - * doesn't wait. PIPE_TIME_INFINITE waits forever. This requires that - * os_time_get_nano is monotonic. - * - * \param var variable - * \param timeout the time in ns when the waiting should stop - * \return true if the variable is zero - */ -bool -os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout); - -#ifdef __cplusplus -} -#endif - -#endif /* _OS_TIME_H_ */ diff --git a/src/gallium/auxiliary/util/u_time.h b/src/gallium/auxiliary/util/u_time.h index a5017d6bce2..99fa1400511 100644 --- a/src/gallium/auxiliary/util/u_time.h +++ b/src/gallium/auxiliary/util/u_time.h @@ -38,7 +38,7 @@ #include "pipe/p_config.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "pipe/p_compiler.h" diff --git a/src/gallium/drivers/ddebug/dd_draw.c b/src/gallium/drivers/ddebug/dd_draw.c index aec9332d903..a15801beb1d 100644 --- a/src/gallium/drivers/ddebug/dd_draw.c +++ b/src/gallium/drivers/ddebug/dd_draw.c @@ -35,7 +35,7 @@ #include "util/u_memory.h" #include "tgsi/tgsi_parse.h" #include "tgsi/tgsi_scan.h" -#include "os/os_time.h" +#include "util/os_time.h" #include diff --git a/src/gallium/drivers/etnaviv/etnaviv_query_sw.c b/src/gallium/drivers/etnaviv/etnaviv_query_sw.c index dd9bac38501..2e65065b285 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_query_sw.c +++ b/src/gallium/drivers/etnaviv/etnaviv_query_sw.c @@ -25,7 +25,7 @@ * Christian Gmeiner */ -#include "os/os_time.h" +#include "util/os_time.h" #include "pipe/p_state.h" #include "util/u_memory.h" #include "util/u_string.h" diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c b/src/gallium/drivers/etnaviv/etnaviv_screen.c index b0c4b7ba471..30beb412d9d 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_screen.c +++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c @@ -38,7 +38,7 @@ #include "etnaviv_resource.h" #include "etnaviv_translate.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_string.h" diff --git a/src/gallium/drivers/freedreno/freedreno_query_sw.c b/src/gallium/drivers/freedreno/freedreno_query_sw.c index dfa89872397..50965161146 100644 --- a/src/gallium/drivers/freedreno/freedreno_query_sw.c +++ b/src/gallium/drivers/freedreno/freedreno_query_sw.c @@ -30,7 +30,7 @@ #include "util/u_string.h" #include "util/u_memory.h" #include "util/u_inlines.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "freedreno_query_sw.h" #include "freedreno_context.h" diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c index e5504b6b386..5bb1e20c780 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.c +++ b/src/gallium/drivers/freedreno/freedreno_screen.c @@ -38,7 +38,7 @@ #include "util/u_string.h" #include "util/u_debug.h" -#include "os/os_time.h" +#include "util/os_time.h" #include #include diff --git a/src/gallium/drivers/llvmpipe/lp_query.c b/src/gallium/drivers/llvmpipe/lp_query.c index 7b81903b413..ad11d8ca53f 100644 --- a/src/gallium/drivers/llvmpipe/lp_query.c +++ b/src/gallium/drivers/llvmpipe/lp_query.c @@ -33,7 +33,7 @@ #include "draw/draw_context.h" #include "pipe/p_defines.h" #include "util/u_memory.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "lp_context.h" #include "lp_flush.h" #include "lp_fence.h" diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index 9e2780ca1d7..939944aa791 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -34,7 +34,7 @@ #include "util/u_string.h" #include "util/u_thread.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "lp_scene_queue.h" #include "lp_context.h" diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index ee377dc61f8..bd5876994d3 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -38,7 +38,7 @@ #include "gallivm/lp_bld_type.h" #include "os/os_misc.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "lp_texture.h" #include "lp_fence.h" #include "lp_jit.h" diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index 2be6fc033d1..c1573231335 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -41,7 +41,7 @@ #include "util/u_pack_color.h" #include "util/u_viewport.h" #include "draw/draw_pipe.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "lp_context.h" #include "lp_memory.h" #include "lp_scene.h" diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 9223ce63e3a..0daf7aecf6e 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -67,7 +67,7 @@ #include "util/u_string.h" #include "util/simple_list.h" #include "util/u_dual_blend.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "pipe/p_shader_tokens.h" #include "draw/draw_context.h" #include "tgsi/tgsi_dump.h" diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c index 6b0df21b8ad..77c7ac1bbde 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c @@ -29,7 +29,7 @@ #include "util/u_math.h" #include "util/u_memory.h" #include "util/simple_list.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "gallivm/lp_bld_arit.h" #include "gallivm/lp_bld_bitarit.h" #include "gallivm/lp_bld_const.h" diff --git a/src/gallium/drivers/nouveau/nouveau_fence.c b/src/gallium/drivers/nouveau/nouveau_fence.c index 6c299cbc6a5..d14c59b2dd1 100644 --- a/src/gallium/drivers/nouveau/nouveau_fence.c +++ b/src/gallium/drivers/nouveau/nouveau_fence.c @@ -23,7 +23,7 @@ #include "nouveau_screen.h" #include "nouveau_winsys.h" #include "nouveau_fence.h" -#include "os/os_time.h" +#include "util/os_time.h" #ifdef PIPE_OS_UNIX #include diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c index ea68809c6e8..c144b39b2dd 100644 --- a/src/gallium/drivers/nouveau/nouveau_screen.c +++ b/src/gallium/drivers/nouveau/nouveau_screen.c @@ -8,7 +8,7 @@ #include "util/u_format_s3tc.h" #include "util/u_string.h" -#include "os/os_time.h" +#include "util/os_time.h" #include #include diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 6f4231d76e3..b55fb63f000 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -26,7 +26,7 @@ #include "util/u_sampler.h" #include "util/simple_list.h" #include "util/u_upload_mgr.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "vl/vl_decoder.h" #include "vl/vl_video_buffer.h" diff --git a/src/gallium/drivers/r300/r300_flush.c b/src/gallium/drivers/r300/r300_flush.c index 54108d1cdfb..7fabd13f3d7 100644 --- a/src/gallium/drivers/r300/r300_flush.c +++ b/src/gallium/drivers/r300/r300_flush.c @@ -27,7 +27,7 @@ #include "util/simple_list.h" #include "util/u_upload_mgr.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "r300_context.h" #include "r300_cs.h" diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index 72ba0ff84e3..b9b2d7d8382 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -24,7 +24,7 @@ #include "util/u_format.h" #include "util/u_format_s3tc.h" #include "util/u_memory.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "vl/vl_decoder.h" #include "vl/vl_video_buffer.h" diff --git a/src/gallium/drivers/r600/r600_gpu_load.c b/src/gallium/drivers/r600/r600_gpu_load.c index c15fb9dfa06..a2de8cc71a4 100644 --- a/src/gallium/drivers/r600/r600_gpu_load.c +++ b/src/gallium/drivers/r600/r600_gpu_load.c @@ -36,7 +36,7 @@ #include "r600_pipe_common.h" #include "r600_query.h" -#include "os/os_time.h" +#include "util/os_time.h" /* For good accuracy at 1000 fps or lower. This will be inaccurate for higher * fps (there are too few samples per frame). */ diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c index e639d928830..2381c5b7d00 100644 --- a/src/gallium/drivers/r600/r600_pipe.c +++ b/src/gallium/drivers/r600/r600_pipe.c @@ -39,7 +39,7 @@ #include "vl/vl_video_buffer.h" #include "radeon_video.h" #include "radeon_uvd.h" -#include "os/os_time.h" +#include "util/os_time.h" static const struct debug_named_value r600_debug_options[] = { /* features */ diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c index acad670d6fa..e2d0e32bb2b 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.c +++ b/src/gallium/drivers/r600/r600_pipe_common.c @@ -32,7 +32,7 @@ #include "util/u_memory.h" #include "util/u_format_s3tc.h" #include "util/u_upload_mgr.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "vl/vl_decoder.h" #include "vl/vl_video_buffer.h" #include "radeon_video.h" diff --git a/src/gallium/drivers/r600/r600_query.c b/src/gallium/drivers/r600/r600_query.c index aa3e36f56f7..9c17c3ba23e 100644 --- a/src/gallium/drivers/r600/r600_query.c +++ b/src/gallium/drivers/r600/r600_query.c @@ -27,7 +27,7 @@ #include "r600_cs.h" #include "util/u_memory.h" #include "util/u_upload_mgr.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "tgsi/tgsi_text.h" #define R600_MAX_STREAMS 4 diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c index b8411144900..3515d979d9e 100644 --- a/src/gallium/drivers/r600/r600_texture.c +++ b/src/gallium/drivers/r600/r600_texture.c @@ -32,7 +32,7 @@ #include "util/u_memory.h" #include "util/u_pack_color.h" #include "util/u_surface.h" -#include "os/os_time.h" +#include "util/os_time.h" #include #include diff --git a/src/gallium/drivers/r600/sb/sb_core.cpp b/src/gallium/drivers/r600/sb/sb_core.cpp index afea8188f1c..cdc2862d36d 100644 --- a/src/gallium/drivers/r600/sb/sb_core.cpp +++ b/src/gallium/drivers/r600/sb/sb_core.cpp @@ -26,7 +26,7 @@ #define SB_RA_SCHED_CHECK DEBUG -#include "os/os_time.h" +#include "util/os_time.h" #include "r600_pipe.h" #include "r600_shader.h" diff --git a/src/gallium/drivers/radeon/r600_gpu_load.c b/src/gallium/drivers/radeon/r600_gpu_load.c index ccbd1c91864..411dcfe8724 100644 --- a/src/gallium/drivers/radeon/r600_gpu_load.c +++ b/src/gallium/drivers/radeon/r600_gpu_load.c @@ -33,7 +33,7 @@ #include "r600_pipe_common.h" #include "r600_query.h" -#include "os/os_time.h" +#include "util/os_time.h" /* For good accuracy at 1000 fps or lower. This will be inaccurate for higher * fps (there are too few samples per frame). */ diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c index c9502182a7e..5d8214118a1 100644 --- a/src/gallium/drivers/radeon/r600_pipe_common.c +++ b/src/gallium/drivers/radeon/r600_pipe_common.c @@ -29,7 +29,7 @@ #include "util/u_memory.h" #include "util/u_format_s3tc.h" #include "util/u_upload_mgr.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "vl/vl_decoder.h" #include "vl/vl_video_buffer.h" #include "radeon/radeon_video.h" diff --git a/src/gallium/drivers/radeon/r600_query.c b/src/gallium/drivers/radeon/r600_query.c index aedf950ff2d..0a03061ab91 100644 --- a/src/gallium/drivers/radeon/r600_query.c +++ b/src/gallium/drivers/radeon/r600_query.c @@ -26,7 +26,7 @@ #include "r600_cs.h" #include "util/u_memory.h" #include "util/u_upload_mgr.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "tgsi/tgsi_text.h" #include "amd/common/sid.h" diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c index 0800c0f1d1c..258690cadf5 100644 --- a/src/gallium/drivers/radeon/r600_texture.c +++ b/src/gallium/drivers/radeon/r600_texture.c @@ -28,7 +28,7 @@ #include "util/u_memory.h" #include "util/u_pack_color.h" #include "util/u_surface.h" -#include "os/os_time.h" +#include "util/os_time.h" #include #include #include "state_tracker/drm_driver.h" diff --git a/src/gallium/drivers/rbug/rbug_core.c b/src/gallium/drivers/rbug/rbug_core.c index 82bcef8d03b..8eb39c17b14 100644 --- a/src/gallium/drivers/rbug/rbug_core.c +++ b/src/gallium/drivers/rbug/rbug_core.c @@ -33,7 +33,7 @@ #include "util/u_memory.h" #include "util/simple_list.h" #include "util/u_network.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "tgsi/tgsi_parse.h" diff --git a/src/gallium/drivers/softpipe/sp_query.c b/src/gallium/drivers/softpipe/sp_query.c index 267c99977fe..5c9afe6fe47 100644 --- a/src/gallium/drivers/softpipe/sp_query.c +++ b/src/gallium/drivers/softpipe/sp_query.c @@ -30,7 +30,7 @@ */ #include "draw/draw_context.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "pipe/p_defines.h" #include "util/u_memory.h" #include "sp_context.h" diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index 356ebf4e833..08efd14fbe0 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -31,7 +31,7 @@ #include "util/u_format_s3tc.h" #include "util/u_video.h" #include "os/os_misc.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "pipe/p_defines.h" #include "pipe/p_screen.h" #include "draw/draw_context.h" diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h index 0d695a64927..80c59c05e86 100644 --- a/src/gallium/drivers/svga/svga_context.h +++ b/src/gallium/drivers/svga/svga_context.h @@ -31,7 +31,7 @@ #include "pipe/p_defines.h" #include "pipe/p_state.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "util/u_blitter.h" #include "util/list.h" diff --git a/src/gallium/drivers/swr/swr_fence.cpp b/src/gallium/drivers/swr/swr_fence.cpp index abf1d0c69c8..3005eb9aaad 100644 --- a/src/gallium/drivers/swr/swr_fence.cpp +++ b/src/gallium/drivers/swr/swr_fence.cpp @@ -23,7 +23,7 @@ #include "pipe/p_screen.h" #include "util/u_memory.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "swr_context.h" #include "swr_screen.h" diff --git a/src/gallium/drivers/swr/swr_query.cpp b/src/gallium/drivers/swr/swr_query.cpp index e3697304e05..ea31de630b3 100644 --- a/src/gallium/drivers/swr/swr_query.cpp +++ b/src/gallium/drivers/swr/swr_query.cpp @@ -23,7 +23,7 @@ #include "pipe/p_defines.h" #include "util/u_memory.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "swr_context.h" #include "swr_fence.h" #include "swr_query.h" diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c index 2003222cc1c..49349496ac6 100644 --- a/src/gallium/drivers/trace/tr_dump.c +++ b/src/gallium/drivers/trace/tr_dump.c @@ -45,7 +45,7 @@ #include "pipe/p_compiler.h" #include "os/os_thread.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "util/u_debug.h" #include "util/u_memory.h" #include "util/u_string.h" diff --git a/src/gallium/drivers/virgl/virgl_screen.c b/src/gallium/drivers/virgl/virgl_screen.c index 56520156891..1646e7ee025 100644 --- a/src/gallium/drivers/virgl/virgl_screen.c +++ b/src/gallium/drivers/virgl/virgl_screen.c @@ -24,7 +24,7 @@ #include "util/u_format.h" #include "util/u_format_s3tc.h" #include "util/u_video.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "pipe/p_defines.h" #include "pipe/p_screen.h" diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c index 06b5c8da3c2..7348ea3ba88 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -30,7 +30,7 @@ #include "pipe/p_screen.h" #include "util/u_memory.h" #include "hud/hud_context.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "state_tracker/st_api.h" #include "stw_icd.h" diff --git a/src/gallium/tests/unit/pipe_barrier_test.c b/src/gallium/tests/unit/pipe_barrier_test.c index 6bd46b8d964..838c9bfd96c 100644 --- a/src/gallium/tests/unit/pipe_barrier_test.c +++ b/src/gallium/tests/unit/pipe_barrier_test.c @@ -36,8 +36,9 @@ #include #include +#include -#include "os/os_time.h" +#include "util/os_time.h" #include "util/u_atomic.h" #include "util/u_thread.h" diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c index d0395a938ce..c3e97c22861 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c @@ -27,7 +27,7 @@ #include "amdgpu_cs.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "state_tracker/drm_driver.h" #include #include diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c index 0f36cc5ae63..0a3f0fd6016 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c @@ -27,7 +27,8 @@ */ #include "amdgpu_cs.h" -#include "os/os_time.h" +#include "util/os_time.h" +#include #include #include "amd/common/sid.h" diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c index 15e9d38e33a..b4e501c817f 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c @@ -31,7 +31,7 @@ #include "util/simple_list.h" #include "os/os_thread.h" #include "os/os_mman.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "state_tracker/drm_driver.h" diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c index 2b1542fcf48..7220f3a0240 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c @@ -56,7 +56,7 @@ #include "radeon_drm_cs.h" #include "util/u_memory.h" -#include "os/os_time.h" +#include "util/os_time.h" #include #include diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c index 7f542e7f1ff..71e652ebf31 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c @@ -28,7 +28,7 @@ #include #include "os/os_mman.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "util/u_memory.h" #include "util/u_format.h" #include "util/u_hash_table.h" diff --git a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c index 404ba58b08d..d76be4d5d32 100644 --- a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c +++ b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c @@ -24,7 +24,7 @@ #include "util/u_memory.h" #include "util/u_format.h" #include "util/u_inlines.h" -#include "os/os_time.h" +#include "util/os_time.h" #include "state_tracker/sw_winsys.h" #include "virgl_vtest_winsys.h" diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources index f8096feb232..104ecae8ed3 100644 --- a/src/util/Makefile.sources +++ b/src/util/Makefile.sources @@ -22,6 +22,8 @@ MESA_UTIL_FILES := \ macros.h \ mesa-sha1.c \ mesa-sha1.h \ + os_time.c \ + os_time.h \ sha1/sha1.c \ sha1/sha1.h \ ralloc.c \ diff --git a/src/util/meson.build b/src/util/meson.build index a9ab5bf545c..ac86c9e111e 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -46,6 +46,8 @@ files_mesa_util = files( 'macros.h', 'mesa-sha1.c', 'mesa-sha1.h', + 'os_time.c', + 'os_time.h', 'sha1/sha1.c', 'sha1/sha1.h', 'ralloc.c', diff --git a/src/util/os_time.c b/src/util/os_time.c new file mode 100644 index 00000000000..8d8291ff173 --- /dev/null +++ b/src/util/os_time.c @@ -0,0 +1,191 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * OS independent time-manipulation functions. + * + * @author Jose Fonseca + */ + +#include "os_time.h" + +/* TODO: fix this dependency */ +#include "gallium/include/pipe/p_config.h" + +#include "util/u_atomic.h" + +#if defined(PIPE_OS_UNIX) +# include /* timeval */ +# include /* timeval */ +# include /* sched_yield */ +# include +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +# include +#else +# error Unsupported OS +#endif + + +int64_t +os_time_get_nano(void) +{ +#if defined(PIPE_OS_LINUX) + + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + return tv.tv_nsec + tv.tv_sec*INT64_C(1000000000); + +#elif defined(PIPE_OS_UNIX) + + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_usec*INT64_C(1000) + tv.tv_sec*INT64_C(1000000000); + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + + static LARGE_INTEGER frequency; + LARGE_INTEGER counter; + int64_t secs, nanosecs; + if(!frequency.QuadPart) + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + /* Compute seconds and nanoseconds parts separately to + * reduce severity of precision loss. + */ + secs = counter.QuadPart / frequency.QuadPart; + nanosecs = (counter.QuadPart % frequency.QuadPart) * INT64_C(1000000000) + / frequency.QuadPart; + return secs*INT64_C(1000000000) + nanosecs; + +#else + +#error Unsupported OS + +#endif +} + + + +void +os_time_sleep(int64_t usecs) +{ +#if defined(PIPE_OS_LINUX) + struct timespec time; + time.tv_sec = usecs / 1000000; + time.tv_nsec = (usecs % 1000000) * 1000; + while (clock_nanosleep(CLOCK_MONOTONIC, 0, &time, &time) == EINTR); + +#elif defined(PIPE_OS_UNIX) + usleep(usecs); + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + DWORD dwMilliseconds = (DWORD) ((usecs + 999) / 1000); + /* Avoid Sleep(O) as that would cause to sleep for an undetermined duration */ + if (dwMilliseconds) { + Sleep(dwMilliseconds); + } +#else +# error Unsupported OS +#endif +} + + + +int64_t +os_time_get_absolute_timeout(uint64_t timeout) +{ + int64_t time, abs_timeout; + + /* Also check for the type upper bound. */ + if (timeout == OS_TIMEOUT_INFINITE || timeout > INT64_MAX) + return OS_TIMEOUT_INFINITE; + + time = os_time_get_nano(); + abs_timeout = time + (int64_t)timeout; + + /* Check for overflow. */ + if (abs_timeout < time) + return OS_TIMEOUT_INFINITE; + + return abs_timeout; +} + + +bool +os_wait_until_zero(volatile int *var, uint64_t timeout) +{ + if (!p_atomic_read(var)) + return true; + + if (!timeout) + return false; + + if (timeout == OS_TIMEOUT_INFINITE) { + while (p_atomic_read(var)) { +#if defined(PIPE_OS_UNIX) + sched_yield(); +#endif + } + return true; + } + else { + int64_t start_time = os_time_get_nano(); + int64_t end_time = start_time + timeout; + + while (p_atomic_read(var)) { + if (os_time_timeout(start_time, end_time, os_time_get_nano())) + return false; + +#if defined(PIPE_OS_UNIX) + sched_yield(); +#endif + } + return true; + } +} + + +bool +os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout) +{ + if (!p_atomic_read(var)) + return true; + + if (timeout == OS_TIMEOUT_INFINITE) + return os_wait_until_zero(var, OS_TIMEOUT_INFINITE); + + while (p_atomic_read(var)) { + if (os_time_get_nano() >= timeout) + return false; + +#if defined(PIPE_OS_UNIX) + sched_yield(); +#endif + } + return true; +} diff --git a/src/util/os_time.h b/src/util/os_time.h new file mode 100644 index 00000000000..049ab118db2 --- /dev/null +++ b/src/util/os_time.h @@ -0,0 +1,130 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * OS independent time-manipulation functions. + * + * @author Jose Fonseca + */ + +#ifndef _OS_TIME_H_ +#define _OS_TIME_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* must be equal to PIPE_TIMEOUT_INFINITE */ +#define OS_TIMEOUT_INFINITE 0xffffffffffffffffull + +/* + * Get the current time in nanoseconds from an unknown base. + */ +int64_t +os_time_get_nano(void); + + +/* + * Get the current time in microseconds from an unknown base. + */ +static inline int64_t +os_time_get(void) +{ + return os_time_get_nano() / 1000; +} + + +/* + * Sleep. + */ +void +os_time_sleep(int64_t usecs); + + +/* + * Helper function for detecting time outs, taking in account overflow. + * + * Returns true if the current time has elapsed beyond the specified interval. + */ +static inline bool +os_time_timeout(int64_t start, + int64_t end, + int64_t curr) +{ + if (start <= end) + return !(start <= curr && curr < end); + else + return !((start <= curr) || (curr < end)); +} + + +/** + * Convert a relative timeout in nanoseconds into an absolute timeout, + * in other words, it returns current time + timeout. + * os_time_get_nano() must be monotonic. + * OS_TIMEOUT_INFINITE is passed through unchanged. If the calculation + * overflows, OS_TIMEOUT_INFINITE is returned. + */ +int64_t +os_time_get_absolute_timeout(uint64_t timeout); + + +/** + * Wait until the variable at the given memory location is zero. + * + * \param var variable + * \param timeout timeout in ns, can be anything from 0 (no wait) to + * OS_TIMEOUT_INFINITE (wait forever) + * \return true if the variable is zero + */ +bool +os_wait_until_zero(volatile int *var, uint64_t timeout); + + +/** + * Wait until the variable at the given memory location is zero. + * The timeout is the absolute time when the waiting should stop. If it is + * less than or equal to the current time, it only returns the status and + * doesn't wait. OS_TIMEOUT_INFINITE waits forever. This requires that + * os_time_get_nano is monotonic. + * + * \param var variable + * \param timeout the time in ns when the waiting should stop + * \return true if the variable is zero + */ +bool +os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* _OS_TIME_H_ */