summaryrefslogtreecommitdiffstats
path: root/src/util/u_queue.h
diff options
context:
space:
mode:
authorNicolai Hähnle <[email protected]>2017-10-22 17:38:46 +0200
committerNicolai Hähnle <[email protected]>2017-11-09 13:58:10 +0100
commite3a8013de8ca854d21225be00f123ccf63f9060f (patch)
treeb0163adc1cbfe8ac52e7c98987ebd30d1d4e8f25 /src/util/u_queue.h
parentf1a364878431c8c5f4fd38b40b9766449e49f552 (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 <[email protected]>
Diffstat (limited to 'src/util/u_queue.h')
-rw-r--r--src/util/u_queue.h54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/util/u_queue.h b/src/util/u_queue.h
index a54ec710114..ec028157480 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 {