Java Code Examples for java.util.concurrent.atomic.AtomicLongArray#lazySet()

The following examples show how to use java.util.concurrent.atomic.AtomicLongArray#lazySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpscLongArrayQueue.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
public boolean offer(long value) {
    final AtomicLongArray a = buffer;
    final int m = mask;
    final long pi = a.get(0);

    int offset = calcOffset(pi, m);
    int offset1 = offset + 1;

    if (a.get(offset1) != 0L) {
        return false;
    }

    a.lazySet(offset, value);
    a.lazySet(offset1, 1L);
    a.lazySet(0, pi + 2);
    return true;
}
 
Example 2
Source File: SpscLongArrayQueue.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
public long poll(boolean[] hasValue) {
    final AtomicLongArray a = buffer;
    final int m = mask;
    final long ci = a.get(1);

    int offset = calcOffset(ci, m);
    int offset1 = offset + 1;

    long v = a.get(offset1);
    if (v == 0L) {
        hasValue[0] = false;
        return 0L;
    }
    hasValue[0] = true;
    v = a.get(offset);
    a.lazySet(offset1, 0L);
    a.lazySet(1, ci + 2);

    return v;
}
 
Example 3
Source File: SpscLongArrayQueue.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
public long poll() {
    final AtomicLongArray a = buffer;
    final int m = mask;
    final long ci = a.get(1);

    int offset = calcOffset(ci, m);

    long v = a.get(offset + 1);
    if (v == 0L) {
        return 0L;
    }
    v = a.get(offset);
    a.lazySet(offset + 1, 0L);
    a.lazySet(1, ci + 2);
    return v;
}
 
Example 4
Source File: AtomicLongArrayTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * get returns the last value lazySet at index by same thread
 */
public void testGetLazySet() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.lazySet(i, 1);
        assertEquals(1, aa.get(i));
        aa.lazySet(i, 2);
        assertEquals(2, aa.get(i));
        aa.lazySet(i, -3);
        assertEquals(-3, aa.get(i));
    }
}
 
Example 5
Source File: ByteArrayOrdinalMap.java    From hollow with Apache License 2.0 5 votes vote down vote up
/**
 * Create an AtomicLongArray of the specified size, each value in the array will be EMPTY_BUCKET_VALUE
 */
private AtomicLongArray emptyKeyArray(int size) {
    AtomicLongArray arr = new AtomicLongArray(size);
    // Volatile store not required, could use plain store
    // See VarHandles for JDK >= 9
    for (int i = 0; i < arr.length(); i++) {
        arr.lazySet(i, EMPTY_BUCKET_VALUE);
    }
    return arr;
}
 
Example 6
Source File: AtomicLongArrayTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * get returns the last value lazySet at index by same thread
 */
public void testGetLazySet() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.lazySet(i, 1);
        assertEquals(1, aa.get(i));
        aa.lazySet(i, 2);
        assertEquals(2, aa.get(i));
        aa.lazySet(i, -3);
        assertEquals(-3, aa.get(i));
    }
}
 
Example 7
Source File: AtomicQueueUtil.java    From JCTools with Apache License 2.0 4 votes vote down vote up
static void spLongElement(AtomicLongArray buffer, int offset, long e)
{
    buffer.lazySet(offset, e);
}
 
Example 8
Source File: AtomicQueueUtil.java    From JCTools with Apache License 2.0 4 votes vote down vote up
static void soLongElement(AtomicLongArray buffer, int offset, long e)
{
    buffer.lazySet(offset, e);
}
 
Example 9
Source File: SequencedAtomicReferenceArrayQueue.java    From JCTools with Apache License 2.0 4 votes vote down vote up
protected final void soSequence(AtomicLongArray buffer, int offset, long e)
{
    buffer.lazySet(offset, e);
}
 
Example 10
Source File: MpscRelaxedAtomicArrayQueue.java    From JCTools with Apache License 2.0 4 votes vote down vote up
protected static void soValue(AtomicLongArray elements, int index, long value)
{
    elements.lazySet(calcValueOffset(index), value);
}