Fix deadlock when an editing transaction needs to perform its work on the main thread, and then elsewhere, on the main thread, we block waiting for all editing transactions to finish

This commit is contained in:
Garrett Moon 2015-12-11 10:03:43 -08:00
parent f94229796c
commit 066596314e

View File

@ -1001,24 +1001,28 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
{
ASDN::MutexLocker l(_serialQueueLock);
[_blocks addObject:block];
ASDN::MutexUnlocker u(_serialQueueLock);
[self runBlocks];
}
- (void)runBlocks
{
dispatch_block_t mainThread = ^{
ASDN::MutexLocker l(_serialQueueLock);
for (NSUInteger i = 0; i < _blocks.count; i++) {
dispatch_block_t block = [_blocks objectAtIndex:i];
do {
ASDN::MutexLocker l(_serialQueueLock);
dispatch_block_t block;
if (_blocks.count > 0) {
block = [_blocks objectAtIndex:0];
[_blocks removeObjectAtIndex:0];
} else {
break;
}
ASDN::MutexUnlocker u(_serialQueueLock);
block();
}
[_blocks removeAllObjects];
} while (true);
};
if ([NSThread isMainThread]) {
ASDN::MutexUnlocker u(_serialQueueLock);
mainThread();
} else {
dispatch_async(dispatch_get_main_queue(), ^{