Skip to content

Commit

Permalink
Ok, making the entire reading and increment atomic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Long committed Aug 31, 2011
1 parent 9a0ed24 commit ef0cb81
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions AFNetworking/AFNetworkActivityIndicatorManager.m
Expand Up @@ -23,7 +23,7 @@
#import "AFNetworkActivityIndicatorManager.h"

@interface AFNetworkActivityIndicatorManager ()
@property (readwrite, assign) NSInteger activityCount;
@property (readwrite, nonatomic, assign) NSInteger activityCount;
@end

@implementation AFNetworkActivityIndicatorManager
Expand All @@ -40,21 +40,23 @@ + (AFNetworkActivityIndicatorManager *)sharedManager {
}

- (void)setActivityCount:(NSInteger)activityCount {
@synchronized(self) {
[self willChangeValueForKey:@"activityCount"];
_activityCount = MAX(activityCount, 0);
[self didChangeValueForKey:@"activityCount"];

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
}
[self willChangeValueForKey:@"activityCount"];
_activityCount = MAX(activityCount, 0);
[self didChangeValueForKey:@"activityCount"];

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
}

- (void)startAnimating {
self.activityCount += 1;
@synchronized(self) {
self.activityCount += 1;
}
}

- (void)stopAnimating {
self.activityCount -= 1;
@synchronized(self) {
self.activityCount -= 1;
}
}

@end

0 comments on commit ef0cb81

Please sign in to comment.