Skip to content

Commit

Permalink
[Darwin] MTRDevice should log better (#23784)
Browse files Browse the repository at this point in the history
* Issue 23621 - [Darwin] MTRDevice should log better

* Update src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.mm

Co-authored-by: Boris Zbarsky <[email protected]>

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 28, 2023
1 parent f795227 commit a64f1c5
Show file tree
Hide file tree
Showing 5 changed files with 755 additions and 111 deletions.
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

0 comments on commit a64f1c5

Please sign in to comment.