|
2 | 2 |
|
3 | 3 | import net.minecraft.util.thread.BlockableEventLoop; |
4 | 4 | import org.spongepowered.asm.mixin.Mixin; |
5 | | -import org.spongepowered.asm.mixin.injection.At; |
6 | | -import org.spongepowered.asm.mixin.injection.ModifyArg; |
7 | | -import org.spongepowered.asm.mixin.injection.Redirect; |
| 5 | +import org.spongepowered.asm.mixin.Overwrite; |
8 | 6 |
|
9 | 7 | import java.util.concurrent.TimeUnit; |
| 8 | +import java.util.concurrent.locks.LockSupport; |
10 | 9 |
|
11 | 10 | // This should fix https://bugs.mojang.com/browse/MC-183518 |
12 | | -@Mixin(BlockableEventLoop.class) |
| 11 | +@Mixin(value = BlockableEventLoop.class, priority = 500) |
13 | 12 | public class BlockableEventLoopMixin { |
14 | | - /** |
15 | | - * @author embeddedt |
16 | | - * @reason yielding the thread is pretty pointless if we're about to park anyway |
17 | | - */ |
18 | | - @Redirect(method = "waitForTasks", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;yield()V"), require = 0) |
19 | | - private void doNotYield() {} |
20 | | - |
21 | 13 | private static final long MFIX$TICK_WAIT_TIME = TimeUnit.MILLISECONDS.toNanos(2); |
22 | 14 |
|
23 | 15 | /** |
24 | 16 | * @author embeddedt |
25 | | - * @reason park for more than 0.1ms at a time. Task submission will call unpark(), so the thread will become |
26 | | - * runnable again if a task is submitted. |
| 17 | + * @reason yielding the thread is pretty pointless if we're about to park anyway |
27 | 18 | */ |
28 | | - @ModifyArg(method = "waitForTasks", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/locks/LockSupport;parkNanos(Ljava/lang/Object;J)V"), index = 1, require = 0) |
29 | | - private long changeParkDuration(long originalDuration) { |
30 | | - return MFIX$TICK_WAIT_TIME; |
| 19 | + @Overwrite |
| 20 | + protected void waitForTasks() { |
| 21 | + LockSupport.parkNanos("waiting for tasks", MFIX$TICK_WAIT_TIME); |
31 | 22 | } |
32 | 23 | } |
0 commit comments