]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Hazel pretty good. 2020.9.1
authorForest <forest@innersloth.com>
Thu, 3 Sep 2020 22:31:52 +0000 (15:31 -0700)
committerForest <forest@innersloth.com>
Thu, 3 Sep 2020 22:31:52 +0000 (15:31 -0700)
Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs
Hazel/Hazel.csproj
Hazel/ObjectPool.cs

index 87e8fbfd9ab597d1ab04719a41138d36ee94103b..10076d77ff059a7638c6218fa916fa9f4ad52a7e 100644 (file)
@@ -51,12 +51,12 @@ namespace Hazel.Udp.FewerThreads
 
         private ConcurrentDictionary<EndPoint, ThreadLimitedUdpServerConnection> allConnections = new ConcurrentDictionary<EndPoint, ThreadLimitedUdpServerConnection>();
 
-        private Queue<ReceiveMessageInfo> receiveQueue = new Queue<ReceiveMessageInfo>();
+        private BlockingCollection<ReceiveMessageInfo> receiveQueue;
         private Queue<SendMessageInfo> sendQueue = new Queue<SendMessageInfo>();
 
         public int ConnectionCount { get { return this.allConnections.Count; } }
         public int SendQueueLength { get { lock(this.sendQueue) return this.sendQueue.Count; } }
-        public int ReceiveQueueLength { get { lock (this.receiveQueue) return this.receiveQueue.Count; } }
+        public int ReceiveQueueLength { get { return this.receiveQueue.Count; } }
 
         private bool isActive;
 
@@ -66,6 +66,8 @@ namespace Hazel.Udp.FewerThreads
             this.EndPoint = endPoint;
             this.IPMode = ipMode;
 
+            this.receiveQueue = new BlockingCollection<ReceiveMessageInfo>(10000);
+
             this.socket = UdpConnection.CreateSocket(this.IPMode);
             this.socket.Blocking = false;
 
@@ -140,11 +142,7 @@ namespace Hazel.Udp.FewerThreads
                         return;
                     }
 
-                    lock (this.receiveQueue)
-                    {
-                        this.receiveQueue.Enqueue(new ReceiveMessageInfo() { Message = message, Sender = remoteEP });
-                        Monitor.Pulse(this.receiveQueue);
-                    }
+                    this.receiveQueue.Add(new ReceiveMessageInfo() { Message = message, Sender = remoteEP });
                 }
             }
         }
@@ -153,28 +151,15 @@ namespace Hazel.Udp.FewerThreads
         {
             while (this.isActive)
             {
-                ReceiveMessageInfo msg;
-                lock (this.receiveQueue)
-                {
-                    if (this.receiveQueue.Count == 0)
-                    {
-                        Monitor.Wait(this.receiveQueue);
-
-                        if (this.receiveQueue.Count == 0)
-                        {
-                            continue;
-                        }
-                    }
-
-                    msg = this.receiveQueue.Dequeue();
-                }
-
+                ReceiveMessageInfo msg = this.receiveQueue.Take();
+                
                 try
                 {
                     this.ReadCallback(msg.Message, msg.Sender);
                 }
                 catch
                 {
+
                 }
             }
         }
@@ -306,7 +291,8 @@ namespace Hazel.Udp.FewerThreads
             this.isActive = false;
 
             lock (this.sendQueue) Monitor.PulseAll(this.sendQueue);
-            lock (this.receiveQueue) Monitor.PulseAll(this.receiveQueue);
+
+            this.receiveQueue.CompleteAdding();
 
             this.reliablePacketThread.Join();
             this.sendThread.Join();
index f6b10e6b4d382eab36b17ef69289883b4fd56732..6ca0b0a10cbf41a98fe785be9268c591710c6dcd 100644 (file)
@@ -31,7 +31,7 @@
     <DebugType>portable</DebugType>
     <Optimize>true</Optimize>
     <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
+    <DefineConstants>TRACE;HAZEL_BAG</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <DocumentationFile>
index db3e3b467e8b1dc64f8dc51b64350ac0891b177a..510e55a69d1cae16e1832a01ba0edffd2c41958c 100644 (file)
@@ -99,7 +99,9 @@ namespace Hazel
             }
             else
             {
+#if DEBUG
                 throw new Exception("Duplicate add " + typeof(T).Name);
+#endif
             }
         }
     }