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