summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2016-07-21 13:51:36 -0400
committerRob Clark <[email protected]>2016-07-30 09:23:42 -0400
commit010e4b2d52d5b5ab1eb866dfa0a2df5b984c343d (patch)
treee55cd653f59dfc38352a21b1e0226e58c8125d55
parent9f0eb6952790bffe2670f26d399f15acec199cac (diff)
os: add pipe_mutex_assert_locked()
Would be nice if we could also have lockdep, like in the linux kernel. But this is better than nothing. Signed-off-by: Rob Clark <[email protected]>
-rw-r--r--src/gallium/auxiliary/os/os_thread.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h
index be8adcc6cf2..ec8adbc75bb 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -116,6 +116,22 @@ typedef mtx_t pipe_mutex;
#define pipe_mutex_unlock(mutex) \
(void) mtx_unlock(&(mutex))
+#define pipe_mutex_assert_locked(mutex) \
+ __pipe_mutex_assert_locked(&(mutex))
+
+static inline void
+__pipe_mutex_assert_locked(pipe_mutex *mutex)
+{
+#ifdef DEBUG
+ /* NOTE: this would not work for recursive mutexes, but
+ * pipe_mutex doesn't support those
+ */
+ int ret = mtx_trylock(mutex);
+ assert(ret == thrd_busy);
+ if (ret == thrd_success)
+ mtx_unlock(mutex);
+#endif
+}
/* pipe_condvar
*/