aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/Manager/OpenGridServices.Manager/BlockingQueue.cs
blob: be47385fc59901de214ea4596b85fa86686a65d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Threading;
using System.Collections.Generic;
using System.Text;

namespace OpenGridServices.Manager
{
    public class BlockingQueue<T>
    {
        private Queue<T> _queue = new Queue<T>();
        private object _queueSync = new object();

        public void Enqueue(T value)
        {
            lock (_queueSync)
            {
                _queue.Enqueue(value);
                Monitor.Pulse(_queueSync);
            }
        }

        public T Dequeue()
        {
            lock (_queueSync)
            {
                if (_queue.Count < 1)
                    Monitor.Wait(_queueSync);

                return _queue.Dequeue();
            }
        }
    }
}