Disruptor 问题请教

13-08-20 bingyang

bang ,你好:

我在移植Disruptor到.net版本的是遇到个问题,如果你看到这个帖子望指教下哦,谢谢。

问题描述:

类,MultiProducerSequencer 代码片段如下:

/**
     * @see Sequencer#next(int)
     */
    @Override
    public long next(int n)
    {
        if (n < 1)
        {
            throw new IllegalArgumentException("n must be > 0");
        }

        long current;
        long next;

        do
        {
            current = cursor.get();
            next = current + n;

            long wrapPoint = next - bufferSize;
            long cachedGatingSequence = gatingSequenceCache.get();

            if (wrapPoint > cachedGatingSequence || cachedGatingSequence > current)
            {
                long gatingSequence = Util.getMinimumSequence([b]gatingSequences[/b], current);               
                if (wrapPoint > gatingSequence)
                {
                    LockSupport.parkNanos(1); // TODO, should we spin based on the wait strategy?
                    continue;
                }

                gatingSequenceCache.set(gatingSequence);
            }
            else if (cursor.compareAndSet(current, next))
            {
                break;
            }
        }
        while (true);

        return next;
    }
<p>

这个方法执行完后gatingSequences 的值都变为next 变量的值,但源代码中并没有显示设置gatingSequences 的值,请问是如何改变gatingSequences 的值的呢?

gong1
2013-08-20 12:00

gatingSequenceCache.set(gatingSequence);这不是设置了么?

bingyang
2013-08-20 14:28

2013-08-20 12:00 "@gong1

"的内容

gatingSequenceCache.set(gatingSequence);这不是设置了么? ...

不是同一个变量哦 gatingSequence 是个long型临时变量,gatingSequences是个 Sequence[] 型数组

bingyang
2013-08-24 18:40

已搞定