Ok, making the entire reading and increment atomic.

This commit is contained in:
Evan Long 2011-08-30 22:36:24 -07:00
parent 9a0ed2497c
commit ef0cb81909

View file

@ -23,7 +23,7 @@
#import "AFNetworkActivityIndicatorManager.h" #import "AFNetworkActivityIndicatorManager.h"
@interface AFNetworkActivityIndicatorManager () @interface AFNetworkActivityIndicatorManager ()
@property (readwrite, assign) NSInteger activityCount; @property (readwrite, nonatomic, assign) NSInteger activityCount;
@end @end
@implementation AFNetworkActivityIndicatorManager @implementation AFNetworkActivityIndicatorManager
@ -40,21 +40,23 @@
} }
- (void)setActivityCount:(NSInteger)activityCount { - (void)setActivityCount:(NSInteger)activityCount {
@synchronized(self) { [self willChangeValueForKey:@"activityCount"];
[self willChangeValueForKey:@"activityCount"]; _activityCount = MAX(activityCount, 0);
_activityCount = MAX(activityCount, 0); [self didChangeValueForKey:@"activityCount"];
[self didChangeValueForKey:@"activityCount"];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
}
} }
- (void)startAnimating { - (void)startAnimating {
self.activityCount += 1; @synchronized(self) {
self.activityCount += 1;
}
} }
- (void)stopAnimating { - (void)stopAnimating {
self.activityCount -= 1; @synchronized(self) {
self.activityCount -= 1;
}
} }
@end @end