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!)
This commit is contained in:
Stefano Pigozzi authored and wm4 committed 2013-11-02 19:01:39 +01:00
1 parent b3233fa3ff
commit 31cdb96474
2 files changed
+14

No files matched your search

+13
View File
@@ -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;
}
+1
View File
@@ -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);