Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen authored and marcphilipp committed Sep 16, 2024
1 parent 1449c4a commit 72437f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ on GitHub.

==== Bug Fixes

* ❓
* Fixed potential locking issue with `ExclusiveResource` in the
`HierarchicalTestExecutorService`, which could lead to deadlocks in certain scenarios.

==== Deprecations and Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CompositeLock implements ResourceLock {

// for tests only
List<Lock> getLocks() {
return locks;
return this.locks;
}

@Override
Expand All @@ -38,9 +38,9 @@ public ResourceLock acquire() throws InterruptedException {
}

private void acquireAllLocks() throws InterruptedException {
List<Lock> acquiredLocks = new ArrayList<>(locks.size());
List<Lock> acquiredLocks = new ArrayList<>(this.locks.size());
try {
for (Lock lock : locks) {
for (Lock lock : this.locks) {
lock.lockInterruptibly();
acquiredLocks.add(lock);
}
Expand All @@ -53,7 +53,7 @@ private void acquireAllLocks() throws InterruptedException {

@Override
public void release() {
release(locks);
release(this.locks);
}

private void release(List<Lock> acquiredLocks) {
Expand All @@ -64,20 +64,20 @@ private void release(List<Lock> acquiredLocks) {

private class CompositeLockManagedBlocker implements ForkJoinPool.ManagedBlocker {

private boolean acquired;
private volatile boolean acquired;

@Override
public boolean block() throws InterruptedException {
if (!acquired) {
if (!this.acquired) {
acquireAllLocks();
acquired = true;
this.acquired = true;
}
return true;
}

@Override
public boolean isReleasable() {
return acquired;
return this.acquired;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SingleLock implements ResourceLock {

// for tests only
Lock getLock() {
return lock;
return this.lock;
}

@Override
Expand All @@ -37,25 +37,25 @@ public ResourceLock acquire() throws InterruptedException {

@Override
public void release() {
lock.unlock();
this.lock.unlock();
}

private class SingleLockManagedBlocker implements ForkJoinPool.ManagedBlocker {

private boolean acquired;
private volatile boolean acquired;

@Override
public boolean block() throws InterruptedException {
if (!acquired) {
lock.lockInterruptibly();
acquired = true;
if (!this.acquired) {
SingleLock.this.lock.lockInterruptibly();
this.acquired = true;
}
return true;
}

@Override
public boolean isReleasable() {
return acquired || (acquired = lock.tryLock());
return this.acquired || (this.acquired = SingleLock.this.lock.tryLock());
}

}
Expand Down

0 comments on commit 72437f6

Please sign in to comment.