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

Last change on this file since 381 was 351, checked in by alloc, 6 years ago

Fixed game version compatibility of GamePrefs
Code style cleanup (mostly argument names)

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