aboutsummaryrefslogtreecommitdiff
path: root/stubs
diff options
context:
space:
mode:
authorEmanuele Giuseppe Esposito <eesposit@redhat.com>2022-03-03 10:15:46 -0500
committerKevin Wolf <kwolf@redhat.com>2022-03-04 18:18:15 +0100
commit6538692e2802666926e62d9309ddddda5ec9dc3b (patch)
tree2e846ea0c7ecaf993195b3fd55a7bf43b75afb5e /stubs
parentad6fe44bea25e9b0efe050d00751466ad2779631 (diff)
main-loop.h: introduce qemu_in_main_thread()
When invoked from the main loop, this function is the same as qemu_mutex_iothread_locked, and returns true if the BQL is held. When invoked from iothreads or tests, it returns true only if the current AioContext is the Main Loop. This essentially just extends qemu_mutex_iothread_locked to work also in unit tests or other users like storage-daemon, that run in the Main Loop but end up using the implementation in stubs/iothread-lock.c. Using qemu_mutex_iothread_locked in unit tests defaults to false because they use the implementation in stubs/iothread-lock, making all assertions added in next patches fail despite the AioContext is still the main loop. See the comment in the function header for more information. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Message-Id: <20220303151616.325444-2-eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'stubs')
-rw-r--r--stubs/iothread-lock-block.c8
-rw-r--r--stubs/meson.build3
2 files changed, 11 insertions, 0 deletions
diff --git a/stubs/iothread-lock-block.c b/stubs/iothread-lock-block.c
new file mode 100644
index 0000000000..c88ed70462
--- /dev/null
+++ b/stubs/iothread-lock-block.c
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
+
+bool qemu_in_main_thread(void)
+{
+ return qemu_get_current_aio_context() == qemu_get_aio_context();
+}
+
diff --git a/stubs/meson.build b/stubs/meson.build
index d359cbe1ad..6f80fec761 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -17,6 +17,9 @@ if linux_io_uring.found()
stub_ss.add(files('io_uring.c'))
endif
stub_ss.add(files('iothread-lock.c'))
+if have_block
+ stub_ss.add(files('iothread-lock-block.c'))
+endif
stub_ss.add(files('isa-bus.c'))
stub_ss.add(files('is-daemonized.c'))
if libaio.found()