Skip to content

Commit

Permalink
Make inner LockFreePool#Node a static class.
Browse files Browse the repository at this point in the history
  • Loading branch information
axel22 committed Feb 9, 2023
1 parent 55bec5e commit 0877b80
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class LockFreePool<T> {
/**
* The top-of-the-Treiber-stack pointer.
*/
private final AtomicReference<Node> head;
private final AtomicReference<Node<T>> head;

public LockFreePool() {
this.head = new AtomicReference<>();
Expand All @@ -88,11 +88,11 @@ public LockFreePool() {
*/
public T get() {
while (true) {
Node oldHead = head.get();
Node<T> oldHead = head.get();
if (oldHead == null) {
return null;
}
Node newHead = oldHead.tail;
Node<T> newHead = oldHead.tail;
if (head.compareAndSet(oldHead, newHead)) {
return oldHead.element;
}
Expand All @@ -113,8 +113,8 @@ public T get() {
*/
public void add(T element) {
while (true) {
Node oldHead = head.get();
Node newHead = new Node(element, oldHead);
Node<T> oldHead = head.get();
Node<T> newHead = new Node<>(element, oldHead);
if (head.compareAndSet(oldHead, newHead)) {
return;
}
Expand All @@ -124,17 +124,17 @@ public void add(T element) {
/**
* Internal wrapper node used to wrap the element and the {@code tail} pointer.
*/
private final class Node {
private static final class Node<E> {
/**
* Element stored in this node.
*/
final T element;
final E element;
/**
* Pointer to the tail of the linked list, or {@code null} if the end of the list.
*/
final Node tail;
final Node<E> tail;

private Node(T element, Node tail) {
private Node(E element, Node<E> tail) {
this.element = element;
this.tail = tail;
}
Expand Down

0 comments on commit 0877b80

Please sign in to comment.