Permalink
Browse files

Ok, making the entire reading and increment atomic.

  • Loading branch information...
1 parent 9a0ed24 commit ef0cb8190912d14336ff8e5df10241bff573995a Evan Long committed Aug 31, 2011
Showing with 12 additions and 10 deletions.
  1. +12 −10 AFNetworking/AFNetworkActivityIndicatorManager.m
@@ -23,7 +23,7 @@
#import "AFNetworkActivityIndicatorManager.h"
@interface AFNetworkActivityIndicatorManager ()
-@property (readwrite, assign) NSInteger activityCount;
+@property (readwrite, nonatomic, assign) NSInteger activityCount;
@end
@implementation AFNetworkActivityIndicatorManager
@@ -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.