summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XNetEventPool.cs
blob: 4cac37c81ca58a2294853931446d599b06d1db53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
		}
	}
}