Skip to content

Commit

Permalink
Add isHeld to lock interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns committed Jul 30, 2024
1 parent 1eba1cf commit fda65f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public void unlock() {
Preconditions.checkState(locked, "WorkflowLock.unlock called when not locked");
locked = false;
}

@Override
public boolean isHeld() {
return locked;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public interface WorkflowLock {

/** Releases the lock. */
void unlock();

/**
* Checks if a lock is held.
*
* @return true if the lock is held and false otherwise.
*/
boolean isHeld();
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public void testThreadInterleaving() {
WorkflowLock l2 = WorkflowInternal.newWorkflowLock();
trace.add("root begin");
l2.lock();
trace.add("l1.isHeld " + l1.isHeld());
trace.add("l2.isHeld " + l2.isHeld());
WorkflowThread.newThread(
() -> {
trace.add("thread1 begin");
Expand Down Expand Up @@ -96,6 +98,8 @@ public void testThreadInterleaving() {
String[] expected =
new String[] {
"root begin",
"l1.isHeld false",
"l2.isHeld true",
"root done",
"thread1 begin",
"thread1 lock 1 success",
Expand Down

0 comments on commit fda65f0

Please sign in to comment.