Skip to content

Commit 2993123

Browse files
eDO Teammobile-devx-github-bot
authored andcommitted
Fix warning in Xcode 26 in client service for thread performance checker.
PiperOrigin-RevId: 796623220
1 parent d228369 commit 2993123

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

Channel/Sources/EDOChannel.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ typedef void (^EDOChannelSentHandler)(id<EDOChannel> channel, NSError *_Nullable
9494
*/
9595
- (void)receiveDataWithHandler:(EDOChannelReceiveHandler _Nullable)handler;
9696

97+
/**
98+
* Schedule the block for the next received data to process.
99+
*
100+
* When the new data is received, the handler will be dispatched on the given @c queue. If the data
101+
* is received without scheduling any block, it is up to the implementation to ignore or buffer it
102+
* locally, i.e. TCP socket may allow some system buffer to temporarily cache the data. For the
103+
* request/response style communication, it is better to call this in the sentCompletion block to
104+
* avoid race condition as the scheduled receive block may not be in the same order of the
105+
* @c sendData:withCompletionHandler.
106+
*
107+
* @param queue The dispatch queue on which the handler will be dispatched.
108+
* @param handler The handler to be dispatched when the data is received.
109+
* @remark Once it schedules the block to receive data, it will retain itself until the data is
110+
* received or it becomes invalid by calling @c invalidate or it detects the other end
111+
* closes the channel.
112+
*/
113+
- (void)receiveDataWithQueue:(dispatch_queue_t)queue
114+
handler:(EDOChannelReceiveHandler _Nullable)handler;
115+
97116
/**
98117
* Invalidate this channel.
99118
*

Channel/Sources/EDOSocketChannel.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ - (void)sendData:(NSData *)data withCompletionHandler:(EDOChannelSentHandler)han
111111
}
112112

113113
- (void)receiveDataWithHandler:(EDOChannelReceiveHandler)handler {
114-
dispatch_queue_t handlerQueue = self.handlerQueue;
114+
[self receiveDataWithQueue:self.handlerQueue handler:handler];
115+
}
116+
117+
- (void)receiveDataWithQueue:(dispatch_queue_t)queue
118+
handler:(EDOChannelReceiveHandler _Nullable)handler {
119+
dispatch_queue_t handlerQueue = queue;
115120
dispatch_io_t channel = self.channel;
116121
if (!channel) {
117122
dispatch_async(handlerQueue, ^{

Service/Sources/EDOClientService.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ + (EDOServiceResponse *)sendSynchronousRequest:(EDOServiceRequest *)request
262262
while (currentAttempt < maxAttempts) {
263263
NSError *connectionError;
264264
uint64_t connectionStartTime = mach_absolute_time();
265-
dispatch_queue_t connectionQueue = nil;
266265
dispatch_queue_t executionQueue = executor.executionQueue;
267-
if (executionQueue) {
268-
dispatch_queue_attr_t queueAttributes = dispatch_queue_attr_make_with_qos_class(
269-
DISPATCH_QUEUE_SERIAL, dispatch_queue_get_qos_class(executionQueue, nil), 0);
270-
connectionQueue = dispatch_queue_create("com.google.edo.connectChannel", queueAttributes);
271-
}
266+
dispatch_qos_class_t qosClass =
267+
executionQueue ? dispatch_queue_get_qos_class(executionQueue, nil) : qos_class_self();
268+
dispatch_queue_attr_t queueAttributes =
269+
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, qosClass, 0);
270+
dispatch_queue_t connectionQueue =
271+
dispatch_queue_create("com.google.edo.connectChannel", queueAttributes);
272272
id<EDOChannel> channel = [EDOChannelPool.sharedChannelPool channelWithPort:port
273273
connectionQueue:connectionQueue
274274
error:&connectionError];
@@ -427,7 +427,8 @@ + (NSData *)sendRequestData:(NSData *)requestData withChannel:(id<EDOChannel>)ch
427427
};
428428

429429
// Check ping response to make sure channel is healthy.
430-
[channel receiveDataWithHandler:receiveHandler];
430+
[channel receiveDataWithQueue:dispatch_get_global_queue(qos_class_self(), 0)
431+
handler:receiveHandler];
431432

432433
dispatch_time_t timeoutInSeconds = dispatch_time(DISPATCH_TIME_NOW, kPingTimeoutSeconds);
433434
long result = dispatch_semaphore_wait(waitLock, timeoutInSeconds);

0 commit comments

Comments
 (0)