source: binary-improvements/7dtd-server-fixes/src/BlockingQueue.cs@ 328

Last change on this file since 328 was 325, checked in by alloc, 6 years ago

Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)

File size: 617 bytes
Line 
1using System.Collections.Generic;
2using System.Threading;
3
4namespace AllocsFixes {
5 public class BlockingQueue<T> {
6 private readonly Queue<T> queue = new Queue<T> ();
7 private bool closing;
8
9 public void Enqueue (T item) {
10 lock (queue) {
11 queue.Enqueue (item);
12 Monitor.PulseAll (queue);
13 }
14 }
15
16 public T Dequeue () {
17 lock (queue) {
18 while (queue.Count == 0) {
19 if (closing) {
20 return default (T);
21 }
22
23 Monitor.Wait (queue);
24 }
25
26 return queue.Dequeue ();
27 }
28 }
29
30 public void Close () {
31 lock (queue) {
32 closing = true;
33 Monitor.PulseAll (queue);
34 }
35 }
36 }
37}
Note: See TracBrowser for help on using the repository browser.