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

Ensure nesting is only decremented when lock was acquired successfully #4000

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,17 @@ public boolean exec() {
// this means that .join() will wait.
return false;
}
try (ResourceLock lock = resourceLock.acquire()) {
threadLock.incrementNesting(lock);
try ( //
ResourceLock lock = resourceLock.acquire(); //
@SuppressWarnings("unused")
ThreadLock.NestedResourceLock nested = threadLock.withNesting(lock) //
) {
testTask.execute();
return true;
}
catch (InterruptedException e) {
throw ExceptionUtils.throwAsUncheckedException(e);
}
finally {
threadLock.decrementNesting();
}
}

@Override
Expand Down Expand Up @@ -300,18 +300,19 @@ void addDeferredTask(ExclusiveTask task) {
deferredTasks.add(task);
}

void incrementNesting(ResourceLock lock) {
NestedResourceLock withNesting(ResourceLock lock) {
locks.push(lock);
}

@SuppressWarnings("resource")
void decrementNesting() {
locks.pop();
return locks::pop;
}

boolean areAllHeldLocksCompatibleWith(ResourceLock lock) {
return locks.stream().allMatch(l -> l.isCompatible(lock));
}

interface NestedResourceLock extends AutoCloseable {
@Override
void close();
}
}

interface TaskEventListener {
Expand Down
Loading