mbox series

[v4,0/3] ui/cocoa: Run qemu_init in the main thread

Message ID 20220717073340.25830-1-akihiko.odaki@gmail.com (mailing list archive)
Headers show
Series ui/cocoa: Run qemu_init in the main thread | expand

Message

Akihiko Odaki July 17, 2022, 7:33 a.m. UTC
This work is based on:
https://patchew.org/QEMU/20220317125534.38706-1-philippe.mathieu.daude@gmail.com/

Simplify the initialization dance by running qemu_init() in the main
thread before the Cocoa event loop starts. The secondary thread only
runs only qemu_main_loop() and qemu_cleanup().

This fixes a case where addRemovableDevicesMenuItems() calls
qmp_query_block() while expecting the main thread to still hold
the BQL.

Overriding the code after calling qemu_init() is done by dynamically
replacing a function pointer variable, qemu_main when initializing
ui/cocoa, which unifies the static implementation of main() for
builds with ui/cocoa and ones without ui/cocoa.

v4: Asynchronously call -[NSApplication terminate:] to avoid potential
    deadlock with qemu_thread_join(). (Paolo Bonzini)

v3: Document functions involved in startup. (Peter Maydell)

v2: Restore allow_events flag to fix the crash reported by
    Philippe Mathieu-Daudé.

Akihiko Odaki (3):
  ui/cocoa: Run qemu_init in the main thread
  Revert "main-loop: Disable block backend global state assertion on
    Cocoa"
  meson: Allow to enable gtk and sdl while cocoa is enabled

 docs/devel/fuzzing.rst   |   4 +-
 include/qemu-main.h      |   3 +-
 include/qemu/main-loop.h |  13 ---
 include/sysemu/sysemu.h  |   2 +-
 meson.build              |  10 +--
 softmmu/main.c           |  14 ++--
 softmmu/vl.c             |   2 +-
 tests/qtest/fuzz/fuzz.c  |   2 +-
 ui/cocoa.m               | 168 ++++++++++++++-------------------------
 9 files changed, 76 insertions(+), 142 deletions(-)

Comments

Paolo Bonzini July 18, 2022, 4:09 p.m. UTC | #1
On 7/17/22 09:33, Akihiko Odaki wrote:
> This work is based on:
> https://patchew.org/QEMU/20220317125534.38706-1-philippe.mathieu.daude@gmail.com/
> 
> Simplify the initialization dance by running qemu_init() in the main
> thread before the Cocoa event loop starts. The secondary thread only
> runs only qemu_main_loop() and qemu_cleanup().
> 
> This fixes a case where addRemovableDevicesMenuItems() calls
> qmp_query_block() while expecting the main thread to still hold
> the BQL.
> 
> Overriding the code after calling qemu_init() is done by dynamically
> replacing a function pointer variable, qemu_main when initializing
> ui/cocoa, which unifies the static implementation of main() for
> builds with ui/cocoa and ones without ui/cocoa.
> 
> v4: Asynchronously call -[NSApplication terminate:] to avoid potential
>      deadlock with qemu_thread_join(). (Paolo Bonzini)
> 
> v3: Document functions involved in startup. (Peter Maydell)
> 
> v2: Restore allow_events flag to fix the crash reported by
>      Philippe Mathieu-Daudé.
> 
> Akihiko Odaki (3):
>    ui/cocoa: Run qemu_init in the main thread
>    Revert "main-loop: Disable block backend global state assertion on
>      Cocoa"
>    meson: Allow to enable gtk and sdl while cocoa is enabled
> 
>   docs/devel/fuzzing.rst   |   4 +-
>   include/qemu-main.h      |   3 +-
>   include/qemu/main-loop.h |  13 ---
>   include/sysemu/sysemu.h  |   2 +-
>   meson.build              |  10 +--
>   softmmu/main.c           |  14 ++--
>   softmmu/vl.c             |   2 +-
>   tests/qtest/fuzz/fuzz.c  |   2 +-
>   ui/cocoa.m               | 168 ++++++++++++++-------------------------
>   9 files changed, 76 insertions(+), 142 deletions(-)
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Thanks for continuing this work!

Paolo