Skip to content

Commit

Permalink
ui: Fix hanging up Cocoa display on macOS 10.15 (Catalina)
Browse files Browse the repository at this point in the history
macOS API documentation says that before applicationDidFinishLaunching
is called, any events will not be processed. However, some events are
fired before it is called in macOS Catalina. This causes deadlock of
iothread_lock in handleEvent while it will be released after the
app_started_sem is posted.
This patch avoids processing events before the app_started_sem is
posted to prevent this deadlock.

Buglink: https://bugs.launchpad.net/qemu/+bug/1847906
Signed-off-by: Hikaru Nishida <[email protected]>
Message-id: [email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
hikalium authored and kraxel committed Oct 18, 2019
1 parent f22f553 commit dff742a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ui/cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@

static QemuSemaphore display_init_sem;
static QemuSemaphore app_started_sem;
static bool allow_events;

// Utility functions to run specified code block with iothread lock held
typedef void (^CodeBlock)(void);
Expand Down Expand Up @@ -729,6 +730,16 @@ - (void) handleMonitorInput:(NSEvent *)event

- (bool) handleEvent:(NSEvent *)event
{
if(!allow_events) {
/*
* Just let OSX have all events that arrive before
* applicationDidFinishLaunching.
* This avoids a deadlock on the iothread lock, which cocoa_display_init()
* will not drop until after the app_started_sem is posted. (In theory
* there should not be any such events, but OSX Catalina now emits some.)
*/
return false;
}
return bool_with_iothread_lock(^{
return [self handleEventLocked:event];
});
Expand Down Expand Up @@ -1156,6 +1167,7 @@ - (void) dealloc
- (void)applicationDidFinishLaunching: (NSNotification *) note
{
COCOA_DEBUG("QemuCocoaAppController: applicationDidFinishLaunching\n");
allow_events = true;
/* Tell cocoa_display_init to proceed */
qemu_sem_post(&app_started_sem);
}
Expand Down

0 comments on commit dff742a

Please sign in to comment.