From c54a1f3e412e107f3eb675e5276839cf0038c4fa Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 24 Oct 2013 00:04:43 +0200 Subject: cocoa: fix race condition with input context creation This seems to be a problem only in OS X 10.9. I guess they improved the general speed of the Cocoa startup and suddenly mpv core takes more time than the Cocoa thread to initialize. Fixes #285 (hopefully!) --- osdep/macosx_application.m | 13 +++++++++++++ osdep/macosx_application_objc.h | 1 + 2 files changed, 14 insertions(+) (limited to 'osdep') diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 7ee15267d0..50d5a5bb4f 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -77,6 +77,7 @@ static NSString *escape_loadfile_name(NSString *input) @synthesize inputContext = _input_context; @synthesize eventsResponder = _events_responder; @synthesize menuItems = _menu_items; +@synthesize input_ready = _input_ready; - (void)sendEvent:(NSEvent *)event { @@ -94,6 +95,7 @@ static NSString *escape_loadfile_name(NSString *input) self.argumentsList = [[[NSMutableArray alloc] init] autorelease]; self.eventsResponder = [[[EventsResponder alloc] init] autorelease]; self.willStopOnOpenEvent = NO; + self.input_ready = [[[NSCondition alloc] init] autorelease]; [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSKeyUpMask handler:^(NSEvent *event) { @@ -325,6 +327,11 @@ int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]) init_cocoa_application(); macosx_finder_args_preinit(&argc, &argv); pthread_create(&playback_thread_id, NULL, playback_thread, &ctx); + + [mpv_shared_app().input_ready lock]; + [mpv_shared_app().input_ready wait]; + [mpv_shared_app().input_ready unlock]; + cocoa_run_runloop(); // This should never be reached: cocoa_run_runloop blocks until the @@ -380,6 +387,12 @@ void cocoa_stop_runloop(void) void cocoa_set_input_context(struct input_ctx *input_context) { + if (input_context) { + [mpv_shared_app().input_ready lock]; + [mpv_shared_app().input_ready signal]; + [mpv_shared_app().input_ready unlock]; + } + mpv_shared_app().inputContext = input_context; } diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index 53d00b2ab4..c130e51eba 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -43,6 +43,7 @@ @property(nonatomic, retain) NSArray *files; @property(nonatomic, retain) NSMutableArray *argumentsList; @property(nonatomic, assign) BOOL willStopOnOpenEvent; +@property(nonatomic, retain) NSCondition *input_ready; @end Application *mpv_shared_app(void); -- cgit v1.2.3