content: package kotlinx.coroutines.scheduling;
  
  import java.util.concurrent.ConcurrentLinkedQueue;
  import java.util.concurrent.Executor;
  import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
  import kotlin.Metadata;
  import kotlin.coroutines.CoroutineContext;
  import kotlinx.coroutines.ExecutorCoroutineDispatcher;
  
  @Metadata(d1 = {"\u0000R\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\u0018\u0002\b\u0002\u0018\u00002\u00020+2\u00020,2\u00020\u001fB)\u0012\u0006\u0010\u0002\u001a\u00020\u0001\u0012\u0006\u0010\u0004\u001a\u00020\u0003\u0012\b\u0010\u0006\u001a\u0004\u0018\u00010\u0005\u0012\u0006\u0010\u0007\u001a\u00020\u0003¢\u0006\u0004\b\b\u0010\tJ\u000f\u0010\u000b\u001a\u00020\nH\u0016¢\u0006\u0004\b\u000b\u0010\fJ\u000f\u0010\r\u001a\u00020\nH\u0016¢\u0006\u0004\b\r\u0010\fJ#\u0010\u0013\u001a\u00020\n2\u0006\u0010\u000f\u001a\u00020\u000e2\n\u0010\u0012\u001a\u00060\u0010j\u0002`\u0011H\u0016¢\u0006\u0004\b\u0013\u0010\u0014J#\u0010\u0013\u001a\u00020\n2\n\u0010\u0012\u001a\u00060\u0010j\u0002`\u00112\u0006\u0010\u0016\u001a\u00020\u0015H\u0002¢\u0006\u0004\b\u0013\u0010\u0017J#\u0010\u0018\u001a\u00020\n2\u0006\u0010\u000f\u001a\u00020\u000e2\n\u0010\u0012\u001a\u00060\u0010j\u0002`\u0011H\u0016¢\u0006\u0004\b\u0018\u0010\u0014J\u001b\u0010\u001a\u001a\u00020\n2\n\u0010\u0019\u001a\u00060\u0010j\u0002`\u0011H\u0016¢\u0006\u0004\b\u001a\u0010\u001bJ\u000f\u0010\u001c\u001a\u00020\u0005H\u0016¢\u0006\u0004\b\u001c\u0010\u001dR\u0014\u0010\u0002\u001a\u00020\u00018\u0002X\u0004¢\u0006\u0006\n\u0004\b\u0002\u0010\u001eR\u0014\u0010\"\u001a\u00020\u001f8VX\u0004¢\u0006\u0006\u001a\u0004\b \u0010!R\u0016\u0010\u0006\u001a\u0004\u0018\u00010\u00058\u0002X\u0004¢\u0006\u0006\n\u0004\b\u0006\u0010#R\u0014\u0010\u0004\u001a\u00020\u00038\u0002X\u0004¢\u0006\u0006\n\u0004\b\u0004\u0010$R\u001e\u0010&\u001a\f\u0012\b\u0012\u00060\u0010j\u0002`\u00110%8\u0002X\u0004¢\u0006\u0006\n\u0004\b&\u0010'R\u001a\u0010\u0007\u001a\u00020\u00038\u0016X\u0004¢\u0006\f\n\u0004\b\u0007\u0010$\u001a\u0004\b(\u0010)¨\u0006*"}, d2 = {"Lkotlinx/coroutines/scheduling/LimitingDispatcher;", "Lkotlinx/coroutines/scheduling/ExperimentalCoroutineDispatcher;", "dispatcher", "", "parallelism", "", "name", "taskMode", "<init>", "(Lkotlinx/coroutines/scheduling/ExperimentalCoroutineDispatcher;ILjava/lang/String;I)V", "", "afterTask", "()V", "close", "Lkotlin/coroutines/CoroutineContext;", "context", "Ljava/lang/Runnable;", "Lkotlinx/coroutines/Runnable;", "block", "dispatch", "(Lkotlin/coroutines/CoroutineContext;Ljava/lang/Runnable;)V", "", "tailDispatch", "(Ljava/lang/Runnable;Z)V", "dispatchYield", "command", "execute", "(Ljava/lang/Runnable;)V", "toString", "()Ljava/lang/String;", "Lkotlinx/coroutines/scheduling/ExperimentalCoroutineDispatcher;", "Ljava/util/concurrent/Executor;", "getExecutor", "()Ljava/util/concurrent/Executor;", "executor", "Ljava/lang/String;", "I", "Ljava/util/concurrent/ConcurrentLinkedQueue;", "queue", "Ljava/util/concurrent/ConcurrentLinkedQueue;", "getTaskMode", "()I", "kotlinx-coroutines-core", "Lkotlinx/coroutines/ExecutorCoroutineDispatcher;", "Lkotlinx/coroutines/scheduling/TaskContext;"}, k = 1, mv = {1, 6, 0}, xi = 48)
  /* compiled from: Deprecated.kt */
  final class LimitingDispatcher extends ExecutorCoroutineDispatcher implements TaskContext, Executor {
      private static final /* synthetic */ AtomicIntegerFieldUpdater inFlightTasks$FU = AtomicIntegerFieldUpdater.newUpdater(LimitingDispatcher.class, "inFlightTasks");
      private final ExperimentalCoroutineDispatcher dispatcher;
      private volatile /* synthetic */ int inFlightTasks = 0;
      private final String name;
      private final int parallelism;
      private final ConcurrentLinkedQueue<Runnable> queue = new ConcurrentLinkedQueue<>();
      private final int taskMode;
  
      public LimitingDispatcher(ExperimentalCoroutineDispatcher dispatcher2, int parallelism2, String name2, int taskMode2) {
          this.dispatcher = dispatcher2;
          this.parallelism = parallelism2;
          this.name = name2;
          this.taskMode = taskMode2;
      }
  
      private final void dispatch(Runnable block, boolean tailDispatch) {
          Runnable poll;
          Runnable runnable = block;
          while (true) {
              AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = inFlightTasks$FU;
              if (atomicIntegerFieldUpdater.incrementAndGet(this) <= this.parallelism) {
                  this.dispatcher.dispatchWithContext$kotlinx_coroutines_core(runnable, this, tailDispatch);
                  return;
              }
              this.queue.add(runnable);
              if (atomicIntegerFieldUpdater.decrementAndGet(this) < this.parallelism && (poll = this.queue.poll()) != null) {
                  runnable = poll;
              } else {
                  return;
              }
          }
      }
  
      public void afterTask() {
          Runnable poll = this.queue.poll();
          if (poll != null) {
              this.dispatcher.dispatchWithContext$kotlinx_coroutines_core(poll, this, true);
              return;
          }
          inFlightTasks$FU.decrementAndGet(this);
          Runnable poll2 = this.queue.poll();
          if (poll2 != null) {
              dispatch(poll2, true);
          }
      }
  
      public void close() {
          throw new IllegalStateException("Close cannot be invoked on LimitingBlockingDispatcher".toString());
      }
  
      public void dispatch(CoroutineContext context, Runnable block) {
          dispatch(block, false);
      }
  
      public void dispatchYield(CoroutineContext context, Runnable block) {
          dispatch(block, true);
      }
  
      public void execute(Runnable command) {
          dispatch(command, false);
      }
  
      public Executor getExecutor() {
          return this;
      }
  
      public int getTaskMode() {
          return this.taskMode;
      }
  
      public String toString() {
          String str = this.name;
          return str == null ? super.toString() + "[dispatcher = " + this.dispatcher + ']' : str;
      }
  }
  