From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fam Zheng <fam@euphon.net>,
fweimer@redhat.com, thuth@redhat.com,
Daniel Berrange <berrange@redhat.com>,
qemu-block@nongnu.org,
Richard Henderson <richard.henderson@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Warner Losh <imp@bsdimp.com>,
sguelton@redhat.com
Subject: [RFC v3 2/4] util/async: replace __thread with QEMU TLS macros
Date: Mon, 6 Dec 2021 14:26:30 +0000 [thread overview]
Message-ID: <20211206142632.116925-3-stefanha@redhat.com> (raw)
In-Reply-To: <20211206142632.116925-1-stefanha@redhat.com>
QEMU TLS macros must be used to make TLS variables safe with coroutines.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
util/async.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/util/async.c b/util/async.c
index 6f6717a34b..ddd9f24419 100644
--- a/util/async.c
+++ b/util/async.c
@@ -32,6 +32,7 @@
#include "qemu/rcu_queue.h"
#include "block/raw-aio.h"
#include "qemu/coroutine_int.h"
+#include "qemu/coroutine-tls.h"
#include "trace.h"
/***********************************************************/
@@ -669,12 +670,13 @@ void aio_context_release(AioContext *ctx)
qemu_rec_mutex_unlock(&ctx->lock);
}
-static __thread AioContext *my_aiocontext;
+QEMU_DEFINE_STATIC_CO_TLS(AioContext *, my_aiocontext)
AioContext *qemu_get_current_aio_context(void)
{
- if (my_aiocontext) {
- return my_aiocontext;
+ AioContext *ctx = get_my_aiocontext();
+ if (ctx) {
+ return ctx;
}
if (qemu_mutex_iothread_locked()) {
/* Possibly in a vCPU thread. */
@@ -685,6 +687,6 @@ AioContext *qemu_get_current_aio_context(void)
void qemu_set_current_aio_context(AioContext *ctx)
{
- assert(!my_aiocontext);
- my_aiocontext = ctx;
+ assert(!get_my_aiocontext());
+ set_my_aiocontext(ctx);
}
--
2.33.1
next prev parent reply other threads:[~2021-12-06 14:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-06 14:26 [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 1/4] " Stefan Hajnoczi
2021-12-06 14:26 ` Stefan Hajnoczi [this message]
2021-12-06 14:26 ` [RFC v3 3/4] rcu: use coroutine TLS macros Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 4/4] cpus: use coroutine TLS macros for iothread_locked Stefan Hajnoczi
2021-12-06 14:34 ` [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables Peter Maydell
2021-12-07 13:34 ` Stefan Hajnoczi
2021-12-07 13:53 ` Stefan Hajnoczi
2021-12-07 13:55 ` Peter Maydell
2021-12-07 16:29 ` Stefan Hajnoczi
2021-12-13 14:09 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211206142632.116925-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=berrange@redhat.com \
--cc=fam@euphon.net \
--cc=fweimer@redhat.com \
--cc=imp@bsdimp.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sguelton@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).