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

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

fixes

File size: 637 bytes
RevLine 
[182]1using System;
2using System.Collections.Generic;
3using System.Threading;
4
5namespace AllocsFixes
6{
7 public class BlockingQueue<T>
8 {
[190]9 private bool closing = false;
[182]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) {
[190]24 if (closing) {
25 return default(T);
26 }
[182]27 Monitor.Wait (queue);
28 }
29 return queue.Dequeue ();
30 }
31 }
32
[190]33 public void Close ()
34 {
35 lock (queue) {
36 closing = true;
37 Monitor.PulseAll (queue);
38 }
39 }
[182]40
41 }
42}
43
Note: See TracBrowser for help on using the repository browser.