From 51f78db84aa9f88a54164fdd40299fefaf161c07 Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Fri, 17 Jul 2026 13:29:10 -0700 Subject: [PATCH] Standardize property attributes and refactor private properties. This change: * Explicitly adds `nonatomic` to properties where thread safety is not required, improving performance. * Adds `atomic` to class properties and other properties where thread safety is important. * Refactors private properties in `ITRTestTraceRecorder` to be instance variables. * Simplifies the `EDODeviceDetector` by removing a redundant `started` property and using the channel's existence. PiperOrigin-RevId: 949734296 --- Channel/Sources/EDOBlockingQueue.h | 4 ++-- Channel/Sources/EDOChannelMultiplexer.h | 2 +- Channel/Sources/EDOChannelPool.h | 4 ++-- Channel/Sources/EDOHostPort.h | 2 +- Device/Sources/EDODeviceConnector.h | 4 ++-- Device/Sources/EDODeviceDetector.m | 8 +------- Service/Sources/EDOHostNamingService.h | 6 +++--- Service/Sources/EDORemoteException.h | 2 +- Service/Sources/EDOServiceRequest.h | 2 +- 9 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Channel/Sources/EDOBlockingQueue.h b/Channel/Sources/EDOBlockingQueue.h index 6082385d..151d0134 100644 --- a/Channel/Sources/EDOBlockingQueue.h +++ b/Channel/Sources/EDOBlockingQueue.h @@ -31,10 +31,10 @@ NS_ASSUME_NONNULL_BEGIN @interface EDOBlockingQueue : NSObject /** Whether the queue has any objects. */ -@property(readonly, getter=isEmpty) BOOL empty; +@property(atomic, readonly, getter=isEmpty) BOOL empty; /** The number of objects in the queue. */ -@property(readonly) NSUInteger count; +@property(atomic, readonly) NSUInteger count; /** Appends the @c object to the end of the queue. * diff --git a/Channel/Sources/EDOChannelMultiplexer.h b/Channel/Sources/EDOChannelMultiplexer.h index 6b44a1e6..948d33a3 100644 --- a/Channel/Sources/EDOChannelMultiplexer.h +++ b/Channel/Sources/EDOChannelMultiplexer.h @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN @property(readonly, nonatomic) EDOHostPort *port; /** The number of channels that are set up with the forwarder and ready to connect. */ -@property(readonly) NSUInteger numberOfChannels; +@property(readonly, nonatomic) NSUInteger numberOfChannels; /** * Starts the multiplexer on the given @c port. diff --git a/Channel/Sources/EDOChannelPool.h b/Channel/Sources/EDOChannelPool.h index bb3cb9a6..70fb00d0 100644 --- a/Channel/Sources/EDOChannelPool.h +++ b/Channel/Sources/EDOChannelPool.h @@ -32,13 +32,13 @@ NS_ASSUME_NONNULL_BEGIN @interface EDOChannelPool : NSObject /** The singleton of @c EDOChannelPool. */ -@property(class, readonly) EDOChannelPool *sharedChannelPool; +@property(atomic, class, readonly) EDOChannelPool *sharedChannelPool; /** * A port for clients to accept connection, and receive host name to register as service. This port * will lazily create a listen socket when accessed. */ -@property(readonly) UInt16 serviceConnectionPort; +@property(nonatomic, readonly) UInt16 serviceConnectionPort; /** * Fetches an already-connected channel from the pool, keyed by the host @c port. diff --git a/Channel/Sources/EDOHostPort.h b/Channel/Sources/EDOHostPort.h index 64f6a76b..fdee671b 100644 --- a/Channel/Sources/EDOHostPort.h +++ b/Channel/Sources/EDOHostPort.h @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN * TODO(haowoo): This will be used to identify whether the host is on a real device or a machine * later, to replace deviceSerialNumber. */ -@property(readonly, class) NSString *deviceIdentifier; +@property(readonly, class, nonatomic) NSString *deviceIdentifier; /** The listen port number of the host. 0 if the host port is identified by name. */ @property(readonly, nonatomic) UInt16 port; diff --git a/Device/Sources/EDODeviceConnector.h b/Device/Sources/EDODeviceConnector.h index 0bb44c07..600e80f9 100644 --- a/Device/Sources/EDODeviceConnector.h +++ b/Device/Sources/EDODeviceConnector.h @@ -40,9 +40,9 @@ extern NSString *const EDODeviceIDKey; @interface EDODeviceConnector : NSObject /** The serial numbers of connected devices. */ -@property(readonly) NSArray *connectedDevices; +@property(nonatomic, readonly) NSArray *connectedDevices; /** Shared device connector. */ -@property(readonly, class) EDODeviceConnector *sharedConnector; +@property(atomic, readonly, class) EDODeviceConnector *sharedConnector; - (instancetype)init NS_UNAVAILABLE; diff --git a/Device/Sources/EDODeviceDetector.m b/Device/Sources/EDODeviceDetector.m index 8a582651..5277bc9d 100644 --- a/Device/Sources/EDODeviceDetector.m +++ b/Device/Sources/EDODeviceDetector.m @@ -25,8 +25,6 @@ @interface EDODeviceDetector () * is called. */ @property(nonatomic) EDODeviceChannel *channel; -/** @c YES if the detector has already started to listen to broadcast. */ -@property(readonly) BOOL started; @end @@ -37,7 +35,7 @@ - (BOOL)listenToBroadcastWithError:(NSError **)error __block NSError *resultError; EDODeviceChannel *deviceChannel; @synchronized(self) { - if (!self.started) { + if (!self.channel) { deviceChannel = [EDODeviceChannel channelWithError:&resultError]; self.channel = deviceChannel; } else { @@ -93,10 +91,6 @@ - (void)cancel { } } -- (BOOL)started { - return self.channel != nil; -} - #pragma mark - Private - (void)edo_scheduleReadBroadcastPacketWithHandler:(EDOBroadcastHandler)handler { diff --git a/Service/Sources/EDOHostNamingService.h b/Service/Sources/EDOHostNamingService.h index 3a23cb36..45ac7872 100644 --- a/Service/Sources/EDOHostNamingService.h +++ b/Service/Sources/EDOHostNamingService.h @@ -32,16 +32,16 @@ NS_ASSUME_NONNULL_BEGIN @interface EDOHostNamingService : NSObject /** The default port number 11237 which the naming service will be listening on. */ -@property(class, readonly) UInt16 namingServerPort; +@property(nonatomic, class, readonly) UInt16 namingServerPort; /** Shared singleton instance. */ -@property(class, readonly) EDOHostNamingService *sharedService; +@property(atomic, class, readonly) EDOHostNamingService *sharedService; /** * The port for service registration. Clients can connect to this port to register their * services by name. */ -@property(readonly) UInt16 serviceConnectionPort; +@property(nonatomic, readonly) UInt16 serviceConnectionPort; - (instancetype)init NS_UNAVAILABLE; diff --git a/Service/Sources/EDORemoteException.h b/Service/Sources/EDORemoteException.h index 72c83ee9..8c40284e 100644 --- a/Service/Sources/EDORemoteException.h +++ b/Service/Sources/EDORemoteException.h @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN @interface EDORemoteException : NSException /** The merged call stack traces of both client process and host process. */ -@property(readonly, copy) NSArray *callStackSymbols; +@property(atomic, readonly, copy) NSArray *callStackSymbols; /** EDORemoteException cannot be initialized with default data members. */ - (instancetype)init NS_UNAVAILABLE; diff --git a/Service/Sources/EDOServiceRequest.h b/Service/Sources/EDOServiceRequest.h index a7d9d723..e04cfec4 100644 --- a/Service/Sources/EDOServiceRequest.h +++ b/Service/Sources/EDOServiceRequest.h @@ -45,7 +45,7 @@ typedef EDOServiceResponse *_Nonnull (^EDORequestHandler)(EDOServiceRequest *req * The sub classes should override this and provide its own handler. The default implementation * returns an EDOErrorRequestNotHandled response. */ -@property(readonly, class) EDORequestHandler requestHandler; +@property(readonly, class, nonatomic) EDORequestHandler requestHandler; - (instancetype)initWithMessageID:(NSString *)messageID NS_UNAVAILABLE;