qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

coroutine: Add qemu_co_mutex_assert_locked()

Some functions require that the caller holds a certain CoMutex for them
to operate correctly. Add a function so that they can assert the lock is
really held.

Cc: qemu-stable@nongnu.org
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Tested-by: Michael Weiser <michael.weiser@gmx.de>
Reviewed-by: Michael Weiser <michael.weiser@gmx.de>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Max Reitz <mreitz@redhat.com>

+15
+15
include/qemu/coroutine.h
··· 167 167 */ 168 168 void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex); 169 169 170 + /** 171 + * Assert that the current coroutine holds @mutex. 172 + */ 173 + static inline coroutine_fn void qemu_co_mutex_assert_locked(CoMutex *mutex) 174 + { 175 + /* 176 + * mutex->holder doesn't need any synchronisation if the assertion holds 177 + * true because the mutex protects it. If it doesn't hold true, we still 178 + * don't mind if another thread takes or releases mutex behind our back, 179 + * because the condition will be false no matter whether we read NULL or 180 + * the pointer for any other coroutine. 181 + */ 182 + assert(atomic_read(&mutex->locked) && 183 + mutex->holder == qemu_coroutine_self()); 184 + } 170 185 171 186 /** 172 187 * CoQueues are a mechanism to queue coroutines in order to continue executing