Archiviert
13
0

Re-add some method synchronization and move to a SingleThreadedExecutor in MCUtils

Dieser Commit ist enthalten in:
Zach Brown 2016-05-22 21:14:17 -05:00
Ursprung aaf6c3f329
Commit 3ab1f229c5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: CC9DA35FC5450B76
2 geänderte Dateien mit 34 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -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> From: Aikar <aikar@aikar.co>
Date: Mon, 28 Mar 2016 20:55:47 -0400 Date: Mon, 28 Mar 2016 20:55:47 -0400
Subject: [PATCH] MC Utils 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 diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
new file mode 100644 new file mode 100644
index 0000000..8643312 index 0000000..bcc8ee7
--- /dev/null --- /dev/null
+++ b/src/main/java/net/minecraft/server/MCUtil.java +++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -0,0 +1,154 @@ @@ -0,0 +1,154 @@
@ -23,7 +23,7 @@ index 0000000..8643312
+ +
+public final class MCUtil { +public final class MCUtil {
+ private static final Pattern REPLACE_QUOTES = Pattern.compile("\""); + 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() {} + private MCUtil() {}
+ +

Datei anzeigen

@ -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> From: Aikar <aikar@aikar.co>
Date: Mon, 16 May 2016 20:47:41 -0400 Date: Mon, 16 May 2016 20:47:41 -0400
Subject: [PATCH] Optimize UserCache / Thread Safe Subject: [PATCH] Optimize UserCache / Thread Safe
@ -23,9 +23,18 @@ index ec9f037..7e7ec23 100644
// Spigot end // Spigot end
} }
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java 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 --- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/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 { @@ -122,8 +122,9 @@ public class UserCache {
String s = gameprofile.getName().toLowerCase(Locale.ROOT); String s = gameprofile.getName().toLowerCase(Locale.ROOT);
UserCache.UserCacheEntry usercache_usercacheentry = new UserCache.UserCacheEntry(gameprofile, date, null); 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.d.remove(usercache_usercacheentry1.a().getName().toLowerCase(Locale.ROOT));
this.f.remove(gameprofile); 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 { @@ -227,8 +228,15 @@ public class UserCache {
} }
@ -48,7 +75,7 @@ index 5cc2731..4fde2de 100644
+ public void c(boolean asyncSave) { + public void c(boolean asyncSave) {
+ // Paper end + // Paper end
String s = this.b.toJson(this.a(org.spigotmc.SpigotConfig.userCacheCap)); 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; BufferedWriter bufferedwriter = null;
@ -58,7 +85,7 @@ index 5cc2731..4fde2de 100644
IOUtils.closeQuietly(bufferedwriter); IOUtils.closeQuietly(bufferedwriter);
} }
+ // Paper start + // Paper start
+ }; + }};
+ if (asyncSave) { + if (asyncSave) {
+ MCUtil.scheduleAsyncTask(save); + MCUtil.scheduleAsyncTask(save);
+ } else { + } else {