]> git.proxmox.com Git - mirror_qemu.git/commitdiff
coroutine: Let CoMutex remember who holds it
authorKevin Wolf <kwolf@redhat.com>
Thu, 11 Aug 2016 15:45:06 +0000 (17:45 +0200)
committerKevin Wolf <kwolf@redhat.com>
Mon, 5 Sep 2016 17:06:48 +0000 (19:06 +0200)
In cases of deadlocks, knowing who holds a given CoMutex is really
helpful for debugging. Keeping the information around doesn't cost much
and allows us to add another assertion to keep the code correct, so
let's just add it.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
include/qemu/coroutine.h
util/qemu-coroutine-lock.c

index ac8d4c9cc824ec020e6bdb1cfe28c97af4d2b217..29a20782f0ab6367db3153d1ed3be0550c16b309 100644 (file)
@@ -143,6 +143,7 @@ bool qemu_co_queue_empty(CoQueue *queue);
  */
 typedef struct CoMutex {
     bool locked;
+    Coroutine *holder;
     CoQueue queue;
 } CoMutex;
 
index 22aa9abb304e9a603fb6600eab2a26e178af42cd..f30ee8184d8f5ed5e4b1f983ce64311796d6d9f0 100644 (file)
@@ -129,6 +129,7 @@ void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex)
     }
 
     mutex->locked = true;
+    mutex->holder = self;
 
     trace_qemu_co_mutex_lock_return(mutex, self);
 }
@@ -140,9 +141,11 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex)
     trace_qemu_co_mutex_unlock_entry(mutex, self);
 
     assert(mutex->locked == true);
+    assert(mutex->holder == self);
     assert(qemu_in_coroutine());
 
     mutex->locked = false;
+    mutex->holder = NULL;
     qemu_co_queue_next(&mutex->queue);
 
     trace_qemu_co_mutex_unlock_return(mutex, self);