content: package okio;
  
  import java.io.IOException;
  import java.io.InterruptedIOException;
  import java.util.concurrent.TimeUnit;
  import kotlin.Metadata;
  import kotlin.Unit;
  import kotlin.jvm.functions.Function0;
  import kotlin.jvm.internal.DefaultConstructorMarker;
  import kotlin.jvm.internal.InlineMarker;
  import kotlin.jvm.internal.Intrinsics;
  
  @Metadata(bv = {1, 0, 3}, d1 = {"\u00000\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0016\u0018\u0000 \u00172\u00020\u0001:\u0001\u0017B\u0005¢\u0006\u0002\u0010\u0002J\b\u0010\b\u001a\u00020\u0000H\u0016J\b\u0010\t\u001a\u00020\u0000H\u0016J\u0016\u0010\n\u001a\u00020\u00002\u0006\u0010\u000b\u001a\u00020\u00042\u0006\u0010\f\u001a\u00020\rJ\b\u0010\u0003\u001a\u00020\u0004H\u0016J\u0010\u0010\u0003\u001a\u00020\u00002\u0006\u0010\u0003\u001a\u00020\u0004H\u0016J\b\u0010\u0005\u001a\u00020\u0006H\u0016J\"\u0010\u000e\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u00002\f\u0010\u0011\u001a\b\u0012\u0004\u0012\u00020\u000f0\u0012H\bø\u0001\u0000J\b\u0010\u0013\u001a\u00020\u000fH\u0016J\u0018\u0010\u0014\u001a\u00020\u00002\u0006\u0010\u0014\u001a\u00020\u00042\u0006\u0010\f\u001a\u00020\rH\u0016J\b\u0010\u0007\u001a\u00020\u0004H\u0016J\u000e\u0010\u0015\u001a\u00020\u000f2\u0006\u0010\u0016\u001a\u00020\u0001R\u000e\u0010\u0003\u001a\u00020\u0004X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\u0004X\u000e¢\u0006\u0002\n\u0000\u0002\u0007\n\u0005\b20\u0001¨\u0006\u0018"}, d2 = {"Lokio/Timeout;", "", "()V", "deadlineNanoTime", "", "hasDeadline", "", "timeoutNanos", "clearDeadline", "clearTimeout", "deadline", "duration", "unit", "Ljava/util/concurrent/TimeUnit;", "intersectWith", "", "other", "block", "Lkotlin/Function0;", "throwIfReached", "timeout", "waitUntilNotified", "monitor", "Companion", "okio"}, k = 1, mv = {1, 4, 0})
  /* compiled from: Timeout.kt */
  public class Timeout {
      public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
      public static final Timeout NONE = new Timeout$Companion$NONE$1();
      private long deadlineNanoTime;
      private boolean hasDeadline;
      private long timeoutNanos;
  
      @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0003\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0016\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\u00062\u0006\u0010\b\u001a\u00020\u0006R\u0010\u0010\u0003\u001a\u00020\u00048\u0006X\u0004¢\u0006\u0002\n\u0000¨\u0006\t"}, d2 = {"Lokio/Timeout$Companion;", "", "()V", "NONE", "Lokio/Timeout;", "minTimeout", "", "aNanos", "bNanos", "okio"}, k = 1, mv = {1, 4, 0})
      /* compiled from: Timeout.kt */
      public static final class Companion {
          private Companion() {
          }
  
          public /* synthetic */ Companion(DefaultConstructorMarker $constructor_marker) {
              this();
          }
  
          public final long minTimeout(long aNanos, long bNanos) {
              return (aNanos != 0 && (bNanos == 0 || aNanos < bNanos)) ? aNanos : bNanos;
          }
      }
  
      public Timeout clearDeadline() {
          this.hasDeadline = false;
          return this;
      }
  
      public Timeout clearTimeout() {
          this.timeoutNanos = 0;
          return this;
      }
  
      public final Timeout deadline(long duration, TimeUnit unit) {
          Intrinsics.checkNotNullParameter(unit, "unit");
          if (duration > 0) {
              return deadlineNanoTime(System.nanoTime() + unit.toNanos(duration));
          }
          throw new IllegalArgumentException(("duration <= 0: " + duration).toString());
      }
  
      public long deadlineNanoTime() {
          if (this.hasDeadline) {
              return this.deadlineNanoTime;
          }
          throw new IllegalStateException("No deadline".toString());
      }
  
      public Timeout deadlineNanoTime(long deadlineNanoTime2) {
          this.hasDeadline = true;
          this.deadlineNanoTime = deadlineNanoTime2;
          return this;
      }
  
      public boolean hasDeadline() {
          return this.hasDeadline;
      }
  
      public final void intersectWith(Timeout other, Function0<Unit> block) {
          Intrinsics.checkNotNullParameter(other, "other");
          Intrinsics.checkNotNullParameter(block, "block");
          long timeoutNanos2 = timeoutNanos();
          timeout(Companion.minTimeout(other.timeoutNanos(), timeoutNanos()), TimeUnit.NANOSECONDS);
          if (hasDeadline()) {
              long deadlineNanoTime2 = deadlineNanoTime();
              if (other.hasDeadline()) {
                  deadlineNanoTime(Math.min(deadlineNanoTime(), other.deadlineNanoTime()));
              }
              try {
                  block.invoke();
              } finally {
                  InlineMarker.finallyStart(1);
                  timeout(timeoutNanos2, TimeUnit.NANOSECONDS);
                  if (other.hasDeadline()) {
                      deadlineNanoTime(deadlineNanoTime2);
                  }
                  InlineMarker.finallyEnd(1);
              }
          } else {
              if (other.hasDeadline()) {
                  deadlineNanoTime(other.deadlineNanoTime());
              }
              try {
                  block.invoke();
              } finally {
                  InlineMarker.finallyStart(1);
                  timeout(timeoutNanos2, TimeUnit.NANOSECONDS);
                  if (other.hasDeadline()) {
                      clearDeadline();
                  }
                  InlineMarker.finallyEnd(1);
              }
          }
      }
  
      public void throwIfReached() throws IOException {
          if (Thread.interrupted()) {
              Thread.currentThread().interrupt();
              throw new InterruptedIOException("interrupted");
          } else if (this.hasDeadline && this.deadlineNanoTime - System.nanoTime() <= 0) {
              throw new InterruptedIOException("deadline reached");
          }
      }
  
      public Timeout timeout(long timeout, TimeUnit unit) {
          Intrinsics.checkNotNullParameter(unit, "unit");
          if (timeout >= 0) {
              this.timeoutNanos = unit.toNanos(timeout);
              return this;
          }
          throw new IllegalArgumentException(("timeout < 0: " + timeout).toString());
      }
  
      public long timeoutNanos() {
          return this.timeoutNanos;
      }
  
      public final void waitUntilNotified(Object monitor) throws InterruptedIOException {
          Intrinsics.checkNotNullParameter(monitor, "monitor");
          try {
              boolean hasDeadline2 = hasDeadline();
              long timeoutNanos2 = timeoutNanos();
              if (hasDeadline2 || timeoutNanos2 != 0) {
                  long nanoTime = System.nanoTime();
                  long deadlineNanoTime2 = (!hasDeadline2 || timeoutNanos2 == 0) ? hasDeadline2 ? deadlineNanoTime() - nanoTime : timeoutNanos2 : Math.min(timeoutNanos2, deadlineNanoTime() - nanoTime);
                  long j = 0;
                  if (deadlineNanoTime2 > 0) {
                      long j2 = deadlineNanoTime2 / 1000000;
                      monitor.wait(j2, (int) (deadlineNanoTime2 - (1000000 * j2)));
                      j = System.nanoTime() - nanoTime;
                  }
                  if (j >= deadlineNanoTime2) {
                      throw new InterruptedIOException("timeout");
                  }
                  return;
              }
              monitor.wait();
          } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
              throw new InterruptedIOException("interrupted");
          }
      }
  }
  