diff src/goodjava/lucene/logging/SemaphoreLock.java @ 1538:634f6765830e

use goodjava/lucene/logging
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 07 Aug 2020 21:42:16 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/goodjava/lucene/logging/SemaphoreLock.java	Fri Aug 07 21:42:16 2020 -0600
@@ -0,0 +1,21 @@
+package goodjava.lucene.logging;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+
+public final class SemaphoreLock {
+	private final Semaphore semaphore = new Semaphore(1);
+
+	public void unlock() {
+		semaphore.release();
+	}
+
+	public boolean isLocked() {
+		return semaphore.availablePermits() == 0;
+	}
+
+	public boolean tryLock(long time,TimeUnit unit) throws InterruptedException {
+		return semaphore.tryAcquire(time,unit);
+	}
+}