summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-10-24 00:04:43 +0200
committerwm4 <wm4@nowhere>2013-11-02 19:01:39 +0100
commit31cdb9647461b7c5f1d73ae0befa94710688523c (patch)
tree65d8811f44fdb11e297a21e3ae5a6ddc2c24151f
parentb3233fa3ff01d381f7fd5099df538299745ea342 (diff)
downloadmpv-31cdb9647461b7c5f1d73ae0befa94710688523c.tar.bz2
mpv-31cdb9647461b7c5f1d73ae0befa94710688523c.tar.xz
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!)
-rw-r--r--osdep/macosx_application.m13
-rw-r--r--osdep/macosx_application_objc.h1
2 files changed, 14 insertions, 0 deletions
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);