-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(IoT): Using custom atomic dictionary for topic listeners (#5415)
fix(IoT): Fixing random crash when a connection is attempted just after disconnecting
- Loading branch information
Showing
6 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Copyright 2010-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// A copy of the License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0 | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface AWSIoTAtomicDictionary<KeyType, ObjectType> : NSObject | ||
|
||
@property (readonly, copy) NSArray<KeyType> *allKeys; | ||
@property (readonly, copy) NSArray<ObjectType> *allValues; | ||
|
||
/// Create new instance. | ||
- (instancetype)init; | ||
|
||
- (id)objectForKey:(id)aKey; | ||
- (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey; | ||
|
||
- (void)removeObjectForKey:(id)aKey; | ||
- (void)removeAllObjects; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// Copyright 2010-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// A copy of the License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0 | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
// | ||
|
||
#import "AWSIoTAtomicDictionary.h" | ||
|
||
@interface AWSIoTAtomicDictionary() | ||
|
||
@property (nonatomic, strong) NSMutableDictionary *dictionary; | ||
@property (nonatomic, strong) NSLock *lock; | ||
|
||
@end | ||
|
||
@implementation AWSIoTAtomicDictionary | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self) { | ||
_lock = [[NSLock alloc] init]; | ||
_dictionary = [NSMutableDictionary new]; | ||
} | ||
return self; | ||
} | ||
|
||
- (NSArray *)allKeys { | ||
[self.lock lock]; | ||
NSArray * result = self.dictionary.allKeys; | ||
[self.lock unlock]; | ||
return result; | ||
} | ||
|
||
- (NSArray *)allValues { | ||
[self.lock lock]; | ||
NSArray * result = self.dictionary.allValues; | ||
[self.lock unlock]; | ||
return result; | ||
} | ||
|
||
- (id)objectForKey:(id)aKey { | ||
[self.lock lock]; | ||
id result = [self.dictionary objectForKey:aKey]; | ||
[self.lock unlock]; | ||
return result; | ||
} | ||
|
||
- (void)setObject:(id)anObject forKey:(id)aKey { | ||
[self.lock lock]; | ||
[self.dictionary setObject:anObject forKey:aKey]; | ||
[self.lock unlock]; | ||
} | ||
|
||
- (void)removeObjectForKey:(id)aKey { | ||
[self.lock lock]; | ||
[self.dictionary removeObjectForKey:aKey]; | ||
[self.lock unlock]; | ||
} | ||
|
||
- (void)removeAllObjects { | ||
[self.lock lock]; | ||
[self.dictionary removeAllObjects]; | ||
[self.lock unlock]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters