SoundEngineExecutor .java

net.minecraft.client.sounds.SoundEngineExecutor (class, 77 lines): members: shutDown, shutdown, startUp, waitForTasks, getRunningThread, shouldRun, thread.

net.minecraft.client.soundsclass77 linesclientextends BlockableEventLoop<Runnable>1.7 KB

API Surface (7)

Runnable wrapRunnable(final Runnable runnable)
void schedule(final Runnable runnable)
boolean shouldRun(final Runnable task)
Thread getRunningThread()
void waitForTasks()
void shutDown()
void startUp()

Fields & Constants (2)

thread
shutdown

String literals (4)

"Sound executor"
"Sound engine"
"Uncaught exception on thread: "
"waiting for tasks"

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SoundEngineExecutor.java77 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.sounds;
2
3
import java.util.concurrent.locks.LockSupport;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.CrashReport;
7
import net.minecraft.client.Minecraft;
8
import net.minecraft.util.thread.BlockableEventLoop;
9
10
@Environment(EnvType.CLIENT)
11
public class SoundEngineExecutor extends BlockableEventLoop<Runnable> {
12
	private Thread thread = this.createThread();
13
	private volatile boolean shutdown;
14
15
	public SoundEngineExecutor() {
16
		super("Sound executor", false);
17
	}
18
19
	private Thread createThread() {
20
		Thread thread = new Thread(this::run, "Sound engine");
21
		thread.setDaemon(true);
22
		thread.setUncaughtExceptionHandler((t, e) -> Minecraft.getInstance().delayCrash(CrashReport.forThrowable(e, "Uncaught exception on thread: " + t.getName())));
23
		thread.start();
24
		return thread;
25
	}
26
27
	@Override
28
	public Runnable wrapRunnable(final Runnable runnable) {
29
		return runnable;
30
	}
31
32
	@Override
33
	public void schedule(final Runnable runnable) {
34
		if (!this.shutdown) {
35
			super.schedule(runnable);
36
		}
37
	}
38
39
	@Override
40
	protected boolean shouldRun(final Runnable task) {
41
		return !this.shutdown;
42
	}
43
44
	@Override
45
	protected Thread getRunningThread() {
46
		return this.thread;
47
	}
48
49
	private void run() {
50
		while (!this.shutdown) {
51
			this.managedBlock(() -> this.shutdown);
52
		}
53
	}
54
55
	@Override
56
	protected void waitForTasks() {
57
		LockSupport.park("waiting for tasks");
58
	}
59
60
	public void shutDown() {
61
		this.shutdown = true;
62
		this.dropAllTasks();
63
		this.thread.interrupt();
64
65
		try {
66
			this.thread.join();
67
		} catch (InterruptedException e) {
68
			Thread.currentThread().interrupt();
69
		}
70
	}
71
72
	public void startUp() {
73
		this.shutdown = false;
74
		this.thread = this.createThread();
75
	}
76
}
77

Decompiled Minecraft 26.3 source of SoundEngineExecutor (net/minecraft/client/sounds/SoundEngineExecutor.java) with Mojang official mappings, stored verbatim on the site.