Merge pull request #165 from pinterest/addBetterLocking

Add slightly more performant locking.
This commit is contained in:
Garrett Moon
2016-03-17 10:38:06 -07:00
11 changed files with 444 additions and 293 deletions

View File

@@ -24,11 +24,11 @@ PODS:
- libwebp/core
- libwebp/webp (0.5.0)
- PINCache (2.2.2)
- PINRemoteImage/Core (2.0.1):
- PINRemoteImage/Core (2.1):
- PINCache (>= 2.1)
- PINRemoteImage/iOS (2.0.1):
- PINRemoteImage/iOS (2.1):
- PINRemoteImage/Core
- PINRemoteImage/WebP (2.0.1):
- PINRemoteImage/WebP (2.1):
- libwebp
- PINRemoteImage/Core
@@ -44,6 +44,6 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
libwebp: 68ba2001ba6806ee52837ebd77a551a0b6567e4e
PINCache: 078426d356ab95ef875e9e62e5c35a2ea3333c28
PINRemoteImage: b700a7bc774a19758092b5c06b3e076fe2cf3dce
PINRemoteImage: 49cfb689cf7af1227ee563e921a1f7e4ce215a8d
COCOAPODS: 0.39.0

View File

@@ -0,0 +1 @@
../../../../../Pod/Classes/PINRemoteLock.h

View File

@@ -0,0 +1 @@
../../../../../Pod/Classes/PINRemoteLock.h

View File

@@ -1,6 +1,6 @@
{
"name": "PINRemoteImage",
"version": "2.0.1",
"version": "2.1",
"summary": "A thread safe, performant, feature rich image fetcher",
"homepage": "https://github.com/pinterest/PINRemoteImage",
"license": "Apache 2.0",
@@ -9,12 +9,13 @@
},
"source": {
"git": "https://github.com/pinterest/PINRemoteImage.git",
"tag": "2.0.1"
"tag": "2.1"
},
"social_media_url": "https://twitter.com/garrettmoon",
"platforms": {
"ios": "6.0",
"osx": "10.8"
"osx": "10.8",
"tvos": "9.0"
},
"requires_arc": true,
"default_subspecs": "FLAnimatedImage",
@@ -57,6 +58,16 @@
},
"frameworks": "Cocoa"
},
{
"name": "tvOS",
"platforms": "tvos",
"dependencies": {
"PINRemoteImage/Core": [
]
},
"frameworks": "UIKit"
},
{
"name": "FLAnimatedImage",
"platforms": "ios",

8
Example/Pods/Manifest.lock generated vendored
View File

@@ -24,11 +24,11 @@ PODS:
- libwebp/core
- libwebp/webp (0.5.0)
- PINCache (2.2.2)
- PINRemoteImage/Core (2.0.1):
- PINRemoteImage/Core (2.1):
- PINCache (>= 2.1)
- PINRemoteImage/iOS (2.0.1):
- PINRemoteImage/iOS (2.1):
- PINRemoteImage/Core
- PINRemoteImage/WebP (2.0.1):
- PINRemoteImage/WebP (2.1):
- libwebp
- PINRemoteImage/Core
@@ -44,6 +44,6 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
libwebp: 68ba2001ba6806ee52837ebd77a551a0b6567e4e
PINCache: 078426d356ab95ef875e9e62e5c35a2ea3333c28
PINRemoteImage: b700a7bc774a19758092b5c06b3e076fe2cf3dce
PINRemoteImage: 49cfb689cf7af1227ee563e921a1f7e4ce215a8d
COCOAPODS: 0.39.0

File diff suppressed because it is too large Load Diff

View File

@@ -7,33 +7,30 @@
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForAnalyzing = "YES"
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
buildForArchiving = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4659B8FEB8162320413F74963CC40CBE"
BuildableName = "libPods-PINRemoteImage Tests-PINRemoteImage.a"
BlueprintName = "Pods-PINRemoteImage Tests-PINRemoteImage"
ReferencedContainer = "container:Pods.xcodeproj">
BuildableIdentifier = 'primary'
BlueprintIdentifier = '5A55E49DFDC10F3AC36B8D32'
BlueprintName = 'Pods-PINRemoteImage Tests-PINRemoteImage'
ReferencedContainer = 'container:Pods.xcodeproj'
BuildableName = 'libPods-PINRemoteImage Tests-PINRemoteImage.a'>
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
@@ -41,25 +38,17 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
buildConfiguration = "Debug"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4659B8FEB8162320413F74963CC40CBE"
BuildableName = "libPods-PINRemoteImage Tests-PINRemoteImage.a"
BlueprintName = "Pods-PINRemoteImage Tests-PINRemoteImage"
ReferencedContainer = "container:Pods.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
debugDocumentVersioning = "YES"
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">

View File

@@ -14,7 +14,7 @@
buildForArchiving = "YES">
<BuildableReference
BuildableIdentifier = 'primary'
BlueprintIdentifier = '385E12D68B3AF6655007C776'
BlueprintIdentifier = 'CC50F664916C302A35C5EA9C'
BlueprintName = 'Pods-PINRemoteImage-PINRemoteImage'
ReferencedContainer = 'container:Pods.xcodeproj'
BuildableName = 'libPods-PINRemoteImage-PINRemoteImage.a'>

View File

@@ -14,6 +14,7 @@
#import <PINCache/PINCache.h>
#import "PINRemoteImage.h"
#import "PINRemoteLock.h"
#import "PINProgressiveImage.h"
#import "PINRemoteImageCallbacks.h"
#import "PINRemoteImageTask.h"
@@ -96,7 +97,7 @@ typedef void (^PINRemoteImageManagerDataCompletion)(NSData *data, NSError *error
@interface PINRemoteImageManager () <PINURLSessionManagerDelegate>
{
dispatch_queue_t _callbackQueue;
NSLock *_lock;
PINRemoteLock *_lock;
NSOperationQueue *_concurrentOperationQueue;
NSOperationQueue *_urlSessionTaskQueue;
}
@@ -173,8 +174,7 @@ static dispatch_once_t sharedDispatchToken;
configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
}
_callbackQueue = dispatch_queue_create("PINRemoteImageManagerCallbackQueue", DISPATCH_QUEUE_CONCURRENT);
_lock = [[NSLock alloc] init];
_lock.name = @"PINRemoteImageManager";
_lock = [[PINRemoteLock alloc] initWithName:@"PINRemoteImageManager"];
_concurrentOperationQueue = [[NSOperationQueue alloc] init];
_concurrentOperationQueue.name = @"PINRemoteImageManager Concurrent Operation Queue";
_concurrentOperationQueue.maxConcurrentOperationCount = NSOperationQueueDefaultMaxConcurrentOperationCount;

View File

@@ -0,0 +1,25 @@
//
// PINRemoteLock.h
// Pods
//
// Created by Garrett Moon on 3/17/16.
//
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, PINRemoteLockType) {
PINRemoteLockTypeNonRecursive = 0,
PINRemoteLockTypeRecursive,
};
@interface PINRemoteLock : NSObject
- (instancetype)initWithName:(NSString *)lockName lockType:(PINRemoteLockType)lockType NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithName:(NSString *)lockName;
- (void)lockWithBlock:(dispatch_block_t)block;
- (void)lock;
- (void)unlock;
@end

112
Pod/Classes/PINRemoteLock.m Normal file
View File

@@ -0,0 +1,112 @@
//
// PINRemoteLock.m
// Pods
//
// Created by Garrett Moon on 3/17/16.
//
//
#import "PINRemoteLock.h"
#import <pthread.h>
#if !defined(PINREMOTELOCK_DEBUG) && defined(DEBUG)
#define PINREMOTELOCK_DEBUG DEBUG
#endif
@interface PINRemoteLock ()
{
#if PINREMOTELOCK_DEBUG
NSLock *_lock;
NSRecursiveLock *_recursiveLock;
#else
pthread_mutex_t _lock;
#endif
}
@end
@implementation PINRemoteLock
- (instancetype)init
{
return [self initWithName:nil];
}
- (instancetype)initWithName:(NSString *)lockName lockType:(PINRemoteLockType)lockType
{
if (self = [super init]) {
#if PINREMOTELOCK_DEBUG
if (lockType == PINRemoteLockTypeNonRecursive) {
_lock = [[NSLock alloc] init];
} else {
_recursiveLock = [[NSRecursiveLock alloc] init];
}
if (lockName) {
[_lock setName:lockName];
[_recursiveLock setName:lockName];
}
#else
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
if (lockType == PINRemoteLockTypeRecursive) {
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
}
pthread_mutex_init(&_lock, &attr);
#endif
}
return self;
}
- (instancetype)initWithName:(NSString *)lockName
{
return [self initWithName:lockName lockType:PINRemoteLockTypeNonRecursive];
}
#if ! PINREMOTELOCK_DEBUG
- (void)dealloc
{
pthread_mutex_destroy(&_lock);
}
#endif
- (void)lockWithBlock:(dispatch_block_t)block
{
#if PINREMOTELOCK_DEBUG
[_lock lock];
[_recursiveLock lock];
#else
pthread_mutex_lock(&_lock);
#endif
block();
#if PINREMOTELOCK_DEBUG
[_lock unlock];
[_recursiveLock unlock];
#else
pthread_mutex_unlock(&_lock);
#endif
}
- (void)lock
{
#if PINREMOTELOCK_DEBUG
[_lock lock];
[_recursiveLock lock];
#else
pthread_mutex_lock(&_lock);
#endif
}
- (void)unlock
{
#if PINREMOTELOCK_DEBUG
[_lock unlock];
[_recursiveLock unlock];
#else
pthread_mutex_unlock(&_lock);
#endif
}
@end