Mercurial > hg > Database > jungle-sharp
annotate src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/transaction/AtomicReference.cs @ 7:02b2ab7bffe6
fix
author | Kazuma |
---|---|
date | Tue, 27 Sep 2016 18:36:05 +0900 |
parents | dec15de2c6ff |
children |
rev | line source |
---|---|
0 | 1 using System.Threading; |
2 | |
3 public class AtomicReference <T> where T : class { | |
4 private T value; | |
5 | |
6 public AtomicReference(T value) { | |
7 this.value = value; | |
8 } | |
9 | |
7 | 10 public bool CompareAndSet(T newValue, T prevValue) { |
0 | 11 // change to compere exchange. |
7 | 12 T oldValue = value; |
13 return (oldValue != Interlocked.CompareExchange (ref value, newValue, prevValue)); | |
0 | 14 } |
7 | 15 |
0 | 16 |
17 public T Get() { | |
18 return value; | |
19 } | |
20 } |