mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-26 00:27:08 +01:00
Prevent blocking on adding a new network manager (#3027)
Previous solution could still block network thread (while addPending is executing). This window is small, but removing it completely is better. This should probably also speed up concurrent adds, because no locking will be performed anymore. The only possible downside is that adding elements one by one to synchronized list might be slower (But it's done while already locked, so maybe jvm will avoid additional locking?),
This commit is contained in:
parent
94476a6910
commit
d490d491ff
1 changed files with 5 additions and 5 deletions
|
@ -6,7 +6,7 @@ Subject: [PATCH] Avoid blocking on Network Manager creation
|
|||
Per Paper issue 294
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/ServerConnection.java b/src/main/java/net/minecraft/server/ServerConnection.java
|
||||
index e7e216850..9cd7c9064 100644
|
||||
index e7e21685..404e7834 100644
|
||||
--- a/src/main/java/net/minecraft/server/ServerConnection.java
|
||||
+++ b/src/main/java/net/minecraft/server/ServerConnection.java
|
||||
@@ -0,0 +0,0 @@ public class ServerConnection {
|
||||
|
@ -14,11 +14,11 @@ index e7e216850..9cd7c9064 100644
|
|||
private final List<ChannelFuture> listeningChannels = Collections.synchronizedList(Lists.newArrayList());
|
||||
private final List<NetworkManager> connectedChannels = Collections.synchronizedList(Lists.newArrayList());
|
||||
+ // Paper start - prevent blocking on adding a new network manager while the server is ticking
|
||||
+ private final List<NetworkManager> pending = Collections.synchronizedList(Lists.<NetworkManager>newArrayList());
|
||||
+ private final java.util.Queue<NetworkManager> pending = new java.util.concurrent.ConcurrentLinkedQueue<>();
|
||||
+ private void addPending() {
|
||||
+ synchronized (pending) {
|
||||
+ connectedChannels.addAll(pending);
|
||||
+ pending.clear();
|
||||
+ NetworkManager manager = null;
|
||||
+ while ((manager = pending.poll()) != null) {
|
||||
+ connectedChannels.add(manager);
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
|
Loading…
Add table
Reference in a new issue