Skip to content

Commit 29cb403

Browse files
author
YangSen-qn
committed
optimize some code
1 parent eceda5f commit 29cb403

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

QiniuSDK/Storage/QNUpProgress.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
@interface QNUpProgress()
1313

14-
@property( atomic, assign)long long maxProgressUploadBytes;
15-
@property( atomic, assign)long long previousUploadBytes;
14+
@property(nonatomic, assign)long long maxProgressUploadBytes;
15+
@property(nonatomic, assign)long long previousUploadBytes;
1616
@property(nonatomic, copy)QNUpProgressHandler progress;
1717
@property(nonatomic, copy)QNUpByteProgressHandler byteProgress;
1818

@@ -34,22 +34,26 @@ - (void)progress:(NSString *)key uploadBytes:(long long)uploadBytes totalBytes:(
3434
}
3535

3636
if (totalBytes > 0) {
37-
if (self.maxProgressUploadBytes < 0) {
38-
self.maxProgressUploadBytes = totalBytes * 0.95;
37+
@synchronized (self) {
38+
if (self.maxProgressUploadBytes < 0) {
39+
self.maxProgressUploadBytes = totalBytes * 0.95;
40+
}
3941
}
4042

4143
if (uploadBytes > self.maxProgressUploadBytes) {
4244
return;
4345
}
4446
}
4547

46-
if (uploadBytes > self.previousUploadBytes) {
47-
self.previousUploadBytes = uploadBytes;
48-
} else {
49-
return;
48+
@synchronized (self) {
49+
if (uploadBytes > self.previousUploadBytes) {
50+
self.previousUploadBytes = uploadBytes;
51+
} else {
52+
return;
53+
}
5054
}
5155

52-
[self notify:key uploadBytes:self.previousUploadBytes totalBytes:totalBytes];
56+
[self notify:key uploadBytes:uploadBytes totalBytes:totalBytes];
5357
}
5458

5559
- (void)notifyDone:(NSString *)key totalBytes:(long long)totalBytes {

0 commit comments

Comments
 (0)