Skip to content

Commit

Permalink
Fixing deadlock, and not cleaning up on purpose now
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Oct 8, 2024
1 parent a854245 commit 3357493
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 54 deletions.
11 changes: 3 additions & 8 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@
static bool sExitHandlerRegistered = false;
static void ShutdownOnExit()
{
// Depending on the structure of the software, this code might execute *after* the main autorelease pool has exited.
// Therefore, it needs to be enclosed in its own autorelease pool.
@autoreleasepool {
MTR_LOG("ShutdownOnExit invoked on exit");
[[MTRDeviceControllerFactory sharedInstance] stopControllerFactory];
}
// Don't do anything here, period
}

@interface MTRDeviceControllerFactoryParams ()
Expand Down Expand Up @@ -441,8 +436,8 @@ - (void)stopControllerFactory
{
[self _assertCurrentQueueIsNotMatterQueue];

while ([_controllers count] != 0) {
[_controllers[0] shutdown];
for (MTRDeviceController * controller in [_controllers copy]) {
[controller shutdown];
}

dispatch_sync(_chipWorkQueue, ^{
Expand Down
65 changes: 19 additions & 46 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,14 @@

#import <os/lock.h>

#define MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(NAME, TYPE, DEFAULT_VALUE, GETTER_NAME) \
MTR_SIMPLE_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], NAME, TYPE, DEFAULT_VALUE, GETTER_NAME, deviceController \
: [[self deviceController] uniqueIdentifier] nodeID \
: [self nodeID])
#define MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(NAME, TYPE, DEFAULT_VALUE, GETTER_NAME) \
MTR_SIMPLE_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], NAME, TYPE, DEFAULT_VALUE, GETTER_NAME, deviceController : [[self deviceController] uniqueIdentifier] nodeID : [self nodeID])

#define MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS) \
MTR_COMPLEX_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS, deviceController \
: [[self deviceController] uniqueIdentifier] nodeID \
: [self nodeID])
#define MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS) \
MTR_COMPLEX_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS, deviceController : [[self deviceController] uniqueIdentifier] nodeID : [self nodeID])

#define MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS) \
MTR_SIMPLE_REMOTE_XPC_COMMAND([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS, deviceController \
: [[self deviceController] uniqueIdentifier] nodeID \
: [self nodeID])
#define MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS) \
MTR_SIMPLE_REMOTE_XPC_COMMAND([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS, deviceController : [[self deviceController] uniqueIdentifier] nodeID : [self nodeID])

@implementation MTRDevice_XPC

Expand Down Expand Up @@ -200,40 +194,18 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di
MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(estimatedSubscriptionLatency, NSNumber * _Nullable, nil, getEstimatedSubscriptionLatencyWithReply)

typedef NSDictionary<NSString *, id> * _Nullable ReadAttributeResponseType;
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributeWithEndpointID
: (NSNumber *) endpointID clusterID
: (NSNumber *) clusterID attributeID
: (NSNumber *) attributeID params
: (MTRReadParams * _Nullable) params,
ReadAttributeResponseType,
nil,
readAttributeWithEndpointID
: endpointID clusterID
: clusterID attributeID
: attributeID params
: params withReply)

MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(writeAttributeWithEndpointID
: (NSNumber *) endpointID clusterID
: (NSNumber *) clusterID attributeID
: (NSNumber *) attributeID value
: (id) value expectedValueInterval
: (NSNumber *) expectedValueInterval timedWriteTimeout
: (NSNumber * _Nullable) timeout, writeAttributeWithEndpointID
: endpointID clusterID
: clusterID attributeID
: attributeID value
: value expectedValueInterval
: expectedValueInterval timedWriteTimeout
: timeout)
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributeWithEndpointID : (NSNumber *) endpointID clusterID : (NSNumber *) clusterID attributeID : (NSNumber *) attributeID params : (MTRReadParams * _Nullable) params,
ReadAttributeResponseType,
nil,
readAttributeWithEndpointID : endpointID clusterID : clusterID attributeID : attributeID params : params withReply)

MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(writeAttributeWithEndpointID : (NSNumber *) endpointID clusterID : (NSNumber *) clusterID attributeID : (NSNumber *) attributeID value : (id) value expectedValueInterval : (NSNumber *) expectedValueInterval timedWriteTimeout : (NSNumber * _Nullable) timeout, writeAttributeWithEndpointID : endpointID clusterID : clusterID attributeID : attributeID value : value expectedValueInterval : expectedValueInterval timedWriteTimeout : timeout)

typedef NSArray<NSDictionary<NSString *, id> *> * ReadAttributePathsResponseType;
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributePaths
: (NSArray<MTRAttributeRequestPath *> *) attributePaths,
ReadAttributePathsResponseType,
[NSArray array], // Default return value
readAttributePaths
: attributePaths withReply)
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributePaths : (NSArray<MTRAttributeRequestPath *> *) attributePaths,
ReadAttributePathsResponseType,
[NSArray array], // Default return value
readAttributePaths : attributePaths withReply)

- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
Expand All @@ -250,7 +222,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID

@try {
[[xpcConnection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
MTR_LOG_ERROR("Error: %@", error);
completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
}] deviceController:[[self deviceController] uniqueIdentifier]
nodeID:[self nodeID]
invokeCommandWithEndpointID:endpointID
Expand All @@ -263,7 +235,8 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
serverSideProcessingTimeout:serverSideProcessingTimeout
completion:completion];
} @catch (NSException * exception) {
MTR_LOG_ERROR("Exception sending XPC messsage: %@", exception);
MTR_LOG_ERROR("Exception sending XPC message: %@", exception);
completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
}
}

Expand Down

0 comments on commit 3357493

Please sign in to comment.