diff options
author | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2017-10-22 17:38:46 +0200 |
---|---|---|
committer | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2017-11-03 19:39:30 +0100 |
commit | e0da8ed3f1c43aeeecd3ef23f943e434ae56dcb7 (patch) | |
tree | 2312f3d907d9330062748b6009ced837b0b5ae04 /src/util/u_queue.h | |
parent | a68df50b65269dadc923eff43769b1c1741c76dc (diff) |
util/u_queue: add util_queue_fence_wait_timeout
v2:
- style fixes
- fix missing timeout handling in futex path
Reviewed-by: Marek Olšák <marek.olsak@amd.com> (v1)
Diffstat (limited to 'src/util/u_queue.h')
-rw-r--r-- | src/util/u_queue.h | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/src/util/u_queue.h b/src/util/u_queue.h index 9c911fe6b4..7f9b43d72f 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -81,26 +81,6 @@ util_queue_fence_destroy(struct util_queue_fence *fence) } static inline void -util_queue_fence_wait(struct util_queue_fence *fence) -{ - uint32_t v = fence->val; - - if (likely(v == 0)) - return; - - do { - if (v != 2) { - v = p_atomic_cmpxchg(&fence->val, 1, 2); - if (v == 0) - return; - } - - futex_wait(&fence->val, 2); - v = fence->val; - } while(v != 0); -} - -static inline void util_queue_fence_signal(struct util_queue_fence *fence) { uint32_t val = p_atomic_xchg(&fence->val, 0); @@ -147,7 +127,6 @@ struct util_queue_fence { void util_queue_fence_init(struct util_queue_fence *fence); void util_queue_fence_destroy(struct util_queue_fence *fence); -void util_queue_fence_wait(struct util_queue_fence *fence); void util_queue_fence_signal(struct util_queue_fence *fence); /** @@ -170,6 +149,39 @@ util_queue_fence_is_signalled(struct util_queue_fence *fence) } #endif +void +_util_queue_fence_wait(struct util_queue_fence *fence); + +static inline void +util_queue_fence_wait(struct util_queue_fence *fence) +{ + if (unlikely(!util_queue_fence_is_signalled(fence))) + _util_queue_fence_wait(fence); +} + +bool +_util_queue_fence_wait_timeout(struct util_queue_fence *fence, + int64_t abs_timeout); + +/** + * Wait for the fence to be signaled with a timeout. + * + * \param fence the fence + * \param abs_timeout the absolute timeout in nanoseconds, relative to the + * clock provided by os_time_get_nano. + * + * \return true if the fence was signaled, false if the timeout occurred. + */ +static inline bool +util_queue_fence_wait_timeout(struct util_queue_fence *fence, + int64_t abs_timeout) +{ + if (util_queue_fence_is_signalled(fence)) + return true; + + return _util_queue_fence_wait_timeout(fence, abs_timeout); +} + typedef void (*util_queue_execute_func)(void *job, int thread_index); struct util_queue_job { |