All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Create menus in iothread
@ 2022-03-07 13:49 Akihiko Odaki
  2022-03-07 13:49 ` [PATCH v2 1/2] ui/cocoa: Move create_initial_menus Akihiko Odaki
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Akihiko Odaki @ 2022-03-07 13:49 UTC (permalink / raw)
  Cc: Peter Maydell, qemu-devel, Akihiko Odaki, Gerd Hoffmann

ui/cocoa: Create menus in iothread

Commit 0439c5a4623d674efa0c72abd62ca6e98bb7cf87 introduced an
assertion that blk_all_next is called in the main thread. The function
is called in the following chain:
- blk_all_next
- qmp_query_block
- addRemovableDevicesMenuItems
- main

This change moves the menu creation to the iothread. This also changes
the menu creation procedure to construct the entire menu tree before
setting to NSApp, which is necessary because a menu set once cannot be
modified if NSApp is already running.

v2: Separate a change moving create_initial_menus (Peter Maydell)

Akihiko Odaki (2):
  ui/cocoa: Move create_initial_menus
  ui/cocoa: Create menus in iothread

 ui/cocoa.m | 209 +++++++++++++++++++++++++----------------------------
 1 file changed, 98 insertions(+), 111 deletions(-)

-- 
2.32.0 (Apple Git-132)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] ui/cocoa: Move create_initial_menus
  2022-03-07 13:49 [PATCH v2 0/2] Create menus in iothread Akihiko Odaki
@ 2022-03-07 13:49 ` Akihiko Odaki
  2022-03-07 13:49 ` [PATCH v2 2/2] ui/cocoa: Create menus in iothread Akihiko Odaki
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Akihiko Odaki @ 2022-03-07 13:49 UTC (permalink / raw)
  Cc: Peter Maydell, qemu-devel, Akihiko Odaki, Gerd Hoffmann

The following change would make it use add_console_menu_entries and
addRemovableDevicesMenuItems so it should come after them.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 ui/cocoa.m | 178 ++++++++++++++++++++++++++---------------------------
 1 file changed, 89 insertions(+), 89 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 8ab9ab5e84d..6c6e82afb90 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1604,6 +1604,95 @@ - (void)sendEvent:(NSEvent *)event
 }
 @end
 
+/* Returns a name for a given console */
+static NSString * getConsoleName(QemuConsole * console)
+{
+    g_autofree char *label = qemu_console_get_label(console);
+
+    return [NSString stringWithUTF8String:label];
+}
+
+/* Add an entry to the View menu for each console */
+static void add_console_menu_entries(void)
+{
+    NSMenu *menu;
+    NSMenuItem *menuItem;
+    int index = 0;
+
+    menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu];
+
+    [menu addItem:[NSMenuItem separatorItem]];
+
+    while (qemu_console_lookup_by_index(index) != NULL) {
+        menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index))
+                                               action: @selector(displayConsole:) keyEquivalent: @""] autorelease];
+        [menuItem setTag: index];
+        [menu addItem: menuItem];
+        index++;
+    }
+}
+
+/* Make menu items for all removable devices.
+ * Each device is given an 'Eject' and 'Change' menu item.
+ */
+static void addRemovableDevicesMenuItems(void)
+{
+    NSMenu *menu;
+    NSMenuItem *menuItem;
+    BlockInfoList *currentDevice, *pointerToFree;
+    NSString *deviceName;
+
+    currentDevice = qmp_query_block(NULL);
+    pointerToFree = currentDevice;
+
+    menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
+
+    // Add a separator between related groups of menu items
+    [menu addItem:[NSMenuItem separatorItem]];
+
+    // Set the attributes to the "Removable Media" menu item
+    NSString *titleString = @"Removable Media";
+    NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString];
+    NSColor *newColor = [NSColor blackColor];
+    NSFontManager *fontManager = [NSFontManager sharedFontManager];
+    NSFont *font = [fontManager fontWithFamily:@"Helvetica"
+                                          traits:NSBoldFontMask|NSItalicFontMask
+                                          weight:0
+                                            size:14];
+    [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])];
+    [attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])];
+    [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])];
+
+    // Add the "Removable Media" menu item
+    menuItem = [NSMenuItem new];
+    [menuItem setAttributedTitle: attString];
+    [menuItem setEnabled: NO];
+    [menu addItem: menuItem];
+
+    /* Loop through all the block devices in the emulator */
+    while (currentDevice) {
+        deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain];
+
+        if(currentDevice->value->removable) {
+            menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device]
+                                                  action: @selector(changeDeviceMedia:)
+                                           keyEquivalent: @""];
+            [menu addItem: menuItem];
+            [menuItem setRepresentedObject: deviceName];
+            [menuItem autorelease];
+
+            menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device]
+                                                  action: @selector(ejectDeviceMedia:)
+                                           keyEquivalent: @""];
+            [menu addItem: menuItem];
+            [menuItem setRepresentedObject: deviceName];
+            [menuItem autorelease];
+        }
+        currentDevice = currentDevice->next;
+    }
+    qapi_free_BlockInfoList(pointerToFree);
+}
+
 static void create_initial_menus(void)
 {
     // Add menus
@@ -1695,95 +1784,6 @@ static void create_initial_menus(void)
     [[NSApp mainMenu] addItem:menuItem];
 }
 
-/* Returns a name for a given console */
-static NSString * getConsoleName(QemuConsole * console)
-{
-    g_autofree char *label = qemu_console_get_label(console);
-
-    return [NSString stringWithUTF8String:label];
-}
-
-/* Add an entry to the View menu for each console */
-static void add_console_menu_entries(void)
-{
-    NSMenu *menu;
-    NSMenuItem *menuItem;
-    int index = 0;
-
-    menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu];
-
-    [menu addItem:[NSMenuItem separatorItem]];
-
-    while (qemu_console_lookup_by_index(index) != NULL) {
-        menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index))
-                                               action: @selector(displayConsole:) keyEquivalent: @""] autorelease];
-        [menuItem setTag: index];
-        [menu addItem: menuItem];
-        index++;
-    }
-}
-
-/* Make menu items for all removable devices.
- * Each device is given an 'Eject' and 'Change' menu item.
- */
-static void addRemovableDevicesMenuItems(void)
-{
-    NSMenu *menu;
-    NSMenuItem *menuItem;
-    BlockInfoList *currentDevice, *pointerToFree;
-    NSString *deviceName;
-
-    currentDevice = qmp_query_block(NULL);
-    pointerToFree = currentDevice;
-
-    menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
-
-    // Add a separator between related groups of menu items
-    [menu addItem:[NSMenuItem separatorItem]];
-
-    // Set the attributes to the "Removable Media" menu item
-    NSString *titleString = @"Removable Media";
-    NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString];
-    NSColor *newColor = [NSColor blackColor];
-    NSFontManager *fontManager = [NSFontManager sharedFontManager];
-    NSFont *font = [fontManager fontWithFamily:@"Helvetica"
-                                          traits:NSBoldFontMask|NSItalicFontMask
-                                          weight:0
-                                            size:14];
-    [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])];
-    [attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])];
-    [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])];
-
-    // Add the "Removable Media" menu item
-    menuItem = [NSMenuItem new];
-    [menuItem setAttributedTitle: attString];
-    [menuItem setEnabled: NO];
-    [menu addItem: menuItem];
-
-    /* Loop through all the block devices in the emulator */
-    while (currentDevice) {
-        deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain];
-
-        if(currentDevice->value->removable) {
-            menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device]
-                                                  action: @selector(changeDeviceMedia:)
-                                           keyEquivalent: @""];
-            [menu addItem: menuItem];
-            [menuItem setRepresentedObject: deviceName];
-            [menuItem autorelease];
-
-            menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device]
-                                                  action: @selector(ejectDeviceMedia:)
-                                           keyEquivalent: @""];
-            [menu addItem: menuItem];
-            [menuItem setRepresentedObject: deviceName];
-            [menuItem autorelease];
-        }
-        currentDevice = currentDevice->next;
-    }
-    qapi_free_BlockInfoList(pointerToFree);
-}
-
 @interface QemuCocoaPasteboardTypeOwner : NSObject<NSPasteboardTypeOwner>
 @end
 
-- 
2.32.0 (Apple Git-132)



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] ui/cocoa: Create menus in iothread
  2022-03-07 13:49 [PATCH v2 0/2] Create menus in iothread Akihiko Odaki
  2022-03-07 13:49 ` [PATCH v2 1/2] ui/cocoa: Move create_initial_menus Akihiko Odaki
@ 2022-03-07 13:49 ` Akihiko Odaki
  2022-03-07 15:32 ` [PATCH v2 0/2] " Paolo Bonzini
  2022-03-20 21:46 ` Philippe Mathieu-Daudé
  3 siblings, 0 replies; 6+ messages in thread
From: Akihiko Odaki @ 2022-03-07 13:49 UTC (permalink / raw)
  Cc: Peter Maydell, qemu-devel, Akihiko Odaki, Gerd Hoffmann

Commit 0439c5a4623d674efa0c72abd62ca6e98bb7cf87 introduced an
assertion that blk_all_next is called in the main thread. The function
is called in the following chain:
- blk_all_next
- qmp_query_block
- addRemovableDevicesMenuItems
- main

This change moves the menu creation to the iothread. This also changes
the menu creation procedure to construct the entire menu tree before
setting to NSApp, which is necessary because a menu set once cannot be
modified if NSApp is already running.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 ui/cocoa.m | 59 +++++++++++++++++++++---------------------------------
 1 file changed, 23 insertions(+), 36 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 6c6e82afb90..edacbef9f7a 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1613,14 +1613,11 @@ - (void)sendEvent:(NSEvent *)event
 }
 
 /* Add an entry to the View menu for each console */
-static void add_console_menu_entries(void)
+static void add_console_menu_entries(NSMenu *menu)
 {
-    NSMenu *menu;
     NSMenuItem *menuItem;
     int index = 0;
 
-    menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu];
-
     [menu addItem:[NSMenuItem separatorItem]];
 
     while (qemu_console_lookup_by_index(index) != NULL) {
@@ -1635,9 +1632,8 @@ static void add_console_menu_entries(void)
 /* Make menu items for all removable devices.
  * Each device is given an 'Eject' and 'Change' menu item.
  */
-static void addRemovableDevicesMenuItems(void)
+static void addRemovableDevicesMenuItems(NSMenu *menu)
 {
-    NSMenu *menu;
     NSMenuItem *menuItem;
     BlockInfoList *currentDevice, *pointerToFree;
     NSString *deviceName;
@@ -1645,8 +1641,6 @@ static void addRemovableDevicesMenuItems(void)
     currentDevice = qmp_query_block(NULL);
     pointerToFree = currentDevice;
 
-    menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
-
     // Add a separator between related groups of menu items
     [menu addItem:[NSMenuItem separatorItem]];
 
@@ -1693,17 +1687,19 @@ static void addRemovableDevicesMenuItems(void)
     qapi_free_BlockInfoList(pointerToFree);
 }
 
-static void create_initial_menus(void)
+static void create_menus(void)
 {
     // Add menus
+    NSString    *title = [[[NSBundle mainBundle] executablePath] lastPathComponent];
+    NSMenu      *mainMenu;
     NSMenu      *menu;
     NSMenuItem  *menuItem;
 
-    [NSApp setMainMenu:[[NSMenu alloc] init]];
+    mainMenu = [[NSMenu alloc] initWithTitle:@"Main Menu"];
     [NSApp setServicesMenu:[[NSMenu alloc] initWithTitle:@"Services"]];
 
     // Application menu
-    menu = [[NSMenu alloc] initWithTitle:@""];
+    menu = [[NSMenu alloc] initWithTitle:title];
     [menu addItemWithTitle:@"About QEMU" action:@selector(do_about_menu_item:) keyEquivalent:@""]; // About QEMU
     [menu addItem:[NSMenuItem separatorItem]]; //Separator
     menuItem = [menu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
@@ -1715,10 +1711,8 @@ static void create_initial_menus(void)
     [menu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; // Show All
     [menu addItem:[NSMenuItem separatorItem]]; //Separator
     [menu addItemWithTitle:@"Quit QEMU" action:@selector(terminate:) keyEquivalent:@"q"];
-    menuItem = [[NSMenuItem alloc] initWithTitle:@"Apple" action:nil keyEquivalent:@""];
+    menuItem = [mainMenu addItemWithTitle:title action:nil keyEquivalent:@""];
     [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
-    [NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; // Workaround (this method is private since 10.4+)
 
     // Machine menu
     menu = [[NSMenu alloc] initWithTitle: @"Machine"];
@@ -1730,17 +1724,17 @@ static void create_initial_menus(void)
     [menu addItem: [NSMenuItem separatorItem]];
     [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Reset" action: @selector(restartQEMU:) keyEquivalent: @""] autorelease]];
     [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Power Down" action: @selector(powerDownQEMU:) keyEquivalent: @""] autorelease]];
-    menuItem = [[[NSMenuItem alloc] initWithTitle: @"Machine" action:nil keyEquivalent:@""] autorelease];
+    addRemovableDevicesMenuItems(menu);
+    menuItem = [mainMenu addItemWithTitle: @"Machine" action:nil keyEquivalent:@""];
     [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
 
     // View menu
     menu = [[NSMenu alloc] initWithTitle:@"View"];
     [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
     [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:@selector(zoomToFit:) keyEquivalent:@""] autorelease]];
-    menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
+    add_console_menu_entries(menu);
+    menuItem = [mainMenu addItemWithTitle:@"View" action:nil keyEquivalent:@""];
     [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
 
     // Speed menu
     menu = [[NSMenu alloc] initWithTitle:@"Speed"];
@@ -1764,24 +1758,23 @@ static void create_initial_menus(void)
         [menuItem setTag: throttle_pct];
         [menu addItem: menuItem];
     }
-    menuItem = [[[NSMenuItem alloc] initWithTitle:@"Speed" action:nil keyEquivalent:@""] autorelease];
+    menuItem = [mainMenu addItemWithTitle:@"Speed" action:nil keyEquivalent:@""];
     [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
 
     // Window menu
     menu = [[NSMenu alloc] initWithTitle:@"Window"];
     [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; // Miniaturize
-    menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease];
+    menuItem = [mainMenu addItemWithTitle:@"Window" action:nil keyEquivalent:@""];
     [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
     [NSApp setWindowsMenu:menu];
 
     // Help menu
     menu = [[NSMenu alloc] initWithTitle:@"Help"];
     [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Documentation" action:@selector(showQEMUDoc:) keyEquivalent:@"?"] autorelease]]; // QEMU Help
-    menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease];
+    menuItem = [mainMenu addItemWithTitle:@"Window" action:nil keyEquivalent:@""];
     [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
+
+    [NSApp setMainMenu:mainMenu];
 }
 
 @interface QemuCocoaPasteboardTypeOwner : NSObject<NSPasteboardTypeOwner>
@@ -1947,18 +1940,6 @@ int main (int argc, char **argv) {
 
     [QemuApplication sharedApplication];
 
-    create_initial_menus();
-
-    /*
-     * Create the menu entries which depend on QEMU state (for consoles
-     * and removeable devices). These make calls back into QEMU functions,
-     * which is OK because at this point we know that the second thread
-     * holds the iothread lock and is synchronously waiting for us to
-     * finish.
-     */
-    add_console_menu_entries();
-    addRemovableDevicesMenuItems();
-
     // Create an Application controller
     QemuCocoaAppController *appController = [[QemuCocoaAppController alloc] init];
     [NSApp setDelegate:appController];
@@ -2050,6 +2031,8 @@ static void cocoa_refresh(DisplayChangeListener *dcl)
 
 static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
 {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
 
     /* Tell main thread to go ahead and create the app and enter the run loop */
@@ -2057,6 +2040,8 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
     qemu_sem_wait(&app_started_sem);
     COCOA_DEBUG("cocoa_display_init: app start completed\n");
 
+    create_menus();
+
     /* if fullscreen mode is to be used */
     if (opts->has_full_screen && opts->full_screen) {
         dispatch_async(dispatch_get_main_queue(), ^{
@@ -2074,6 +2059,8 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
     qemu_event_init(&cbevent, false);
     cbowner = [[QemuCocoaPasteboardTypeOwner alloc] init];
     qemu_clipboard_peer_register(&cbpeer);
+
+    [pool release];
 }
 
 static QemuDisplay qemu_display_cocoa = {
-- 
2.32.0 (Apple Git-132)



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Create menus in iothread
  2022-03-07 13:49 [PATCH v2 0/2] Create menus in iothread Akihiko Odaki
  2022-03-07 13:49 ` [PATCH v2 1/2] ui/cocoa: Move create_initial_menus Akihiko Odaki
  2022-03-07 13:49 ` [PATCH v2 2/2] ui/cocoa: Create menus in iothread Akihiko Odaki
@ 2022-03-07 15:32 ` Paolo Bonzini
  2022-03-07 15:59   ` Akihiko Odaki
  2022-03-20 21:46 ` Philippe Mathieu-Daudé
  3 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2022-03-07 15:32 UTC (permalink / raw)
  To: Akihiko Odaki; +Cc: Peter Maydell, qemu-devel, Gerd Hoffmann

On 3/7/22 14:49, Akihiko Odaki wrote:
> ui/cocoa: Create menus in iothread
> 
> Commit 0439c5a4623d674efa0c72abd62ca6e98bb7cf87 introduced an
> assertion that blk_all_next is called in the main thread. The function
> is called in the following chain:
> - blk_all_next
> - qmp_query_block
> - addRemovableDevicesMenuItems
> - main
> 
> This change moves the menu creation to the iothread. This also changes
> the menu creation procedure to construct the entire menu tree before
> setting to NSApp, which is necessary because a menu set once cannot be
> modified if NSApp is already running.

I wonder if you actually need the iothread/secondary thread separation 
during initialization.  It's needed to run the "secondary" main loop, 
but until that point nobody should care what thread things run on. 
cocoa_display_init() is close enough to the end of qemu_init() that I 
think you can just do:

   main()
     qemu_init()
       /* takes iothread lock */
       cocoa_display_init()
         /* just save a few values from opts */
     ... create menus ...
     [NSApp run]
       applicationDidFinishLaunching:
         /* do what was in cocoa_display_init() */
         qemu_unlock_mutex_iothread();
         qemu_thread_create(call_qemu_main_loop)
                                                    call_qemu_main_loop()
                                                      qemu_main_loop()

This might even obsolete the allow_events hack, because now the main 
thread has the iothread lock until applicationDidFinishLaunching:.

Paolo

> v2: Separate a change moving create_initial_menus (Peter Maydell)
> 
> Akihiko Odaki (2):
>    ui/cocoa: Move create_initial_menus
>    ui/cocoa: Create menus in iothread
> 
>   ui/cocoa.m | 209 +++++++++++++++++++++++++----------------------------
>   1 file changed, 98 insertions(+), 111 deletions(-)
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Create menus in iothread
  2022-03-07 15:32 ` [PATCH v2 0/2] " Paolo Bonzini
@ 2022-03-07 15:59   ` Akihiko Odaki
  0 siblings, 0 replies; 6+ messages in thread
From: Akihiko Odaki @ 2022-03-07 15:59 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Peter Maydell, qemu Developers, Gerd Hoffmann

On Tue, Mar 8, 2022 at 12:32 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 3/7/22 14:49, Akihiko Odaki wrote:
> > ui/cocoa: Create menus in iothread
> >
> > Commit 0439c5a4623d674efa0c72abd62ca6e98bb7cf87 introduced an
> > assertion that blk_all_next is called in the main thread. The function
> > is called in the following chain:
> > - blk_all_next
> > - qmp_query_block
> > - addRemovableDevicesMenuItems
> > - main
> >
> > This change moves the menu creation to the iothread. This also changes
> > the menu creation procedure to construct the entire menu tree before
> > setting to NSApp, which is necessary because a menu set once cannot be
> > modified if NSApp is already running.
>
> I wonder if you actually need the iothread/secondary thread separation
> during initialization.  It's needed to run the "secondary" main loop,
> but until that point nobody should care what thread things run on.
> cocoa_display_init() is close enough to the end of qemu_init() that I
> think you can just do:
>
>    main()
>      qemu_init()
>        /* takes iothread lock */
>        cocoa_display_init()
>          /* just save a few values from opts */
>      ... create menus ...
>      [NSApp run]
>        applicationDidFinishLaunching:
>          /* do what was in cocoa_display_init() */
>          qemu_unlock_mutex_iothread();
>          qemu_thread_create(call_qemu_main_loop)
>                                                     call_qemu_main_loop()
>                                                       qemu_main_loop()
>
> This might even obsolete the allow_events hack, because now the main
> thread has the iothread lock until applicationDidFinishLaunching:.

allow_events was necessary not because of the separation of the
thread, but because cocoa_display_init waits the main thread for
finishing the initialization. It can be simply removed if it doesn't
wait for app_started_sem.

Regards,
Akihiko Odaki

>
> Paolo
>
> > v2: Separate a change moving create_initial_menus (Peter Maydell)
> >
> > Akihiko Odaki (2):
> >    ui/cocoa: Move create_initial_menus
> >    ui/cocoa: Create menus in iothread
> >
> >   ui/cocoa.m | 209 +++++++++++++++++++++++++----------------------------
> >   1 file changed, 98 insertions(+), 111 deletions(-)
> >
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Create menus in iothread
  2022-03-07 13:49 [PATCH v2 0/2] Create menus in iothread Akihiko Odaki
                   ` (2 preceding siblings ...)
  2022-03-07 15:32 ` [PATCH v2 0/2] " Paolo Bonzini
@ 2022-03-20 21:46 ` Philippe Mathieu-Daudé
  3 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-03-20 21:46 UTC (permalink / raw)
  To: Akihiko Odaki; +Cc: Peter Maydell, qemu-devel, Gerd Hoffmann

On 7/3/22 14:49, Akihiko Odaki wrote:
> ui/cocoa: Create menus in iothread
> 
> Commit 0439c5a4623d674efa0c72abd62ca6e98bb7cf87 introduced an
> assertion that blk_all_next is called in the main thread. The function
> is called in the following chain:
> - blk_all_next
> - qmp_query_block
> - addRemovableDevicesMenuItems
> - main
> 
> This change moves the menu creation to the iothread. This also changes
> the menu creation procedure to construct the entire menu tree before
> setting to NSApp, which is necessary because a menu set once cannot be
> modified if NSApp is already running.
> 
> v2: Separate a change moving create_initial_menus (Peter Maydell)
> 
> Akihiko Odaki (2):
>    ui/cocoa: Move create_initial_menus
>    ui/cocoa: Create menus in iothread

Patch #2 doesn't apply anymore, can you respin?


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-20 21:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 13:49 [PATCH v2 0/2] Create menus in iothread Akihiko Odaki
2022-03-07 13:49 ` [PATCH v2 1/2] ui/cocoa: Move create_initial_menus Akihiko Odaki
2022-03-07 13:49 ` [PATCH v2 2/2] ui/cocoa: Create menus in iothread Akihiko Odaki
2022-03-07 15:32 ` [PATCH v2 0/2] " Paolo Bonzini
2022-03-07 15:59   ` Akihiko Odaki
2022-03-20 21:46 ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.