Mercurial > hg > Database > jungle-sharp
annotate Main/jungle-main/transaction/AtomicReference.cs @ 20:1f99e150f336
fix folder and add Object Mapper.
author | Kazuma Takeda |
---|---|
date | Thu, 15 Dec 2016 22:52:48 +0900 |
parents | |
children |
rev | line source |
---|---|
20 | 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 | |
10 public bool CompareAndSet(T newValue, T prevValue) { | |
11 T oldValue = value; | |
12 if (oldValue == prevValue) { | |
13 Interlocked.CompareExchange (ref value, newValue, prevValue); | |
14 return true; | |
15 } else { | |
16 return false; | |
17 } | |
18 } | |
19 | |
20 | |
21 public T Get() { | |
22 return value; | |
23 } | |
24 } |