Fix caches manager operation thread safe issue
This commit is contained in:
parent
b0f1006e3f
commit
100869dd70
|
@ -9,10 +9,22 @@
|
||||||
#import "SDImageCachesManagerOperation.h"
|
#import "SDImageCachesManagerOperation.h"
|
||||||
|
|
||||||
@implementation SDImageCachesManagerOperation
|
@implementation SDImageCachesManagerOperation
|
||||||
|
{
|
||||||
|
dispatch_semaphore_t _pendingCountLock;
|
||||||
|
}
|
||||||
|
|
||||||
@synthesize executing = _executing;
|
@synthesize executing = _executing;
|
||||||
@synthesize finished = _finished;
|
@synthesize finished = _finished;
|
||||||
@synthesize cancelled = _cancelled;
|
@synthesize cancelled = _cancelled;
|
||||||
|
@synthesize pendingCount = _pendingCount;
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
if (self = [super init]) {
|
||||||
|
_pendingCountLock = dispatch_semaphore_create(1);
|
||||||
|
_pendingCount = 0;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)beginWithTotalCount:(NSUInteger)totalCount {
|
- (void)beginWithTotalCount:(NSUInteger)totalCount {
|
||||||
self.executing = YES;
|
self.executing = YES;
|
||||||
|
@ -20,8 +32,17 @@
|
||||||
_pendingCount = totalCount;
|
_pendingCount = totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)pendingCount {
|
||||||
|
SD_LOCK(_pendingCountLock);
|
||||||
|
NSUInteger pendingCount = _pendingCount;
|
||||||
|
SD_UNLOCK(_pendingCountLock);
|
||||||
|
return pendingCount;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)completeOne {
|
- (void)completeOne {
|
||||||
|
SD_LOCK(_pendingCountLock);
|
||||||
_pendingCount = _pendingCount > 0 ? _pendingCount - 1 : 0;
|
_pendingCount = _pendingCount > 0 ? _pendingCount - 1 : 0;
|
||||||
|
SD_UNLOCK(_pendingCountLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancel {
|
- (void)cancel {
|
||||||
|
@ -36,7 +57,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reset {
|
- (void)reset {
|
||||||
|
SD_LOCK(_pendingCountLock);
|
||||||
_pendingCount = 0;
|
_pendingCount = 0;
|
||||||
|
SD_UNLOCK(_pendingCountLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFinished:(BOOL)finished {
|
- (void)setFinished:(BOOL)finished {
|
||||||
|
|
Loading…
Reference in New Issue