Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push: fix deadlock in rest.device #663

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -54,6 +54,7 @@ ART_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