fix
杨锴
2025-06-16 3fa53409f5132333ce6d83fff796e108ddd62090
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * This file is part of the SDWebImage package.
 * (c) Olivier Poitrey <rs@dailymotion.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
 
#import "SDImageCachesManagerOperation.h"
#import "SDInternalMacros.h"
 
@implementation SDImageCachesManagerOperation {
    SD_LOCK_DECLARE(_pendingCountLock);
}
 
@synthesize executing = _executing;
@synthesize finished = _finished;
@synthesize cancelled = _cancelled;
@synthesize pendingCount = _pendingCount;
 
- (instancetype)init {
    if (self = [super init]) {
        SD_LOCK_INIT(_pendingCountLock);
        _pendingCount = 0;
    }
    return self;
}
 
- (void)beginWithTotalCount:(NSUInteger)totalCount {
    self.executing = YES;
    self.finished = NO;
    _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 {
    self.cancelled = YES;
    [self reset];
}
 
- (void)done {
    self.finished = YES;
    self.executing = NO;
    [self reset];
}
 
- (void)reset {
    SD_LOCK(_pendingCountLock);
    _pendingCount = 0;
    SD_UNLOCK(_pendingCountLock);
}
 
- (void)setFinished:(BOOL)finished {
    [self willChangeValueForKey:@"isFinished"];
    _finished = finished;
    [self didChangeValueForKey:@"isFinished"];
}
 
- (void)setExecuting:(BOOL)executing {
    [self willChangeValueForKey:@"isExecuting"];
    _executing = executing;
    [self didChangeValueForKey:@"isExecuting"];
}
 
- (void)setCancelled:(BOOL)cancelled {
    [self willChangeValueForKey:@"isCancelled"];
    _cancelled = cancelled;
    [self didChangeValueForKey:@"isCancelled"];
}
 
@end