~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Sharpen/Sharpen/ReferenceQueue.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace Sharpen
 
2
{
 
3
        using System;
 
4
        using System.Collections.Generic;
 
5
 
 
6
        internal class ReferenceQueue<T>
 
7
        {
 
8
                private Queue<Reference<T>> queue;
 
9
 
 
10
                public ReferenceQueue ()
 
11
                {
 
12
                        this.queue = new Queue<Reference<T>> ();
 
13
                }
 
14
 
 
15
                internal bool Add (Reference<T> t)
 
16
                {
 
17
                        Queue<Reference<T>> queue = this.queue;
 
18
                        lock (queue) {
 
19
                                if (this.queue.Contains (t)) {
 
20
                                        return false;
 
21
                                }
 
22
                                this.queue.Enqueue (t);
 
23
                                return true;
 
24
                        }
 
25
                }
 
26
 
 
27
                public Reference<T> Poll ()
 
28
                {
 
29
                        Queue<Reference<T>> queue = this.queue;
 
30
                        lock (queue) {
 
31
                                if (this.queue.Count > 0) {
 
32
                                        return this.queue.Dequeue ();
 
33
                                }
 
34
                                return null;
 
35
                        }
 
36
                }
 
37
        }
 
38
}