diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/XNetEventPool.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XNetEventPool.cs')
-rw-r--r-- | Client/Assets/Scripts/XMainClient/XNetEventPool.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/XNetEventPool.cs b/Client/Assets/Scripts/XMainClient/XNetEventPool.cs new file mode 100644 index 00000000..4cac37c8 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XNetEventPool.cs @@ -0,0 +1,54 @@ +using System;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace XMainClient
+{
+ internal class XNetEventPool
+ {
+ private static Queue<NetEvent> _pool = new Queue<NetEvent>(128);
+
+ public static NetEvent GetEvent()
+ {
+ NetEvent netEvent = null;
+ Monitor.Enter(XNetEventPool._pool);
+ bool flag = XNetEventPool._pool.Count > 0;
+ if (flag)
+ {
+ netEvent = XNetEventPool._pool.Dequeue();
+ }
+ Monitor.Exit(XNetEventPool._pool);
+ bool flag2 = netEvent != null;
+ NetEvent result;
+ if (flag2)
+ {
+ netEvent.Reset();
+ result = netEvent;
+ }
+ else
+ {
+ result = new NetEvent();
+ }
+ return result;
+ }
+
+ public static void Recycle(NetEvent e)
+ {
+ Monitor.Enter(XNetEventPool._pool);
+ XNetEventPool._pool.Enqueue(e);
+ Monitor.Exit(XNetEventPool._pool);
+ }
+
+ public static void RecycleNoLock(NetEvent e)
+ {
+ XNetEventPool._pool.Enqueue(e);
+ }
+
+ public static void Clear()
+ {
+ Monitor.Enter(XNetEventPool._pool);
+ XNetEventPool._pool.Clear();
+ Monitor.Exit(XNetEventPool._pool);
+ }
+ }
+}
|