Here you can find the source of bitwiseOrAndGet(final AtomicInteger ai, final int toOrValue)
Parameter | Description |
---|---|
ai | the atomic variable to operate on |
toOrValue | the value to do the OR operation |
public static int bitwiseOrAndGet(final AtomicInteger ai, final int toOrValue)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.atomic.AtomicInteger; public class Main { /**//from w w w . j a v a2s . c o m * Atomically do bitwise OR between the value in the AtomicInteger and the toOrValue, and set the new value to the * AtomicInteger and also return the new value. * * @param ai the atomic variable to operate on * @param toOrValue the value to do the OR operation * @return the new value. * */ public static int bitwiseOrAndGet(final AtomicInteger ai, final int toOrValue) { int oldValue = ai.get(); int newValue = oldValue | toOrValue; while (oldValue != newValue && !ai.compareAndSet(oldValue, newValue)) { oldValue = ai.get(); newValue = oldValue | toOrValue; } return newValue; } }