Skip to content

Commit

Permalink
Addressing Nitsan's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 authored and nitsanw committed Feb 14, 2024
1 parent 4b7d2ac commit 173423c
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void organiseImports(CompilationUnit cu) {
cu.addImport(new ImportDeclaration("java.util.concurrent.atomic", false, true));

cu.addImport(new ImportDeclaration("org.jctools.queues", false, true));
cu.addImport(staticImportDeclaration(outputPackage() + ".AtomicQueueUtil"));
cu.addImport(staticImportDeclaration("org.jctools.queues.atomic.AtomicQueueUtil"));
}

protected String capitalise(String s) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jctools.queues.atomic.unpadded;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.ImportDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import org.jctools.queues.atomic.JavaParsingAtomicArrayQueueGenerator;

Expand All @@ -23,6 +24,15 @@ public void cleanupComments(CompilationUnit cu) {
cleanupPaddingComments(cu);
}

@Override
public void organiseImports(CompilationUnit cu) {
super.organiseImports(cu);
cu.addImport(new ImportDeclaration("org.jctools.queues.atomic.AtomicReferenceArrayQueue",
false, false));
cu.addImport(new ImportDeclaration("org.jctools.queues.atomic.SequencedAtomicReferenceArrayQueue",
false, false));
}

@Override
public void visit(ClassOrInterfaceDeclaration node, Void arg) {
super.visit(node, arg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jctools.queues.atomic.unpadded;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.ImportDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import org.jctools.queues.atomic.JavaParsingAtomicLinkedQueueGenerator;

Expand All @@ -23,6 +24,13 @@ public void cleanupComments(CompilationUnit cu) {
cleanupPaddingComments(cu);
}

@Override
public void organiseImports(CompilationUnit cu) {
super.organiseImports(cu);
cu.addImport(new ImportDeclaration("org.jctools.queues.atomic.LinkedQueueAtomicNode",
false, false));
}

@Override
public void visit(ClassOrInterfaceDeclaration node, Void arg) {
super.visit(node, arg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,99 +1,102 @@
package org.jctools.queues.atomic;

import org.jctools.util.InternalAPI;

import java.util.concurrent.atomic.AtomicLongArray;
import java.util.concurrent.atomic.AtomicReferenceArray;

final class AtomicQueueUtil
@InternalAPI
public final class AtomicQueueUtil
{
static <E> E lvRefElement(AtomicReferenceArray<E> buffer, int offset)
public static <E> E lvRefElement(AtomicReferenceArray<E> buffer, int offset)
{
return buffer.get(offset);
}

static <E> E lpRefElement(AtomicReferenceArray<E> buffer, int offset)
public static <E> E lpRefElement(AtomicReferenceArray<E> buffer, int offset)
{
return buffer.get(offset); // no weaker form available
}

static <E> void spRefElement(AtomicReferenceArray<E> buffer, int offset, E value)
public static <E> void spRefElement(AtomicReferenceArray<E> buffer, int offset, E value)
{
buffer.lazySet(offset, value); // no weaker form available
}

static void soRefElement(AtomicReferenceArray buffer, int offset, Object value)
public static void soRefElement(AtomicReferenceArray buffer, int offset, Object value)
{
buffer.lazySet(offset, value);
}

static <E> void svRefElement(AtomicReferenceArray<E> buffer, int offset, E value)
public static <E> void svRefElement(AtomicReferenceArray<E> buffer, int offset, E value)
{
buffer.set(offset, value);
}

static int calcRefElementOffset(long index)
public static int calcRefElementOffset(long index)
{
return (int) index;
}

static int calcCircularRefElementOffset(long index, long mask)
public static int calcCircularRefElementOffset(long index, long mask)
{
return (int) (index & mask);
}

static <E> AtomicReferenceArray<E> allocateRefArray(int capacity)
public static <E> AtomicReferenceArray<E> allocateRefArray(int capacity)
{
return new AtomicReferenceArray<E>(capacity);
}

static void spLongElement(AtomicLongArray buffer, int offset, long e)
public static void spLongElement(AtomicLongArray buffer, int offset, long e)
{
buffer.lazySet(offset, e);
}

static void soLongElement(AtomicLongArray buffer, int offset, long e)
public static void soLongElement(AtomicLongArray buffer, int offset, long e)
{
buffer.lazySet(offset, e);
}

static long lpLongElement(AtomicLongArray buffer, int offset)
public static long lpLongElement(AtomicLongArray buffer, int offset)
{
return buffer.get(offset);
}

static long lvLongElement(AtomicLongArray buffer, int offset)
public static long lvLongElement(AtomicLongArray buffer, int offset)
{
return buffer.get(offset);
}

static int calcLongElementOffset(long index)
public static int calcLongElementOffset(long index)
{
return (int) index;
}

static int calcCircularLongElementOffset(long index, int mask)
public static int calcCircularLongElementOffset(long index, int mask)
{
return (int) (index & mask);
}

static AtomicLongArray allocateLongArray(int capacity)
public static AtomicLongArray allocateLongArray(int capacity)
{
return new AtomicLongArray(capacity);
}

static int length(AtomicReferenceArray<?> buf)
public static int length(AtomicReferenceArray<?> buf)
{
return buf.length();
}

/**
* This method assumes index is actually (index << 1) because lower bit is used for resize hence the >> 1
*/
static int modifiedCalcCircularRefElementOffset(long index, long mask)
public static int modifiedCalcCircularRefElementOffset(long index, long mask)
{
return (int) (index & mask) >> 1;
}

static int nextArrayOffset(AtomicReferenceArray<?> curr)
public static int nextArrayOffset(AtomicReferenceArray<?> curr)
{
return length(curr) - 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jctools.queues.MessagePassingQueue;
import org.jctools.queues.QueueProgressIndicators;
import org.jctools.queues.SupportsIterator;
import org.jctools.util.InternalAPI;
import org.jctools.util.Pow2;

import java.util.AbstractQueue;
Expand All @@ -27,7 +28,8 @@

import static org.jctools.queues.atomic.AtomicQueueUtil.*;

abstract class AtomicReferenceArrayQueue<E> extends AbstractQueue<E> implements IndexedQueue, QueueProgressIndicators, MessagePassingQueue<E>, SupportsIterator
@InternalAPI
public abstract class AtomicReferenceArrayQueue<E> extends AbstractQueue<E> implements IndexedQueue, QueueProgressIndicators, MessagePassingQueue<E>, SupportsIterator
{
protected final AtomicReferenceArray<E> buffer;
protected final int mask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
*/
package org.jctools.queues.atomic;

import org.jctools.util.InternalAPI;

import java.util.concurrent.atomic.AtomicReference;

@InternalAPI
public final class LinkedQueueAtomicNode<E> extends AtomicReference<LinkedQueueAtomicNode<E>>
{
/** */
private static final long serialVersionUID = 2404266111789071508L;
private E value;

LinkedQueueAtomicNode()
public LinkedQueueAtomicNode()
{
}

LinkedQueueAtomicNode(E val)
public LinkedQueueAtomicNode(E val)
{
spValue(val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
*/
package org.jctools.queues.atomic;

import org.jctools.util.InternalAPI;

import java.util.concurrent.atomic.AtomicLongArray;

abstract class SequencedAtomicReferenceArrayQueue<E> extends
@InternalAPI
public abstract class SequencedAtomicReferenceArrayQueue<E> extends
AtomicReferenceArrayQueue<E>
{
protected final AtomicLongArray sequenceBuffer;
Expand Down

This file was deleted.

Loading

0 comments on commit 173423c

Please sign in to comment.