summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XNetEventPool.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XNetEventPool.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/XNetEventPool.cs54
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);
+ }
+ }
+}