mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 03:09:56 +00:00
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:
parent
f94229796c
commit
066596314e
@ -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(), ^{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user