Skip to content

Commit

Permalink
Add os_unfair_lock_assert_owner and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling-apple committed Sep 27, 2023
1 parent 2f95a2f commit 8592ff4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/darwin/Framework/CHIP/MTRAsyncWorkQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ typedef BOOL (^MTRAsyncWorkCompletionBlock)(MTRAsyncWorkOutcome outcome);
///
/// The handler will be passed the opaque data of the two work items:
/// `opaqueDataCurrent` is the data of the item about to be executed and
/// `opaqueDataNext` is the data for the next item.
/// `opaqueDataNext` is the data for the next item. The `fullyMerged` parameter
/// will be initialized to NO by the caller.
///
/// The handler is expected to mutate the data as needed to achieve batching.
///
Expand All @@ -64,7 +65,8 @@ typedef void (^MTRAsyncWorkBatchingHandler)(id opaqueDataCurrent, id opaqueDataN
/// Duplicate checking is performed in reverse queue order, i.e. more
/// recently enqueued items will be checked first.
///
/// The handler will be passed the opaque data of the candidate work item.
/// The handler will be passed the opaque data of the candidate work item. The
/// `stop` and `isDuplicate` parameters will be initialized to NO by the caller.
///
/// If the handler determines the data is indeed duplicate work, it should
/// set `stop` to YES, and set `isDuplicate` to YES.
Expand Down
5 changes: 4 additions & 1 deletion src/darwin/Framework/CHIP/MTRAsyncWorkQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ - (void)invalidate

- (void)_postProcessWorkItem:(MTRAsyncWorkItem *)workItem retry:(BOOL)retry
{
os_unfair_lock_assert_owner(&_lock);

MTRAsyncWorkItem * runningWorkItem = (_runningWorkItemCount) ? _items.firstObject : nil;
if (workItem != runningWorkItem) {
NSAssert(NO, @"work item to post-process is not running");
Expand All @@ -230,9 +232,10 @@ - (void)_postProcessWorkItem:(MTRAsyncWorkItem *)workItem retry:(BOOL)retry
[self _callNextReadyWorkItem];
}

// assume lock is held while calling this
- (void)_callNextReadyWorkItem
{
os_unfair_lock_assert_owner(&_lock);

// when "concurrency width" is implemented this will be checked against the width
if (_runningWorkItemCount) {
return; // can't run next work item until the current one is done
Expand Down

0 comments on commit 8592ff4

Please sign in to comment.