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

« back to all changes in this revision

Viewing changes to contrib/Sharpen/Sharpen/AtomicReferenceArray.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.Threading;
 
5
 
 
6
        internal class AtomicReferenceArray<T> where T : class
 
7
        {
 
8
                private T[] array;
 
9
 
 
10
                public AtomicReferenceArray (int size)
 
11
                {
 
12
                        this.array = new T[size];
 
13
                }
 
14
 
 
15
                public bool CompareAndSet (int slot, T expect, T update)
 
16
                {
 
17
                        return (Interlocked.CompareExchange<T> (ref array[slot], update, expect) == expect);
 
18
                }
 
19
 
 
20
                public T Get (int n)
 
21
                {
 
22
                        return array[n];
 
23
                }
 
24
                
 
25
                public int Length ()
 
26
                {
 
27
                        return array.Length;
 
28
                }
 
29
        }
 
30
}