From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXsko-000406-7F for qemu-devel@nongnu.org; Thu, 11 Aug 2016 12:22:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXskn-0004R3-9l for qemu-devel@nongnu.org; Thu, 11 Aug 2016 12:22:46 -0400 From: Kevin Wolf Date: Thu, 11 Aug 2016 18:22:21 +0200 Message-Id: <1470932542-12311-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1470932542-12311-1-git-send-email-kwolf@redhat.com> References: <1470932542-12311-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] coroutine: Let CoMutex remember who holds it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org 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 --- include/qemu/coroutine.h | 1 + util/qemu-coroutine-lock.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index ac8d4c9..29a2078 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -143,6 +143,7 @@ bool qemu_co_queue_empty(CoQueue *queue); */ typedef struct CoMutex { bool locked; + Coroutine *holder; CoQueue queue; } CoMutex; diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 22aa9ab..f30ee81 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -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); -- 1.8.3.1