Last change
on this file since 366 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
|
Line | |
---|
1 | using System.Collections.Generic;
|
---|
2 | using System.Threading;
|
---|
3 |
|
---|
4 | namespace 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.