[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC next] ui: Split main() in two to not have Cocoa hi
From: |
Andreas Färber |
Subject: |
Re: [Qemu-devel] [RFC next] ui: Split main() in two to not have Cocoa hijack it |
Date: |
Wed, 30 May 2012 18:22:05 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 |
Am 30.05.2012 11:00, schrieb Paolo Bonzini:
> Il 28/05/2012 20:18, Andreas Färber ha scritto:
>> Only call into cocoa.m when determined necessary by QEMU's option
>> handling. Avoids redoing all option parsing in ui/cocoa.m:main()
>> and constantly missing new options like -machine accel=qtest.
>>
>> Move function declarations to a new ui.h header to avoid recompiling
>> everything when the new UI-internal function interface changes.
>>
>> Handle the -psn option properly in vl.c.
>>
>> Replace the faking of command line options for user-selected disk
>> image with proper API usage.
>
> This is nice. :)
>
> But the split between main/main2 is ugly.
>
> Is it possible to run the main loop (basically everything starting at
> the creation of the NSAutoreleasePool on) in a separate thread?
No.
> cocoa_main starts the thread and sits on a condition variable waiting
> for applicationDidFinishLaunching: to be called.
>
> applicationDidFinishLaunching: signals that condition variable, then
> goes on a loop like
>
> qemu_mutex_lock(&qemu_cocoa_mutex);
> globalCons = 0;
> localCons = globalCons;
>
> for (;;) {
> while (!exiting && localCons == globalCons) {
> qemu_cond_wait(&qemu_cocoa_cond, &qemu_cocoa_mutex);
> }
> if (exiting) {
> break;
> }
>
> /* we can behave as if we held the global mutex, we
> know the iothread is waiting for us */
> ... content of cocoa_refresh ...
>
> globalProd++;
> qemu_cond_broadcast(&qemu_cocoa_mutex);
> }
> qemu_mutex_unlock(&qemu_cocoa_mutex);
> [NSApp stop];
>
> and cocoa_refresh only handles the rendez-vous:
>
> qemu_mutex_lock(&qemu_cocoa_mutex);
> localProd = globalProd;
> globalCons++;
> qemu_cond_broadcast(&qemu_cocoa_mutex);
> while (localProd == globalProd) {
> qemu_cond_wait(&qemu_cocoa_cond, &qemu_cocoa_mutex);
> }
> qemu_mutex_unlock(&qemu_cocoa_mutex);
> vga_hw_update();
I'd have to investigate this, but the main issue seemed to be that we
cannot *inline* the startup code into QEMU's main() as it is. If we
manage to split it at some sensible point, we can switch to a
multithreaded model. However from what I remember, going as low-level as
creating our own main loop would require re(verse)-engineering Cocoa
code iirc.
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg