Ver código fonte

去掉SingletonLock跟ConfigSingleton中的Lock,dotnet中对引用的获取跟赋值是原子的

tanghai 2 anos atrás
pai
commit
364ebcf822

+ 1 - 1
Unity/Assets/Scripts/Core/Entity/EntitySystemSingleton.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    public class EntitySystemSingleton: SingletonLock<EntitySystemSingleton>, ISingletonAwake
+    public class EntitySystemSingleton: SingletonReload<EntitySystemSingleton>, ISingletonAwake
     {
         public TypeSystems TypeSystems { get; private set; }
         

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Actor/ActorMessageDispatcherComponent.cs

@@ -19,7 +19,7 @@ namespace ET
     /// <summary>
     /// Actor消息分发组件
     /// </summary>
-    public class ActorMessageDispatcherComponent: SingletonLock<ActorMessageDispatcherComponent>, ISingletonAwake
+    public class ActorMessageDispatcherComponent: SingletonReload<ActorMessageDispatcherComponent>, ISingletonAwake
     {
         private readonly Dictionary<Type, List<ActorMessageDispatcherInfo>> ActorMessageHandlers = new();
 

+ 2 - 11
Unity/Assets/Scripts/Core/World/Module/Config/ConfigSingleton.cs

@@ -10,24 +10,15 @@ namespace ET
         [StaticField]
         private static T instance;
         
-        [StaticField]
-        private static object lockObj = new();
-
         public static T Instance
         {
             get
             {
-                lock (lockObj)
-                {
-                    return instance;
-                }
+                return instance;
             }
             private set
             {
-                lock (lockObj)
-                {
-                    instance = value;
-                }
+                instance = value;
             }
         }
 

+ 3 - 12
Unity/Assets/Scripts/Core/World/Singleton.cs

@@ -56,31 +56,22 @@ namespace ET
         }
     }
     
-    public abstract class SingletonLock<T>: ISingleton, ISingletonLoad where T: SingletonLock<T>, new()
+    public abstract class SingletonReload<T>: ISingleton, ISingletonLoad where T: SingletonReload<T>, new()
     {
         private bool isDisposed;
         
         [StaticField]
         private static T instance;
         
-        [StaticField]
-        private static object lockObj = new();
-
         public static T Instance
         {
             get
             {
-                lock (lockObj)
-                {
-                    return instance;
-                }
+                return instance;
             }
             private set
             {
-                lock (lockObj)
-                {
-                    instance = value;
-                }
+                instance = value;
             }
         }
 

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/Http/HttpDispatcher.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 
 namespace ET.Server
 {
-    public class HttpDispatcher: SingletonLock<HttpDispatcher>, ISingletonAwake
+    public class HttpDispatcher: SingletonReload<HttpDispatcher>, ISingletonAwake
     {
         private readonly Dictionary<string, Dictionary<int, IHttpHandler>> dispatcher = new();
         

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSingleton.cs

@@ -11,7 +11,7 @@ namespace ET
         public const int Max = 1;
     }
     
-    public class LSEntitySystemSingleton: SingletonLock<LSEntitySystemSingleton>, ISingletonAwake
+    public class LSEntitySystemSingleton: SingletonReload<LSEntitySystemSingleton>, ISingletonAwake
     {
         public TypeSystems TypeSystems { get; private set; }
         

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/AI/AIDispatcherComponent.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    public class AIDispatcherComponent: SingletonLock<AIDispatcherComponent>, ISingletonAwake
+    public class AIDispatcherComponent: SingletonReload<AIDispatcherComponent>, ISingletonAwake
     {
         private readonly Dictionary<string, AAIHandler> aiHandlers = new();
         

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Console/ConsoleDispatcher.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    public class ConsoleDispatcher: SingletonLock<ConsoleDispatcher>, ISingletonAwake
+    public class ConsoleDispatcher: SingletonReload<ConsoleDispatcher>, ISingletonAwake
     {
         private readonly Dictionary<string, IConsoleHandler> handlers = new();
         

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Message/MessageDispatcherComponent.cs

@@ -15,7 +15,7 @@ namespace ET
         }
     }
     
-    public class MessageDispatcherComponent: SingletonLock<MessageDispatcherComponent>, ISingletonAwake
+    public class MessageDispatcherComponent: SingletonReload<MessageDispatcherComponent>, ISingletonAwake
     {
         private readonly Dictionary<ushort, List<MessageDispatcherInfo>> handlers = new();
         

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Numeric/NumericWatcherComponent.cs

@@ -18,7 +18,7 @@ namespace ET
     /// <summary>
     /// 监视数值变化组件,分发监听
     /// </summary>
-    public class NumericWatcherComponent : SingletonLock<NumericWatcherComponent>, ISingletonAwake
+    public class NumericWatcherComponent : SingletonReload<NumericWatcherComponent>, ISingletonAwake
     {
         private readonly Dictionary<int, List<NumericWatcherInfo>> allWatchers = new();
         

+ 1 - 1
Unity/Assets/Scripts/ModelView/Client/Module/UI/UIEventComponent.cs

@@ -7,7 +7,7 @@ namespace ET.Client
 	/// <summary>
 	/// 管理所有UI GameObject
 	/// </summary>
-	public class UIEventComponent: SingletonLock<UIEventComponent>, ISingletonAwake
+	public class UIEventComponent: SingletonReload<UIEventComponent>, ISingletonAwake
 	{
 		public Dictionary<string, AUIEvent> UIEvents { get; } = new();