0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

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 2013-10-24 00:04:43 +02:00 committed by wm4
parent b3233fa3ff
commit 31cdb96474
2 changed files with 14 additions and 0 deletions

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;
}

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);