From e6c9108923670f579ecd88f346155fc57ab2fb7c Mon Sep 17 00:00:00 2001 From: hmelder Date: Mon, 14 Oct 2024 12:11:49 +0200 Subject: [PATCH] Remove @synchronize --- Tests/base/NSKVOSupport/general.m | 42 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Tests/base/NSKVOSupport/general.m b/Tests/base/NSKVOSupport/general.m index 9368642da..c215bde32 100644 --- a/Tests/base/NSKVOSupport/general.m +++ b/Tests/base/NSKVOSupport/general.m @@ -172,6 +172,7 @@ - (void)dealloc @interface TestKVOObserver : NSObject { NSMutableDictionary *_changedKeypaths; + NSLock *_lock; } - (void)observeValueForKeyPath:(NSString *)keypath ofObject:(id)object @@ -187,7 +188,8 @@ - (id)init self = [super init]; if (self) { - _changedKeypaths = [NSMutableDictionary dictionary]; + _changedKeypaths = [NSMutableDictionary new]; + _lock = [NSLock new]; } return self; } @@ -196,7 +198,6 @@ - (void)observeValueForKeyPath:(NSString *)keypath change:(NSDictionary *)change context:(void *)context { - @synchronized(self) { NSMutableSet *changeSet = [_changedKeypaths objectForKey:keypath]; if (!changeSet) @@ -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