From dec9e4e836330a63fa0be2f3bb4045a7a07ad565 Mon Sep 17 00:00:00 2001 From: appleguy Date: Tue, 18 Oct 2016 09:07:29 -0700 Subject: [PATCH] [ASDeallocQueue] Fix teardown of thread (doesn't currently happen due to singleton). (#2410) Although this didn't occur _currently_, the code was incorrect and needs to be fixed. --- AsyncDisplayKit/ASRunLoopQueue.mm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASRunLoopQueue.mm b/AsyncDisplayKit/ASRunLoopQueue.mm index 6d2bd9d2f6..42e5ea96e7 100644 --- a/AsyncDisplayKit/ASRunLoopQueue.mm +++ b/AsyncDisplayKit/ASRunLoopQueue.mm @@ -79,7 +79,7 @@ static void runLoopSourceCallback(void *info) { [_condition lock]; [_condition signal]; - // At this moment, the thread is guaranteed to be finished starting. + // At this moment, -init is signalled that the thread is guaranteed to be finished starting. [_condition unlock]; // Keep processing events until the runloop is stopped. @@ -87,6 +87,12 @@ static void runLoopSourceCallback(void *info) { CFRunLoopTimerInvalidate(timer); CFRunLoopRemoveTimer(runloop, timer, kCFRunLoopCommonModes); + CFRelease(timer); + + [_condition lock]; + [_condition signal]; + // At this moment, -stop is signalled that the thread is guaranteed to be finished exiting. + [_condition unlock]; } } @@ -116,6 +122,7 @@ static void runLoopSourceCallback(void *info) { [_condition lock]; [self performSelector:@selector(_stop) onThread:_thread withObject:nil waitUntilDone:NO]; [_condition wait]; + // At this moment, the thread is guaranteed to be finished running. [_condition unlock]; _thread = nil; }