Mesa (master): util/simple_mtx: add assert_locked()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 29 21:00:50 UTC 2020


Module: Mesa
Branch: master
Commit: 8aacaeca685c4e705a3237c2187f2f9bcef23339
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8aacaeca685c4e705a3237c2187f2f9bcef23339

Author: Rob Clark <robdclark at chromium.org>
Date:   Tue Apr 28 12:39:32 2020 -0700

util/simple_mtx: add assert_locked()

Signed-off-by: Rob Clark <robdclark at chromium.org>
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4810>

---

 src/util/simple_mtx.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/util/simple_mtx.h b/src/util/simple_mtx.h
index 4fc8a0d4df4..ec3889497f3 100644
--- a/src/util/simple_mtx.h
+++ b/src/util/simple_mtx.h
@@ -113,6 +113,12 @@ simple_mtx_unlock(simple_mtx_t *mtx)
    }
 }
 
+static inline void
+simple_mtx_assert_locked(simple_mtx_t *mtx)
+{
+   assert(mtx->val);
+}
+
 #else
 
 typedef mtx_t simple_mtx_t;
@@ -143,6 +149,22 @@ simple_mtx_unlock(simple_mtx_t *mtx)
    mtx_unlock(mtx);
 }
 
+static inline void
+simple_mtx_assert_locked(simple_mtx_t *mtx)
+{
+#ifdef DEBUG
+   /* NOTE: this would not work for recursive mutexes, but
+    * mtx_t doesn't support those
+    */
+   int ret = mtx_trylock(mtx);
+   assert(ret == thrd_busy);
+   if (ret == thrd_success)
+      mtx_unlock(mtx);
+#else
+   (void)mtx;
+#endif
+}
+
 #endif
 
 #endif



More information about the mesa-commit mailing list