uitl: Add R1_UNORM to the list of noaccess (no pack/unpack) formats.
[mesa.git] / src / util / simple_mtx.h
index c0cc13b3663ec75fb49619482f41221b79e63cc6..1bd57ac800195f117bc0859c74b333f5c3ffc8e0 100644 (file)
 #define _SIMPLE_MTX_H
 
 #include "util/futex.h"
+#include "util/macros.h"
 
 #include "c11/threads.h"
 
-#if defined(__GNUC__) && defined(HAVE_LINUX_FUTEX_H)
+#if UTIL_FUTEX_SUPPORTED
 
 /* mtx_t - Fast, simple mutex
  *
@@ -71,9 +72,11 @@ simple_mtx_init(simple_mtx_t *mtx, ASSERTED int type)
 }
 
 static inline void
-simple_mtx_destroy(simple_mtx_t *mtx)
+simple_mtx_destroy(ASSERTED simple_mtx_t *mtx)
 {
+#ifndef NDEBUG
    mtx->val = _SIMPLE_MTX_INVALID_VALUE;
+#endif
 }
 
 static inline void
@@ -110,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;
@@ -140,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