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 <robdclark@gmail.com>
This commit is contained in:
Rob Clark 2016-07-21 13:51:36 -04:00
parent 9f0eb69527
commit 010e4b2d52
1 changed files with 16 additions and 0 deletions

View File

@ -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
*/