Use thread groups to detect the effective side (#3644)
This commit is contained in:
parent
f0eb941abc
commit
9619be4a17
6 changed files with 129 additions and 9 deletions
|
@ -1,5 +1,30 @@
|
|||
--- ../src-base/minecraft/net/minecraft/network/NetworkSystem.java
|
||||
+++ ../src-work/minecraft/net/minecraft/network/NetworkSystem.java
|
||||
@@ -50,21 +50,21 @@
|
||||
{
|
||||
protected NioEventLoopGroup func_179280_b()
|
||||
{
|
||||
- return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build());
|
||||
+ return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).setThreadFactory(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER).build());
|
||||
}
|
||||
};
|
||||
public static final LazyLoadBase<EpollEventLoopGroup> field_181141_b = new LazyLoadBase<EpollEventLoopGroup>()
|
||||
{
|
||||
protected EpollEventLoopGroup func_179280_b()
|
||||
{
|
||||
- return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).build());
|
||||
+ return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).setThreadFactory(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER).build());
|
||||
}
|
||||
};
|
||||
public static final LazyLoadBase<LocalEventLoopGroup> field_180232_b = new LazyLoadBase<LocalEventLoopGroup>()
|
||||
{
|
||||
protected LocalEventLoopGroup func_179280_b()
|
||||
{
|
||||
- return new LocalEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Server IO #%d").setDaemon(true).build());
|
||||
+ return new LocalEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Server IO #%d").setDaemon(true).setThreadFactory(net.minecraftforge.fml.common.thread.SidedThreadGroups.CLIENT).build());
|
||||
}
|
||||
};
|
||||
private final MinecraftServer field_151273_d;
|
||||
@@ -111,7 +111,7 @@
|
||||
;
|
||||
}
|
||||
|
|
|
@ -243,14 +243,16 @@
|
|||
this.field_71304_b.func_76318_c("connection");
|
||||
this.func_147137_ag().func_151269_c();
|
||||
this.field_71304_b.func_76318_c("players");
|
||||
@@ -758,6 +760,7 @@
|
||||
@@ -758,7 +760,8 @@
|
||||
|
||||
public void func_71256_s()
|
||||
{
|
||||
- this.field_175590_aa = new Thread(this, "Server thread");
|
||||
+ net.minecraftforge.fml.common.StartupQuery.reset();
|
||||
this.field_175590_aa = new Thread(this, "Server thread");
|
||||
+ this.field_175590_aa = new Thread(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER, this, "Server thread");
|
||||
this.field_175590_aa.start();
|
||||
}
|
||||
|
||||
@@ -774,7 +777,13 @@
|
||||
|
||||
public WorldServer func_71218_a(int p_71218_1_)
|
||||
|
|
|
@ -18,3 +18,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@
|
||||
this.field_147335_k = p_147315_1_.func_149300_a(privatekey);
|
||||
this.field_147328_g = NetHandlerLoginServer.LoginState.AUTHENTICATING;
|
||||
this.field_147333_a.func_150727_a(this.field_147335_k);
|
||||
- (new Thread("User Authenticator #" + field_147331_b.incrementAndGet())
|
||||
+ (new Thread(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER, "User Authenticator #" + field_147331_b.incrementAndGet())
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
|
|
|
@ -64,6 +64,8 @@ import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
|||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.thread.SidedThreadGroup;
|
||||
import net.minecraftforge.fml.common.thread.SidedThreadGroups;
|
||||
import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.server.FMLServerHandler;
|
||||
|
@ -201,13 +203,8 @@ public class FMLCommonHandler
|
|||
*/
|
||||
public Side getEffectiveSide()
|
||||
{
|
||||
Thread thr = Thread.currentThread();
|
||||
if (thr.getName().equals("Server thread") || thr.getName().startsWith("Netty Server IO"))
|
||||
{
|
||||
return Side.SERVER;
|
||||
}
|
||||
|
||||
return Side.CLIENT;
|
||||
final ThreadGroup group = Thread.currentThread().getThreadGroup();
|
||||
return group instanceof SidedThreadGroup ? ((SidedThreadGroup) group).getSide() : Side.CLIENT;
|
||||
}
|
||||
/**
|
||||
* Raise an exception
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.common.thread;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* A thread group and factory combination which belongs to a {@link Side}.
|
||||
*/
|
||||
public final class SidedThreadGroup extends ThreadGroup implements ThreadFactory
|
||||
{
|
||||
private final Side side;
|
||||
|
||||
SidedThreadGroup(final Side side)
|
||||
{
|
||||
super(side.name());
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the side this sided thread group belongs to.
|
||||
*
|
||||
* @return the side
|
||||
*/
|
||||
public Side getSide()
|
||||
{
|
||||
return this.side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(@Nonnull final Runnable runnable)
|
||||
{
|
||||
return new Thread(this, runnable);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.common.thread;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
public final class SidedThreadGroups
|
||||
{
|
||||
public static final SidedThreadGroup CLIENT = new SidedThreadGroup(Side.CLIENT);
|
||||
public static final SidedThreadGroup SERVER = new SidedThreadGroup(Side.SERVER);
|
||||
|
||||
private SidedThreadGroups() {
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue