Skip to content

Commit

Permalink
Fix deadlock in rest.device (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira authored and funkyboy committed Jul 17, 2018
1 parent 5b650f0 commit 0874b52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Source/ARTPushActivationStateMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ - (void)persist {

- (void)deviceRegistration:(ARTErrorInfo *)error {
#ifdef TARGET_OS_IOS
ARTLocalDevice *local = _rest.device;
ARTLocalDevice *local = _rest.device_nosync;

if (![[UIApplication sharedApplication].delegate conformsToProtocol:@protocol(ARTPushRegistererDelegate)]) {
[NSException raise:@"ARTPushRegistererDelegate must be implemented on AppDelegate" format:@""];
Expand Down Expand Up @@ -156,7 +156,7 @@ - (void)deviceRegistration:(ARTErrorInfo *)error {

- (void)deviceUpdateRegistration:(ARTErrorInfo *)error {
#ifdef TARGET_OS_IOS
ARTLocalDevice *local = _rest.device;
ARTLocalDevice *local = _rest.device_nosync;

if (![[UIApplication sharedApplication].delegate conformsToProtocol:@protocol(ARTPushRegistererDelegate)]) {
[NSException raise:@"ARTPushRegistererDelegate must be implemented on AppDelegate" format:@""];
Expand Down Expand Up @@ -218,7 +218,7 @@ - (void)deviceUpdateRegistration:(ARTErrorInfo *)error {

- (void)deviceUnregistration:(ARTErrorInfo *)error {
#ifdef TARGET_OS_IOS
ARTLocalDevice *local = _rest.device;
ARTLocalDevice *local = _rest.device_nosync;

id delegate = [UIApplication sharedApplication].delegate;

Expand Down
1 change: 1 addition & 0 deletions Source/ARTRest.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) ARTPush *push;
#ifdef TARGET_OS_IOS
@property (nonnull, nonatomic, readonly, getter=device) ARTLocalDevice *device;
@property (nonnull, nonatomic, readonly, getter=device_nosync) ARTLocalDevice *device_nosync;
#endif

@end
Expand Down
12 changes: 9 additions & 3 deletions Source/ARTRest.m
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,18 @@ void ARTstopHandlingUncaughtExceptions(ARTRest *self) {
}

- (ARTLocalDevice *)device {
__block ARTLocalDevice *ret;
dispatch_sync(_queue, ^{
ret = [self device_nosync];
});
return ret;
}

- (NSString *)device_nosync {
static dispatch_once_t once;
static id device;
dispatch_once(&once, ^{
dispatch_sync(_queue, ^{
device = [ARTLocalDevice load:self];
});
device = [ARTLocalDevice load:self];
});
return device;
}
Expand Down

0 comments on commit 0874b52

Please sign in to comment.