From: Rob Clark Date: Tue, 28 Apr 2020 19:39:32 +0000 (-0700) Subject: util/simple_mtx: add assert_locked() X-Git-Tag: upstream/21.0.0~10578 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8aacaeca685c4e705a3237c2187f2f9bcef23339;p=platform%2Fupstream%2Fmesa.git util/simple_mtx: add assert_locked() Signed-off-by: Rob Clark Reviewed-by: Eric Anholt Part-of: --- diff --git a/src/util/simple_mtx.h b/src/util/simple_mtx.h index 4fc8a0d..ec38894 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