Mercurial > hg > Database > jungle-sharp
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Main/jungle-main/transaction/AtomicReference.cs Thu Dec 15 22:52:48 2016 +0900 @@ -0,0 +1,24 @@ +using System.Threading; + +public class AtomicReference <T> where T : class { + private T value; + + public AtomicReference(T value) { + this.value = value; + } + + public bool CompareAndSet(T newValue, T prevValue) { + T oldValue = value; + if (oldValue == prevValue) { + Interlocked.CompareExchange (ref value, newValue, prevValue); + return true; + } else { + return false; + } + } + + + public T Get() { + return value; + } +}