mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
Re-add some method synchronization and move to a SingleThreadedExecutor in MCUtils
This commit is contained in:
parent
aaf6c3f329
commit
3ab1f229c5
2 changed files with 34 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
From a3e63b2551a8b3dfabbc600ea7e5e72763ec6888 Mon Sep 17 00:00:00 2001
|
||||
From e4c4535575c0397de1e8a388e09428dd60947d13 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Mon, 28 Mar 2016 20:55:47 -0400
|
||||
Subject: [PATCH] MC Utils
|
||||
|
@ -7,7 +7,7 @@ Collection of utils to help reduce NMS diff
|
|||
|
||||
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
||||
new file mode 100644
|
||||
index 0000000..8643312
|
||||
index 0000000..bcc8ee7
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
||||
@@ -0,0 +1,154 @@
|
||||
|
@ -23,7 +23,7 @@ index 0000000..8643312
|
|||
+
|
||||
+public final class MCUtil {
|
||||
+ private static final Pattern REPLACE_QUOTES = Pattern.compile("\"");
|
||||
+ private static final Executor asyncExecutor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Paper Async Task Handler Thread - %1$d").build());
|
||||
+ private static final Executor asyncExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Paper Async Task Handler Thread - %1$d").build());
|
||||
+
|
||||
+ private MCUtil() {}
|
||||
+
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
From a16fb3ba3001e1a330a3b2aeae75a89870d69d33 Mon Sep 17 00:00:00 2001
|
||||
From fadf46bd5f5d74c2a61e95601b3bd3704b16d71b Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Mon, 16 May 2016 20:47:41 -0400
|
||||
Subject: [PATCH] Optimize UserCache / Thread Safe
|
||||
|
@ -23,9 +23,18 @@ index ec9f037..7e7ec23 100644
|
|||
// Spigot end
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
|
||||
index 5cc2731..4fde2de 100644
|
||||
index 5cc2731..ca20b3d 100644
|
||||
--- a/src/main/java/net/minecraft/server/UserCache.java
|
||||
+++ b/src/main/java/net/minecraft/server/UserCache.java
|
||||
@@ -108,7 +108,7 @@ public class UserCache {
|
||||
this.a(gameprofile, (Date) null);
|
||||
}
|
||||
|
||||
- private void a(GameProfile gameprofile, Date date) {
|
||||
+ private synchronized void a(GameProfile gameprofile, Date date) { // Paper - synchronize
|
||||
UUID uuid = gameprofile.getId();
|
||||
|
||||
if (date == null) {
|
||||
@@ -122,8 +122,9 @@ public class UserCache {
|
||||
String s = gameprofile.getName().toLowerCase(Locale.ROOT);
|
||||
UserCache.UserCacheEntry usercache_usercacheentry = new UserCache.UserCacheEntry(gameprofile, date, null);
|
||||
|
@ -37,6 +46,24 @@ index 5cc2731..4fde2de 100644
|
|||
|
||||
this.d.remove(usercache_usercacheentry1.a().getName().toLowerCase(Locale.ROOT));
|
||||
this.f.remove(gameprofile);
|
||||
@@ -136,7 +137,7 @@ public class UserCache {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
- public GameProfile getProfile(String s) {
|
||||
+ public synchronized GameProfile getProfile(String s) { // Paper - synchronize
|
||||
String s1 = s.toLowerCase(Locale.ROOT);
|
||||
UserCache.UserCacheEntry usercache_usercacheentry = (UserCache.UserCacheEntry) this.d.get(s1);
|
||||
|
||||
@@ -165,7 +166,7 @@ public class UserCache {
|
||||
return usercache_usercacheentry == null ? null : usercache_usercacheentry.a();
|
||||
}
|
||||
|
||||
- public String[] a() {
|
||||
+ public synchronized String[] a() { // Paper - synchronize
|
||||
ArrayList arraylist = Lists.newArrayList(this.d.keySet());
|
||||
|
||||
return (String[]) arraylist.toArray(new String[arraylist.size()]);
|
||||
@@ -227,8 +228,15 @@ public class UserCache {
|
||||
|
||||
}
|
||||
|
@ -48,7 +75,7 @@ index 5cc2731..4fde2de 100644
|
|||
+ public void c(boolean asyncSave) {
|
||||
+ // Paper end
|
||||
String s = this.b.toJson(this.a(org.spigotmc.SpigotConfig.userCacheCap));
|
||||
+ Runnable save = () -> { // Paper - ensure only 1 file is writing at same time by syncing to the FD // ¯\_(ツ)_/¯
|
||||
+ Runnable save = () -> { // Paper - ensure only 1 file is writing at same time by syncing to the FD
|
||||
+
|
||||
BufferedWriter bufferedwriter = null;
|
||||
|
||||
|
@ -58,7 +85,7 @@ index 5cc2731..4fde2de 100644
|
|||
IOUtils.closeQuietly(bufferedwriter);
|
||||
}
|
||||
+ // Paper start
|
||||
+ };
|
||||
+ }};
|
||||
+ if (asyncSave) {
|
||||
+ MCUtil.scheduleAsyncTask(save);
|
||||
+ } else {
|
||||
|
|
Loading…
Reference in a new issue