Created
June 22, 2015 02:31
-
-
Save taichi/353b88cf1c369d13b106 to your computer and use it in GitHub Desktop.
use LongAccumulator instead.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface AtomicFieldUpdaters { | |
static <T> void max(T self, long value, AtomicLongFieldUpdater<T> updater) { | |
long max; | |
do { | |
max = updater.get(self); | |
if (value < max) { | |
break; | |
} | |
} while (updater.compareAndSet(self, max, value) == false); | |
} | |
static <T> void min(T self, long value, AtomicLongFieldUpdater<T> updater) { | |
long min; | |
do { | |
min = updater.get(self); | |
if (min < value && -1 < min) { | |
break; | |
} | |
} while (updater.compareAndSet(self, min, value) == false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment