I wrote a bunch of code with the Mutex::Unlocker and didn't understand it. (#2150)

This commit is contained in:
Garrett Moon
2016-08-26 14:07:18 -07:00
committed by Adlai Holler
parent 905508e9be
commit e6e5c346de
3 changed files with 14 additions and 8 deletions

View File

@@ -346,15 +346,16 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
- (void)setShouldRenderProgressImages:(BOOL)shouldRenderProgressImages
{
ASDN::MutexLocker l(__instanceLock__);
__instanceLock__.lock();
if (shouldRenderProgressImages == _shouldRenderProgressImages) {
__instanceLock__.unlock();
return;
}
_shouldRenderProgressImages = shouldRenderProgressImages;
ASDN::MutexUnlocker u(__instanceLock__);
__instanceLock__.unlock();
[self _updateProgressImageBlockOnDownloaderIfNeeded];
}

View File

@@ -224,15 +224,16 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
- (void)setShouldRenderProgressImages:(BOOL)shouldRenderProgressImages
{
ASDN::MutexLocker l(__instanceLock__);
__instanceLock__.lock();
if (shouldRenderProgressImages == _shouldRenderProgressImages) {
__instanceLock__.unlock();
return;
}
_shouldRenderProgressImages = shouldRenderProgressImages;
ASDN::MutexUnlocker u(__instanceLock__);
__instanceLock__.unlock();
[self _updateProgressImageBlockOnDownloaderIfNeeded];
}

View File

@@ -39,8 +39,10 @@
{
ASDN::MutexLocker l(_serialQueueLock);
[_blocks addObject:block];
ASDN::MutexUnlocker u(_serialQueueLock);
[self runBlocks];
{
ASDN::MutexUnlocker u(_serialQueueLock);
[self runBlocks];
}
}
- (void)runBlocks
@@ -55,8 +57,10 @@
} else {
break;
}
ASDN::MutexUnlocker u(_serialQueueLock);
block();
{
ASDN::MutexUnlocker u(_serialQueueLock);
block();
}
} while (true);
};