Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpscLinkedQueue#fill#soNext(temp) may be replaced with spNext(next) #293

Open
hl845740757 opened this issue May 16, 2020 · 4 comments
Open

Comments

@hl845740757
Copy link
Contributor

Just like an object factory, the oldPNode.soNext(head) can ensure correct construction.

   @Override
    public int fill(Supplier<E> s, int limit)
    {
        if (null == s)
            throw new IllegalArgumentException("supplier is null");
        if (limit < 0)
            throw new IllegalArgumentException("limit is negative:" + limit);
        if (limit == 0)
            return 0;

        LinkedQueueNode<E> tail = newNode(s.get());
        final LinkedQueueNode<E> head = tail;
        for (int i = 1; i < limit; i++)
        {
            final LinkedQueueNode<E> temp = newNode(s.get());
            // The fence here may be redundant
            tail.soNext(temp);
            tail = temp;
        }

        final LinkedQueueNode<E> oldPNode = lpProducerNode();
        oldPNode.soNext(head);
        spProducerNode(tail);
        return limit;
    }
@hl845740757
Copy link
Contributor Author

MpscLinkedQueue#fill

    @Override
    public int fill(Supplier<E> s, int limit)
    {
        if (null == s)
            throw new IllegalArgumentException("supplier is null");
        if (limit < 0)
            throw new IllegalArgumentException("limit is negative:" + limit);
        if (limit == 0)
            return 0;

        LinkedQueueNode<E> tail = newNode(s.get());
        final LinkedQueueNode<E> head = tail;
        for (int i = 1; i < limit; i++)
        {
            final LinkedQueueNode<E> temp = newNode(s.get());
            // The fence here may be redundant
            tail.soNext(temp);
            tail = temp;
        }

        final LinkedQueueNode<E> oldPNode = xchgProducerNode(tail);
        oldPNode.soNext(head);
        return limit;
    }

@nitsanw
Copy link
Contributor

nitsanw commented May 21, 2020

The redundant fences are potentially costly on ARM processors. PR is welcome :-)

nitsanw added a commit that referenced this issue May 22, 2020
Partial fix to #293, needs more tests added
@hl845740757
Copy link
Contributor Author

#299 pull request

@hl845740757
Copy link
Contributor Author

hl845740757 commented May 28, 2020

#307 pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants