summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/os/os_time.c
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2015-06-27 00:05:26 +0200
committerMarek Olšák <[email protected]>2015-07-05 15:08:59 +0200
commit7316cc92f3810c9e53a22c35343190d8fb7980be (patch)
tree10eadbf00458d05015db1e4614ca11ccb53a36e0 /src/gallium/auxiliary/os/os_time.c
parent3836857a777a248dd212ce7a1d7307d2984fda7d (diff)
gallium/os: add conversion and wait functions for absolute timeouts
Absolute timeouts are used with the amdgpu kernel driver. It also makes waiting for several variables and fences at the same time easier (the timeout doesn't have to be recalculated after every wait call). Reviewed-by: Alex Deucher <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/os/os_time.c')
-rw-r--r--src/gallium/auxiliary/os/os_time.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c
index bd09452df16..3d2e4167222 100644
--- a/src/gallium/auxiliary/os/os_time.c
+++ b/src/gallium/auxiliary/os/os_time.c
@@ -96,6 +96,26 @@ os_time_sleep(int64_t usecs)
#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)
{
@@ -128,3 +148,24 @@ os_wait_until_zero(volatile int *var, uint64_t timeout)
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;
+}