- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/BlockingQueue.cs
r190 r325 1 using System;2 1 using System.Collections.Generic; 3 2 using System.Threading; 4 3 5 namespace AllocsFixes 6 { 7 public class BlockingQueue<T> 8 { 9 private bool closing = false; 10 private Queue<T> queue = new Queue<T> (); 4 namespace AllocsFixes { 5 public class BlockingQueue<T> { 6 private readonly Queue<T> queue = new Queue<T> (); 7 private bool closing; 11 8 12 public void Enqueue (T item) 13 { 9 public void Enqueue (T item) { 14 10 lock (queue) { 15 11 queue.Enqueue (item); … … 18 14 } 19 15 20 public T Dequeue () 21 { 16 public T Dequeue () { 22 17 lock (queue) { 23 18 while (queue.Count == 0) { 24 19 if (closing) { 25 return default (T);20 return default (T); 26 21 } 22 27 23 Monitor.Wait (queue); 28 24 } 25 29 26 return queue.Dequeue (); 30 27 } 31 28 } 32 29 33 public void Close () 34 { 30 public void Close () { 35 31 lock (queue) { 36 32 closing = true; … … 38 34 } 39 35 } 40 41 36 } 42 37 } 43
Note:
See TracChangeset
for help on using the changeset viewer.