Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Atomically increments by one the current value.
- *
- * @return the updated value
- */
- public final long incrementAndGet() {
- for (;;) {
- long current = get();
- long next = current + 1;
- if (compareAndSet(current, next))
- return next;
- }
- }
- /**
- * Atomically sets the value to the given updated value
- * if the current value {@code ==} the expected value.
- *
- * @param expect the expected value
- * @param update the new value
- * @return true if successful. False return indicates that
- * the actual value was not equal to the expected value.
- */
- public final boolean compareAndSet(long expect, long update) {
- return unsafe.compareAndSwapLong(this, valueOffset, expect, update);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement