content: package kotlinx.coroutines;
  
  import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
  import kotlin.KotlinNothingValueException;
  import kotlin.Metadata;
  import kotlin.Unit;
  import kotlin.jvm.functions.Function1;
  import kotlin.jvm.internal.Intrinsics;
  import mt.Log1F380D;
  
  @Metadata(d1 = {"\u0000H\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u0001\n\u0002\b\u0002\n\u0002\u0010\u0003\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\b\u0002\u0018\u00002#\u0012\u0015\u0012\u0013\u0018\u00010\r¢\u0006\f\b\u001c\u0012\b\b\u001d\u0012\u0004\b\b(\u000e\u0012\u0004\u0012\u00020\u00050\u001bj\u0002`\u001eB\u000f\u0012\u0006\u0010\u0002\u001a\u00020\u0001¢\u0006\u0004\b\u0003\u0010\u0004J\r\u0010\u0006\u001a\u00020\u0005¢\u0006\u0004\b\u0006\u0010\u0007J\u0017\u0010\u000b\u001a\u00020\n2\u0006\u0010\t\u001a\u00020\bH\u0002¢\u0006\u0004\b\u000b\u0010\fJ\u001a\u0010\u000f\u001a\u00020\u00052\b\u0010\u000e\u001a\u0004\u0018\u00010\rH\u0002¢\u0006\u0004\b\u000f\u0010\u0010J\r\u0010\u0011\u001a\u00020\u0005¢\u0006\u0004\b\u0011\u0010\u0007R\u0018\u0010\u0013\u001a\u0004\u0018\u00010\u00128\u0002@\u0002X\u000e¢\u0006\u0006\n\u0004\b\u0013\u0010\u0014R\u0014\u0010\u0002\u001a\u00020\u00018\u0002X\u0004¢\u0006\u0006\n\u0004\b\u0002\u0010\u0015R\u001c\u0010\u0018\u001a\n \u0017*\u0004\u0018\u00010\u00160\u00168\u0002X\u0004¢\u0006\u0006\n\u0004\b\u0018\u0010\u0019¨\u0006\u001a"}, d2 = {"Lkotlinx/coroutines/ThreadState;", "Lkotlinx/coroutines/Job;", "job", "<init>", "(Lkotlinx/coroutines/Job;)V", "", "clearInterrupt", "()V", "", "state", "", "invalidState", "(I)Ljava/lang/Void;", "", "cause", "invoke", "(Ljava/lang/Throwable;)V", "setup", "Lkotlinx/coroutines/DisposableHandle;", "cancelHandle", "Lkotlinx/coroutines/DisposableHandle;", "Lkotlinx/coroutines/Job;", "Ljava/lang/Thread;", "kotlin.jvm.PlatformType", "targetThread", "Ljava/lang/Thread;", "kotlinx-coroutines-core", "Lkotlin/Function1;", "Lkotlin/ParameterName;", "name", "Lkotlinx/coroutines/CompletionHandler;"}, k = 1, mv = {1, 6, 0}, xi = 48)
  /* compiled from: 017C */
  final class ThreadState implements Function1<Throwable, Unit> {
      private static final /* synthetic */ AtomicIntegerFieldUpdater _state$FU = AtomicIntegerFieldUpdater.newUpdater(ThreadState.class, "_state");
      private volatile /* synthetic */ int _state = 0;
      private DisposableHandle cancelHandle;
      private final Job job;
      private final Thread targetThread = Thread.currentThread();
  
      public ThreadState(Job job2) {
          this.job = job2;
      }
  
      private final Void invalidState(int state) {
          String stringPlus = Intrinsics.stringPlus("Illegal state ", Integer.valueOf(state));
          Log1F380D.a((Object) stringPlus);
          throw new IllegalStateException(stringPlus.toString());
      }
  
      public final void clearInterrupt() {
          while (true) {
              int i = this._state;
              switch (i) {
                  case 0:
                      if (!_state$FU.compareAndSet(this, i, 1)) {
                          break;
                      } else {
                          DisposableHandle disposableHandle = this.cancelHandle;
                          if (disposableHandle != null) {
                              disposableHandle.dispose();
                              return;
                          }
                          return;
                      }
                  case 2:
                      break;
                  case 3:
                      Thread.interrupted();
                      return;
                  default:
                      invalidState(i);
                      throw new KotlinNothingValueException();
              }
          }
      }
  
      public /* bridge */ /* synthetic */ Object invoke(Object p1) {
          invoke((Throwable) p1);
          return Unit.INSTANCE;
      }
  
      public void invoke(Throwable cause) {
          int i;
          do {
              i = this._state;
              switch (i) {
                  case 0:
                      break;
                  case 1:
                  case 2:
                  case 3:
                      return;
                  default:
                      invalidState(i);
                      throw new KotlinNothingValueException();
              }
          } while (!_state$FU.compareAndSet(this, i, 2));
          this.targetThread.interrupt();
          this._state = 3;
      }
  
      public final void setup() {
          int i;
          this.cancelHandle = this.job.invokeOnCompletion(true, true, this);
          do {
              i = this._state;
              switch (i) {
                  case 0:
                      break;
                  case 2:
                  case 3:
                      return;
                  default:
                      invalidState(i);
                      throw new KotlinNothingValueException();
              }
          } while (!_state$FU.compareAndSet(this, i, 0));
      }
  }
  