All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Akihiko Odaki <akihiko.odaki@gmail.com>,
	Peter Maydell <peter.maydell@linaro.org>
Cc: qemu Developers <qemu-devel@nongnu.org>
Subject: Re: [RFC uncompiled PATCH] cocoa: run qemu_init in the main thread
Date: Mon, 7 Mar 2022 18:21:32 +0100	[thread overview]
Message-ID: <89a0316d-7e9a-46d9-31cc-c3507483fffb@redhat.com> (raw)
In-Reply-To: <CAMVc7JVZSTpD5VL1Ls8CcWZsoEMMzsZsGApZ+tNkuFhMc8_+cA@mail.gmail.com>

On 3/7/22 17:41, Akihiko Odaki wrote:
>> That series doesn't remove the general design that has quite a bit
>> of "we know some other thread holds the lock and waits for us" code.
> Well, I don't think so. main no longer calls back QEMU code (and it
> should never do so in my opinion).

That's an arbitrary limitation.  With my patch, until [NSApp run] only 
the main thread has the lock and therefore it can do anything.  In my 
patch I decided to minimize the changes, but if 
register_displaychangelistener() and qemu_clipboard_peer_register() can 
be moved earlier, then the iothread could even be unlocked before [NSApp 
run].

There's also the advantage that the flow is a lot more similar between 
"-display cocoa" and "-display none", and also between --enable-cocoa 
and --disable-cocoa builds.

Then main() remains as

     /* doesn't hurt in the !cocoa case */
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

     qemu_init(argc, argv);
     if (!have_cocoa_display) {
         qemu_main_loop();
         qemu_cleanup();
     } else {
         QemuCocoaAppController *appController = 
[[QemuCocoaAppController alloc] init];
         [NSApp setDelegate:appController];
         [NSApp run];
         [appController release];
     }
     [pool release];
     return 0;

which is in my opinion the best of both worlds.  But my patch (assuming 
it works) really fixes the threading model.  Without it, moving menus to 
the iothread makes it even more complicated.

>> It also gives us the opposite problem that we're now calling a lot
>> of Cocoa APIs from something other than the main Cocoa thread.
> Basically NSView is the only thing prohibited from calling from
> another thread so it shouldn't be a problem.

I'd rather have a single thread that does all things related to Cocoa. 
If my patch doesn't work, I would just call qmp_query_block(NULL) from 
cocoa_display_init() and save the result in a global variable.

Paolo


  reply	other threads:[~2022-03-07 17:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 15:10 [RFC uncompiled PATCH] cocoa: run qemu_init in the main thread Paolo Bonzini
2022-03-07 15:34 ` Akihiko Odaki
2022-03-07 16:14   ` Peter Maydell
2022-03-07 16:27     ` Akihiko Odaki
2022-03-07 16:35       ` Peter Maydell
2022-03-07 16:41         ` Akihiko Odaki
2022-03-07 17:21           ` Paolo Bonzini [this message]
2022-03-07 19:25             ` Akihiko Odaki
2022-03-07 16:39   ` Paolo Bonzini
2022-03-07 17:03     ` Akihiko Odaki
2022-03-07 17:06 ` Paolo Bonzini
2022-03-16 16:02 ` Philippe Mathieu-Daudé

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=89a0316d-7e9a-46d9-31cc-c3507483fffb@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=akihiko.odaki@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 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.