Rev | Line | |
---|
[182] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Threading;
|
---|
| 4 |
|
---|
| 5 | namespace AllocsFixes
|
---|
| 6 | {
|
---|
| 7 | public class BlockingQueue<T>
|
---|
| 8 | {
|
---|
| 9 | private Queue<T> queue = new Queue<T> ();
|
---|
| 10 |
|
---|
| 11 | public void Enqueue (T item)
|
---|
| 12 | {
|
---|
| 13 | lock (queue) {
|
---|
| 14 | queue.Enqueue (item);
|
---|
| 15 | Monitor.PulseAll (queue);
|
---|
| 16 | }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public T Dequeue ()
|
---|
| 20 | {
|
---|
| 21 | lock (queue) {
|
---|
| 22 | while (queue.Count == 0) {
|
---|
| 23 | Monitor.Wait (queue);
|
---|
| 24 | }
|
---|
| 25 | return queue.Dequeue ();
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.