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

Last change on this file since 206 was 190, checked in by alloc, 10 years ago

fixes

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