23 package com.realtime.crossfire.jxclient.sound;
25 import java.util.concurrent.BlockingQueue;
26 import java.util.concurrent.LinkedBlockingQueue;
27 import java.util.concurrent.Semaphore;
28 import org.jetbrains.annotations.NotNull;
40 private final BlockingQueue<Runnable>
tasks =
new LinkedBlockingQueue<>();
46 private final Thread
thread =
new Thread(this::executeTasks,
"JXClient:SoundTaskExecutor");
66 while (!Thread.currentThread().isInterrupted()) {
69 }
catch (
final InterruptedException ignored) {
81 public void execute(@NotNull
final Runnable task) {
82 if (Thread.currentThread() ==
thread) {
83 throw new IllegalStateException(
"must not be called from a sound task");
95 public void executeAndWait(@NotNull
final Runnable task)
throws InterruptedException {
96 if (Thread.currentThread() ==
thread) {
97 throw new IllegalStateException(
"must not be called from a sound task");
99 final Semaphore sem =
new Semaphore(0);