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

Fixes coalesce operation race condition #24

Merged
merged 2 commits into from
Sep 9, 2019
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
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Main workflow

on: [pull_request]

jobs:
Lint:
name: Run Unit and Integration Tests (macOS)
runs-on: macOS-latest
steps:
- name: Checkout the Git repository
uses: actions/checkout@v1
- name: Setup dependencies
run: sudo gem install cocoapods danger danger-slack xcpretty
- name: Run Tests
run: make all
21 changes: 21 additions & 0 deletions .github/workflows/ci_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Main workflow

on:
push:
# Sequence of patterns matched against refs/heads
branches:
- master # Push events on master branch
- 'releases/*' # Push events to branches matching refs/heads/releases/*


jobs:
Lint:
name: Run Unit and Integration Tests (macOS)
runs-on: macOS-latest
steps:
- name: Checkout the Git repository
uses: actions/checkout@v1
- name: Setup dependencies
run: sudo gem install cocoapods danger danger-slack xcpretty
- name: Run Tests
run: make all
25 changes: 13 additions & 12 deletions Source/PINOperationQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,10 @@ - (void)setMaxConcurrentOperations:(NSUInteger)maxConcurrentOperations

- (BOOL)locked_cancelOperation:(id <PINOperationReference>)operationReference
{
BOOL success = NO;
PINOperation *operation = [_referenceToOperations objectForKey:operationReference];
if (operation) {
NSMutableOrderedSet *queue = [self operationQueueWithPriority:operation.priority];
if ([queue containsObject:operation]) {
success = YES;
[queue removeObject:operation];
[_queuedOperations removeObject:operation];
dispatch_group_leave(_group);
}
BOOL success = [self locked_removeOperation:operation];
if (success) {
dispatch_group_leave(_group);
}
return success;
}
Expand Down Expand Up @@ -448,13 +442,20 @@ - (void)waitUntilAllOperationsAreFinished
}

//Call with lock held
- (void)locked_removeOperation:(PINOperation *)operation
- (BOOL)locked_removeOperation:(PINOperation *)operation
{
if (operation) {
NSMutableOrderedSet *priorityQueue = [self operationQueueWithPriority:operation.priority];
[priorityQueue removeObject:operation];
[_queuedOperations removeObject:operation];
if ([priorityQueue containsObject:operation]) {
[priorityQueue removeObject:operation];
[_queuedOperations removeObject:operation];
if (operation.identifier) {
[_identifierToOperations removeObjectForKey:operation.identifier];
}
return YES;
}
}
return NO;
}

- (void)lock
Expand Down