Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#trivial] I don't think we need this extra locked method. #824

Merged
merged 2 commits into from
Mar 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ - (void)setURL:(NSURL *)URL resetToDefault:(BOOL)reset
// If URL is nil and URL was not equal to _URL (checked at the top), then we previously had a URL but it's been nil'd out.
BOOL hadURL = (URL == nil);
if (reset || hadURL) {
[self _locked_setCurrentImageQuality:(hadURL ? 0.0 : 1.0)];
[self _setCurrentImageQuality:(hadURL ? 0.0 : 1.0)];
[self _locked__setImage:_defaultImage];
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ - (void)_locked_setDefaultImage:(UIImage *)defaultImage
_defaultImage = defaultImage;

if (!_imageLoaded) {
[self _locked_setCurrentImageQuality:((_URL == nil) ? 0.0 : 1.0)];
[self _setCurrentImageQuality:((_URL == nil) ? 0.0 : 1.0)];
[self _locked__setImage:defaultImage];

}
Expand All @@ -250,24 +250,18 @@ - (CGFloat)currentImageQuality
}

/**
* Always use this methods internally to update the current image quality
* Always use these methods internally to update the current image quality
* We want to maintain the order that currentImageQuality is set regardless of the calling thread,
* so we always have to dispatch to the main threadto ensure that we queue the operations in the correct order.
* so we always have to dispatch to the main thread to ensure that we queue the operations in the correct order.
* (see comment in displayDidFinish)
*/
- (void)_setCurrentImageQuality:(CGFloat)imageQuality
{
ASDN::MutexLocker l(__instanceLock__);
[self _locked_setCurrentImageQuality:imageQuality];
}

- (void)_locked_setCurrentImageQuality:(CGFloat)imageQuality
{
dispatch_async(dispatch_get_main_queue(), ^{
// As the setting of the image quality is dispatched the lock is gone by the time the block is executing.
// Therefore we have to grab the lock again
__instanceLock__.lock();
_currentImageQuality = imageQuality;
_currentImageQuality = imageQuality;
__instanceLock__.unlock();
});
}
Expand Down Expand Up @@ -340,7 +334,7 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
if (_imageLoaded == NO && url && _downloadIdentifier == nil) {
UIImage *result = [[_cache synchronouslyFetchedCachedImageWithURL:url] asdk_image];
if (result) {
[self _locked_setCurrentImageQuality:1.0];
[self _setCurrentImageQuality:1.0];
[self _locked__setImage:result];
_imageLoaded = YES;

Expand Down Expand Up @@ -443,7 +437,7 @@ - (void)handleProgressImage:(UIImage *)progressImage progress:(CGFloat)progress
}

as_log_verbose(ASImageLoadingLog(), "Received progress image for %@ q: %.2g id: %@", self, progress, progressImage);
[self _locked_setCurrentImageQuality:progress];
[self _setCurrentImageQuality:progress];
[self _locked__setImage:progressImage];
}

Expand Down Expand Up @@ -516,7 +510,7 @@ - (void)_locked_cancelDownloadAndClearImageWithResumePossibility:(BOOL)storeResu
[self _locked_cancelImageDownloadWithResumePossibility:storeResume];

[self _locked_setAnimatedImage:nil];
[self _locked_setCurrentImageQuality:0.0];
[self _setCurrentImageQuality:0.0];
[self _locked__setImage:_defaultImage];

_imageLoaded = NO;
Expand Down Expand Up @@ -667,7 +661,7 @@ - (void)_lazilyLoadImageIfNecessary

_imageLoaded = YES;

[self _locked_setCurrentImageQuality:1.0];
[self _setCurrentImageQuality:1.0];

if (_delegateFlags.delegateDidLoadImageWithInfo) {
ASDN::MutexUnlocker u(__instanceLock__);
Expand Down Expand Up @@ -706,7 +700,7 @@ - (void)_lazilyLoadImageIfNecessary

UIImage *newImage;
if (imageContainer != nil) {
[strongSelf _locked_setCurrentImageQuality:1.0];
[strongSelf _setCurrentImageQuality:1.0];
NSData *animatedImageData = [imageContainer asdk_animatedImageData];
if (animatedImageData && strongSelf->_downloaderFlags.downloaderImplementsAnimatedImage) {
id animatedImage = [strongSelf->_downloader animatedImageWithData:animatedImageData];
Expand Down