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

[Darwin] MTRDevice should log better #23784

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
24 changes: 18 additions & 6 deletions src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ - (instancetype)initWithContext:(id)context queue:(dispatch_queue_t)queue
_context = context;
_queue = queue;
_items = [NSMutableArray array];
MTR_LOG_INFO("MTRAsyncCallbackWorkQueue init for context %@", context);
}
return self;
}

- (NSString *)description
{
return [NSString
stringWithFormat:@"MTRAsyncCallbackWorkQueue context: %@ items count: %lu", self.context, (unsigned long) self.items.count];
}

- (void)enqueueWorkItem:(MTRAsyncCallbackQueueWorkItem *)item
{
os_unfair_lock_lock(&_lock);
Expand All @@ -80,6 +87,8 @@ - (void)invalidate
_items = nil;
os_unfair_lock_unlock(&_lock);

MTR_LOG_INFO(
"MTRAsyncCallbackWorkQueue invalidate for context %@ items count: %lu", _context, (unsigned long) invalidateItems.count);
for (MTRAsyncCallbackQueueWorkItem * item in invalidateItems) {
[item cancel];
}
Expand All @@ -94,7 +103,7 @@ - (void)_postProcessWorkItem:(MTRAsyncCallbackQueueWorkItem *)workItem retry:(BO
if (!self.runningWorkItemCount) {
// something is wrong with state - nothing is currently running
os_unfair_lock_unlock(&_lock);
MTR_LOG_ERROR("endWork: no work is running on work queue");
MTR_LOG_ERROR("MTRAsyncCallbackWorkQueue endWork: no work is running on work queue");
return;
}

Expand All @@ -104,7 +113,7 @@ - (void)_postProcessWorkItem:(MTRAsyncCallbackQueueWorkItem *)workItem retry:(BO
if (firstWorkItem != workItem) {
// something is wrong with this work item - should not be currently running
os_unfair_lock_unlock(&_lock);
MTR_LOG_ERROR("endWork: work item is not first on work queue");
MTR_LOG_ERROR("MTRAsyncCallbackWorkQueue endWork: work item is not first on work queue");
return;
}

Expand Down Expand Up @@ -138,11 +147,14 @@ - (void)_callNextReadyWorkItem
return;
}

// when "concurrency width" is implemented this will be incremented instead
self.runningWorkItemCount = 1;
// only proceed to mark queue as running if there are items to run
if (self.items.count) {
// when "concurrency width" is implemented this will be incremented instead
self.runningWorkItemCount = 1;

MTRAsyncCallbackQueueWorkItem * workItem = self.items.firstObject;
[workItem callReadyHandlerWithContext:self.context];
MTRAsyncCallbackQueueWorkItem * workItem = self.items.firstObject;
[workItem callReadyHandlerWithContext:self.context];
}
}
@end

Expand Down
Loading