java.util.concurrent.atomic.AtomicLongArray#lazySet()源码实例Demo

下面列出了java.util.concurrent.atomic.AtomicLongArray#lazySet() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: akarnokd-misc   文件: SpscLongArrayQueue.java
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;
}
 
源代码2 项目: akarnokd-misc   文件: SpscLongArrayQueue.java
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;
}
 
源代码3 项目: akarnokd-misc   文件: SpscLongArrayQueue.java
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;
}
 
源代码4 项目: openjdk-jdk9   文件: AtomicLongArrayTest.java
/**
 * 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));
    }
}
 
源代码5 项目: hollow   文件: ByteArrayOrdinalMap.java
/**
 * 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;
}
 
源代码6 项目: j2objc   文件: AtomicLongArrayTest.java
/**
 * 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));
    }
}
 
源代码7 项目: JCTools   文件: AtomicQueueUtil.java
static void spLongElement(AtomicLongArray buffer, int offset, long e)
{
    buffer.lazySet(offset, e);
}
 
源代码8 项目: JCTools   文件: AtomicQueueUtil.java
static void soLongElement(AtomicLongArray buffer, int offset, long e)
{
    buffer.lazySet(offset, e);
}
 
protected final void soSequence(AtomicLongArray buffer, int offset, long e)
{
    buffer.lazySet(offset, e);
}
 
源代码10 项目: JCTools   文件: MpscRelaxedAtomicArrayQueue.java
protected static void soValue(AtomicLongArray elements, int index, long value)
{
    elements.lazySet(calcValueOffset(index), value);
}