Skip to content

Instantly share code, notes, and snippets.

@taichi
Created June 22, 2015 02:31
Show Gist options
  • Save taichi/353b88cf1c369d13b106 to your computer and use it in GitHub Desktop.
Save taichi/353b88cf1c369d13b106 to your computer and use it in GitHub Desktop.
use LongAccumulator instead.
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