cpus: use coroutine TLS macros for iothread_locked

qemu_mutex_iothread_locked() may be used from coroutines. Standard
__thread variables cannot be used by coroutines. Use the coroutine TLS
macros instead.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220222140150.27240-5-stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Stefan Hajnoczi 2022-02-22 14:01:50 +00:00 committed by Kevin Wolf
parent 17c78154b0
commit d5d2b15ecf

View file

@ -25,6 +25,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "qemu-common.h" #include "qemu-common.h"
#include "monitor/monitor.h" #include "monitor/monitor.h"
#include "qemu/coroutine-tls.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-machine.h"
#include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-misc.h"
@ -473,11 +474,11 @@ bool qemu_in_vcpu_thread(void)
return current_cpu && qemu_cpu_is_self(current_cpu); return current_cpu && qemu_cpu_is_self(current_cpu);
} }
static __thread bool iothread_locked = false; QEMU_DEFINE_STATIC_CO_TLS(bool, iothread_locked)
bool qemu_mutex_iothread_locked(void) bool qemu_mutex_iothread_locked(void)
{ {
return iothread_locked; return get_iothread_locked();
} }
/* /*
@ -490,13 +491,13 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line)
g_assert(!qemu_mutex_iothread_locked()); g_assert(!qemu_mutex_iothread_locked());
bql_lock(&qemu_global_mutex, file, line); bql_lock(&qemu_global_mutex, file, line);
iothread_locked = true; set_iothread_locked(true);
} }
void qemu_mutex_unlock_iothread(void) void qemu_mutex_unlock_iothread(void)
{ {
g_assert(qemu_mutex_iothread_locked()); g_assert(qemu_mutex_iothread_locked());
iothread_locked = false; set_iothread_locked(false);
qemu_mutex_unlock(&qemu_global_mutex); qemu_mutex_unlock(&qemu_global_mutex);
} }