From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XNetEventPool.cs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XNetEventPool.cs (limited to 'Client/Assets/Scripts/XMainClient/XNetEventPool.cs') 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 _pool = new Queue(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); + } + } +} -- cgit v1.1-26-g67d0