mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-18 11:57:18 +01:00
399 lines
12 KiB
Java
399 lines
12 KiB
Java
package com.google.common.util.concurrent;
|
|
|
|
import com.google.common.annotations.GwtCompatible;
|
|
import com.google.common.annotations.GwtIncompatible;
|
|
import com.google.common.annotations.J2ktIncompatible;
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.base.Verify;
|
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|
import java.time.Duration;
|
|
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;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@GwtCompatible(emulated = true)
|
|
/* loaded from: classes8.dex */
|
|
public final class Uninterruptibles {
|
|
private Uninterruptibles() {
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean awaitTerminationUninterruptibly(ExecutorService executorService, long j, TimeUnit timeUnit) {
|
|
boolean z = false;
|
|
try {
|
|
long nanos = timeUnit.toNanos(j);
|
|
while (true) {
|
|
try {
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = (System.nanoTime() + nanos) - System.nanoTime();
|
|
}
|
|
}
|
|
return executorService.awaitTermination(nanos, TimeUnit.NANOSECONDS);
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean awaitUninterruptibly(CountDownLatch countDownLatch, long j, TimeUnit timeUnit) {
|
|
boolean z = false;
|
|
try {
|
|
long nanos = timeUnit.toNanos(j);
|
|
while (true) {
|
|
try {
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = (System.nanoTime() + nanos) - System.nanoTime();
|
|
}
|
|
}
|
|
return countDownLatch.await(nanos, TimeUnit.NANOSECONDS);
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@GwtIncompatible
|
|
@CanIgnoreReturnValue
|
|
@J2ktIncompatible
|
|
@ParametricNullness
|
|
public static <V> V getUninterruptibly(Future<V> future, long j, TimeUnit timeUnit) throws ExecutionException, TimeoutException {
|
|
boolean z = false;
|
|
try {
|
|
long nanos = timeUnit.toNanos(j);
|
|
while (true) {
|
|
try {
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = (System.nanoTime() + nanos) - System.nanoTime();
|
|
}
|
|
}
|
|
return future.get(nanos, TimeUnit.NANOSECONDS);
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
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() + nanos;
|
|
while (true) {
|
|
try {
|
|
TimeUnit.NANOSECONDS.timedJoin(thread, nanos);
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = nanoTime - System.nanoTime();
|
|
}
|
|
}
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
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();
|
|
}
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static void sleepUninterruptibly(long j, TimeUnit timeUnit) {
|
|
boolean z = false;
|
|
try {
|
|
long nanos = timeUnit.toNanos(j);
|
|
long nanoTime = System.nanoTime() + nanos;
|
|
while (true) {
|
|
try {
|
|
TimeUnit.NANOSECONDS.sleep(nanos);
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = nanoTime - System.nanoTime();
|
|
}
|
|
}
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
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;
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean tryAcquireUninterruptibly(Semaphore semaphore, int i, long j, TimeUnit timeUnit) {
|
|
boolean z = false;
|
|
try {
|
|
long nanos = timeUnit.toNanos(j);
|
|
while (true) {
|
|
try {
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = (System.nanoTime() + nanos) - System.nanoTime();
|
|
}
|
|
}
|
|
return semaphore.tryAcquire(i, nanos, TimeUnit.NANOSECONDS);
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean tryLockUninterruptibly(Lock lock, long j, TimeUnit timeUnit) {
|
|
boolean z = false;
|
|
try {
|
|
long nanos = timeUnit.toNanos(j);
|
|
while (true) {
|
|
try {
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = (System.nanoTime() + nanos) - System.nanoTime();
|
|
}
|
|
}
|
|
return lock.tryLock(nanos, TimeUnit.NANOSECONDS);
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static void sleepUninterruptibly(Duration duration) {
|
|
sleepUninterruptibly(Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean awaitTerminationUninterruptibly(ExecutorService executorService, Duration duration) {
|
|
return awaitTerminationUninterruptibly(executorService, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean awaitUninterruptibly(CountDownLatch countDownLatch, Duration duration) {
|
|
return awaitUninterruptibly(countDownLatch, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@GwtIncompatible
|
|
@IgnoreJRERequirement
|
|
@CanIgnoreReturnValue
|
|
@J2ktIncompatible
|
|
@ParametricNullness
|
|
public static <V> V getUninterruptibly(Future<V> future, Duration duration) throws ExecutionException, TimeoutException {
|
|
return (V) getUninterruptibly(future, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean tryAcquireUninterruptibly(Semaphore semaphore, long j, TimeUnit timeUnit) {
|
|
return tryAcquireUninterruptibly(semaphore, 1, j, timeUnit);
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean tryLockUninterruptibly(Lock lock, Duration duration) {
|
|
return tryLockUninterruptibly(lock, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static void awaitTerminationUninterruptibly(ExecutorService executorService) {
|
|
Verify.verify(awaitTerminationUninterruptibly(executorService, Long.MAX_VALUE, TimeUnit.NANOSECONDS));
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
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();
|
|
}
|
|
}
|
|
|
|
@CanIgnoreReturnValue
|
|
@ParametricNullness
|
|
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;
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean tryAcquireUninterruptibly(Semaphore semaphore, int i, Duration duration) {
|
|
return tryAcquireUninterruptibly(semaphore, i, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static void joinUninterruptibly(Thread thread, Duration duration) {
|
|
joinUninterruptibly(thread, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
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();
|
|
}
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean tryAcquireUninterruptibly(Semaphore semaphore, Duration duration) {
|
|
return tryAcquireUninterruptibly(semaphore, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@IgnoreJRERequirement
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean awaitUninterruptibly(Condition condition, Duration duration) {
|
|
return awaitUninterruptibly(condition, Internal.toNanosSaturated(duration), TimeUnit.NANOSECONDS);
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
public static boolean awaitUninterruptibly(Condition condition, long j, TimeUnit timeUnit) {
|
|
boolean z = false;
|
|
try {
|
|
long nanos = timeUnit.toNanos(j);
|
|
while (true) {
|
|
try {
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z = true;
|
|
nanos = (System.nanoTime() + nanos) - System.nanoTime();
|
|
}
|
|
}
|
|
return condition.await(nanos, TimeUnit.NANOSECONDS);
|
|
} finally {
|
|
if (z) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
}
|
|
}
|