-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WaitableSignal was factored out from GradleFilesClassPathProvider
- Loading branch information
Showing
2 changed files
with
48 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.netbeans.gradle.project; | ||
|
||
import java.util.concurrent.locks.Condition; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
public final class WaitableSignal { | ||
private final Lock lock; | ||
private final Condition signalEvent; | ||
private volatile boolean signaled; | ||
|
||
public WaitableSignal() { | ||
this.lock = new ReentrantLock(); | ||
this.signalEvent = this.lock.newCondition(); | ||
this.signaled = false; | ||
} | ||
|
||
public void signal() { | ||
lock.lock(); | ||
try { | ||
signaled = true; | ||
signalEvent.signalAll(); | ||
} finally { | ||
lock.unlock(); | ||
} | ||
} | ||
|
||
public boolean tryWaitForSignal() { | ||
if (signaled) { | ||
return true; | ||
} | ||
lock.lock(); | ||
try { | ||
while (!signaled) { | ||
signalEvent.await(); | ||
} | ||
} catch (InterruptedException ex) { | ||
Thread.currentThread().interrupt(); | ||
} finally { | ||
lock.unlock(); | ||
} | ||
return signaled; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters