xemu/util/qemu-thread-common.h
Paolo Bonzini ba59fb778e QemuMutex: support --enable-debug-mutex
We have had some tracing tools for mutex but it's not easy to use them
for e.g. dead locks.  Let's provide "--enable-debug-mutex" parameter
when configure to allow QemuMutex to store the last owner that took
specific lock.  It will be easy to use this tool to debug deadlocks
since we can directly know who took the lock then as long as we can have
a debugger attached to the process.

Reviewed-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180425025459.5258-4-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-06-28 19:05:32 +02:00

56 lines
1.2 KiB
C

/*
* Common qemu-thread implementation header file.
*
* Copyright Red Hat, Inc. 2018
*
* Authors:
* Peter Xu <peterx@redhat.com>,
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#ifndef QEMU_THREAD_COMMON_H
#define QEMU_THREAD_COMMON_H
#include "qemu/typedefs.h"
#include "qemu/thread.h"
#include "trace.h"
static inline void qemu_mutex_post_init(QemuMutex *mutex)
{
#ifdef CONFIG_DEBUG_MUTEX
mutex->file = NULL;
mutex->line = 0;
#endif
mutex->initialized = true;
}
static inline void qemu_mutex_pre_lock(QemuMutex *mutex,
const char *file, int line)
{
trace_qemu_mutex_lock(mutex, file, line);
}
static inline void qemu_mutex_post_lock(QemuMutex *mutex,
const char *file, int line)
{
#ifdef CONFIG_DEBUG_MUTEX
mutex->file = file;
mutex->line = line;
#endif
trace_qemu_mutex_locked(mutex, file, line);
}
static inline void qemu_mutex_pre_unlock(QemuMutex *mutex,
const char *file, int line)
{
#ifdef CONFIG_DEBUG_MUTEX
mutex->file = NULL;
mutex->line = 0;
#endif
trace_qemu_mutex_unlock(mutex, file, line);
}
#endif