304 lines
9.2 KiB
Java
304 lines
9.2 KiB
Java
|
package com.google.common.util.concurrent;
|
||
|
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import com.google.common.base.Verify;
|
||
|
import java.util.concurrent.BlockingQueue;
|
||
|
import java.util.concurrent.CountDownLatch;
|
||
|
import java.util.concurrent.ExecutionException;
|
||
|
import java.util.concurrent.ExecutorService;
|
||
|
import java.util.concurrent.Future;
|
||
|
import java.util.concurrent.Semaphore;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
import java.util.concurrent.TimeoutException;
|
||
|
import java.util.concurrent.locks.Condition;
|
||
|
import java.util.concurrent.locks.Lock;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class Uninterruptibles {
|
||
|
public static void awaitUninterruptibly(CountDownLatch countDownLatch) {
|
||
|
boolean z = false;
|
||
|
while (true) {
|
||
|
try {
|
||
|
countDownLatch.await();
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
} catch (Throwable th) {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean awaitUninterruptibly(CountDownLatch countDownLatch, long j, TimeUnit timeUnit) {
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (System.nanoTime() + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
return countDownLatch.await(j2, TimeUnit.NANOSECONDS);
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean awaitUninterruptibly(Condition condition, long j, TimeUnit timeUnit) {
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (System.nanoTime() + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
return condition.await(j2, TimeUnit.NANOSECONDS);
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void joinUninterruptibly(Thread thread) {
|
||
|
boolean z = false;
|
||
|
while (true) {
|
||
|
try {
|
||
|
thread.join();
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
} catch (Throwable th) {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void joinUninterruptibly(Thread thread, long j, TimeUnit timeUnit) {
|
||
|
Preconditions.checkNotNull(thread);
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long nanoTime = System.nanoTime();
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
TimeUnit.NANOSECONDS.timedJoin(thread, j2);
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (nanoTime + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static <V> V getUninterruptibly(Future<V> future) throws ExecutionException {
|
||
|
V v;
|
||
|
boolean z = false;
|
||
|
while (true) {
|
||
|
try {
|
||
|
v = future.get();
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
} catch (Throwable th) {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
return v;
|
||
|
}
|
||
|
|
||
|
public static <V> V getUninterruptibly(Future<V> future, long j, TimeUnit timeUnit) throws ExecutionException, TimeoutException {
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (System.nanoTime() + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
return future.get(j2, TimeUnit.NANOSECONDS);
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static <E> E takeUninterruptibly(BlockingQueue<E> blockingQueue) {
|
||
|
E take;
|
||
|
boolean z = false;
|
||
|
while (true) {
|
||
|
try {
|
||
|
take = blockingQueue.take();
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
} catch (Throwable th) {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
return take;
|
||
|
}
|
||
|
|
||
|
public static <E> void putUninterruptibly(BlockingQueue<E> blockingQueue, E e) {
|
||
|
boolean z = false;
|
||
|
while (true) {
|
||
|
try {
|
||
|
blockingQueue.put(e);
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
} catch (Throwable th) {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void sleepUninterruptibly(long j, TimeUnit timeUnit) {
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long nanoTime = System.nanoTime();
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
TimeUnit.NANOSECONDS.sleep(j2);
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (nanoTime + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean tryAcquireUninterruptibly(Semaphore semaphore, long j, TimeUnit timeUnit) {
|
||
|
return tryAcquireUninterruptibly(semaphore, 1, j, timeUnit);
|
||
|
}
|
||
|
|
||
|
public static boolean tryAcquireUninterruptibly(Semaphore semaphore, int i, long j, TimeUnit timeUnit) {
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (System.nanoTime() + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
return semaphore.tryAcquire(i, j2, TimeUnit.NANOSECONDS);
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean tryLockUninterruptibly(Lock lock, long j, TimeUnit timeUnit) {
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (System.nanoTime() + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
return lock.tryLock(j2, TimeUnit.NANOSECONDS);
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void awaitTerminationUninterruptibly(ExecutorService executorService) {
|
||
|
Verify.verify(awaitTerminationUninterruptibly(executorService, Long.MAX_VALUE, TimeUnit.NANOSECONDS));
|
||
|
}
|
||
|
|
||
|
public static boolean awaitTerminationUninterruptibly(ExecutorService executorService, long j, TimeUnit timeUnit) {
|
||
|
boolean z = false;
|
||
|
try {
|
||
|
long nanos = timeUnit.toNanos(j);
|
||
|
long j2 = nanos;
|
||
|
while (true) {
|
||
|
try {
|
||
|
break;
|
||
|
} catch (InterruptedException unused) {
|
||
|
z = true;
|
||
|
j2 = (System.nanoTime() + nanos) - System.nanoTime();
|
||
|
}
|
||
|
}
|
||
|
return executorService.awaitTermination(j2, TimeUnit.NANOSECONDS);
|
||
|
} finally {
|
||
|
if (z) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private Uninterruptibles() {
|
||
|
}
|
||
|
}
|