Merge pull request #2669 from zhongwuzw/fix_cachesoperation_thread_safe
Fix caches manager operation thread safe issue
This commit is contained in:
commit
5e427f6984
|
@ -9,10 +9,22 @@
|
|||
#import "SDImageCachesManagerOperation.h"
|
||||
|
||||
@implementation SDImageCachesManagerOperation
|
||||
{
|
||||
dispatch_semaphore_t _pendingCountLock;
|
||||
}
|
||||
|
||||
@synthesize executing = _executing;
|
||||
@synthesize finished = _finished;
|
||||
@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 {
|
||||
self.executing = YES;
|
||||
|
@ -20,8 +32,17 @@
|
|||
_pendingCount = totalCount;
|
||||
}
|
||||
|
||||
- (NSUInteger)pendingCount {
|
||||
SD_LOCK(_pendingCountLock);
|
||||
NSUInteger pendingCount = _pendingCount;
|
||||
SD_UNLOCK(_pendingCountLock);
|
||||
return pendingCount;
|
||||
}
|
||||
|
||||
- (void)completeOne {
|
||||
SD_LOCK(_pendingCountLock);
|
||||
_pendingCount = _pendingCount > 0 ? _pendingCount - 1 : 0;
|
||||
SD_UNLOCK(_pendingCountLock);
|
||||
}
|
||||
|
||||
- (void)cancel {
|
||||
|
@ -36,7 +57,9 @@
|
|||
}
|
||||
|
||||
- (void)reset {
|
||||
SD_LOCK(_pendingCountLock);
|
||||
_pendingCount = 0;
|
||||
SD_UNLOCK(_pendingCountLock);
|
||||
}
|
||||
|
||||
- (void)setFinished:(BOOL)finished {
|
||||
|
|
Loading…
Reference in New Issue