mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
Hol up
- Spin wait for .01ms in WorkerThreads before waiting
This commit is contained in:
parent
71e6dcc9ef
commit
3222c969e5
@ -198,7 +198,6 @@ public class ParallelTaskExecutor implements TaskExecutor {
|
||||
}
|
||||
|
||||
private class WorkerThread extends Thread {
|
||||
|
||||
public WorkerThread(String name) {
|
||||
super(name);
|
||||
}
|
||||
@ -209,14 +208,28 @@ public class ParallelTaskExecutor implements TaskExecutor {
|
||||
while (ParallelTaskExecutor.this.running.get()) {
|
||||
Runnable task = taskQueue.pollFirst();
|
||||
|
||||
if (task == null) {
|
||||
if (task != null) {
|
||||
processTask(task);
|
||||
} else {
|
||||
// Nothing to do, time to sleep.
|
||||
taskNotifier.awaitNotification();
|
||||
continue;
|
||||
spinThenWait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spinThenWait() {
|
||||
var waitStart = System.nanoTime();
|
||||
|
||||
// Spin for .01ms before waiting to reduce latency in narrow conditions.
|
||||
while (System.nanoTime() - waitStart < 10_000) {
|
||||
if (!taskQueue.isEmpty()) {
|
||||
// Nice! Exit without waiting.
|
||||
return;
|
||||
}
|
||||
|
||||
processTask(task);
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
taskNotifier.awaitNotification();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user