From 61401b3e7b21154422756cf2a8e98e82afc2c22e Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 9 Jan 2015 16:58:18 -0500 Subject: [PATCH] Only dispatch_async on limelight-common's threads --- Limelight/Stream/Connection.h | 1 + Limelight/Stream/Connection.m | 9 ++++++++- Limelight/Stream/StreamManager.h | 1 + Limelight/Stream/StreamManager.m | 9 +++++++++ Limelight/ViewControllers/StreamFrameViewController.m | 2 +- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Limelight/Stream/Connection.h b/Limelight/Stream/Connection.h index ae11364..4a1a734 100644 --- a/Limelight/Stream/Connection.h +++ b/Limelight/Stream/Connection.h @@ -27,6 +27,7 @@ -(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionCallbacks:(id)callbacks; -(void) terminate; +-(void) terminateInternal; -(void) main; @end diff --git a/Limelight/Stream/Connection.m b/Limelight/Stream/Connection.m index c0152d9..459d312 100644 --- a/Limelight/Stream/Connection.m +++ b/Limelight/Stream/Connection.m @@ -275,7 +275,7 @@ void ClDisplayTransientMessage(char* message) [_callbacks displayTransientMessage: message]; } --(void) terminate +-(void) terminateInternal { // We dispatch this async to get out because this can be invoked // on a thread inside common and we don't want to deadlock @@ -285,6 +285,13 @@ void ClDisplayTransientMessage(char* message) }); } +-(void) terminate +{ + // We're guaranteed to not be on a limelight-common thread + // here so it's safe to call stop directly + LiStopConnection(); +} + -(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionCallbacks:(id)callbacks { self = [super init]; diff --git a/Limelight/Stream/StreamManager.h b/Limelight/Stream/StreamManager.h index d0dd6d3..af93e54 100644 --- a/Limelight/Stream/StreamManager.h +++ b/Limelight/Stream/StreamManager.h @@ -14,5 +14,6 @@ - (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionCallbacks:(id)callback; - (void) stopStream; +- (void) stopStreamInternal; @end diff --git a/Limelight/Stream/StreamManager.m b/Limelight/Stream/StreamManager.m index 8ccc07c..577df4a 100644 --- a/Limelight/Stream/StreamManager.m +++ b/Limelight/Stream/StreamManager.m @@ -79,11 +79,20 @@ [opQueue addOperation:_connection]; } +// This should NEVER be called from within a thread +// owned by limelight-common - (void) stopStream { [_connection terminate]; } +// This should only be called from within a thread +// owned by limelight-common +- (void) stopStreamInternal +{ + [_connection terminateInternal]; +} + - (BOOL) launchApp:(HttpManager*)hMan { NSData* launchResp = [hMan executeRequestSynchronously: [hMan newLaunchRequest:_config.appID diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index b44f4c8..40d3910 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -88,7 +88,7 @@ }]]; [self presentViewController:conTermAlert animated:YES completion:nil]; - [_streamMan stopStream]; + [_streamMan stopStreamInternal]; } - (void) stageStarting:(char*)stageName {