Java AtomicInteger bitwiseOrAndGet(final AtomicInteger ai, final int toOrValue)

Here you can find the source of bitwiseOrAndGet(final AtomicInteger ai, final int toOrValue)

Description

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.

License

Open Source License

Parameter

Parameter Description
ai the atomic variable to operate on
toOrValue the value to do the OR operation

Return

the new value.

Declaration

public static int bitwiseOrAndGet(final AtomicInteger ai, final int toOrValue) 

Method Source Code


//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;
    }
}

Related

  1. addNodeUse(String nodeInfo)
  2. count()
  3. count(byte[] array, byte value)
  4. countDownToZero(AtomicInteger counter)
  5. countOccurrences(final Collection collection)