Skip to content

Commit

Permalink
Remove @synchronize
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Oct 14, 2024
1 parent 14a3af1 commit e6c9108
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions Tests/base/NSKVOSupport/general.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ - (void)dealloc
@interface TestKVOObserver : NSObject
{
NSMutableDictionary *_changedKeypaths;
NSLock *_lock;
}
- (void)observeValueForKeyPath:(NSString *)keypath
ofObject:(id)object
Expand All @@ -187,7 +188,8 @@ - (id)init
self = [super init];
if (self)
{
_changedKeypaths = [NSMutableDictionary dictionary];
_changedKeypaths = [NSMutableDictionary new];
_lock = [NSLock new];
}
return self;
}
Expand All @@ -196,7 +198,6 @@ - (void)observeValueForKeyPath:(NSString *)keypath
change:(NSDictionary *)change
context:(void *)context
{
@synchronized(self)
{
NSMutableSet *changeSet = [_changedKeypaths objectForKey:keypath];
if (!changeSet)
Expand All @@ -212,29 +213,32 @@ - (void)observeValueForKeyPath:(NSString *)keypath
}
- (NSSet *)changesForKeypath:(NSString *)keypath
{
@synchronized(self)
{
return [[_changedKeypaths objectForKey:keypath] copy];
}
[_lock lock];
NSSet *paths = [[_changedKeypaths objectForKey:keypath] copy];
[_lock unlock];
return paths;
}
- (void)clear
{
@synchronized(self)
{
[_changedKeypaths removeAllObjects];
}
[_lock lock];
[_changedKeypaths removeAllObjects];
[_lock unlock];
}
- (NSInteger)numberOfObservedChanges
{
@synchronized(self)
{
NSInteger accumulator = 0;
for (NSString *keypath in [_changedKeypaths allKeys])
{
accumulator += [[_changedKeypaths objectForKey:keypath] count];
}
return accumulator;
}
[_lock lock];
NSInteger accumulator = 0;
for (NSString *keypath in [_changedKeypaths allKeys])
{
accumulator += [[_changedKeypaths objectForKey:keypath] count];
}
[_lock unlock];
return accumulator;
}

- (void) dealloc {
[_lock release];
[_changedKeypaths release];
}
@end

Expand Down

0 comments on commit e6c9108

Please sign in to comment.