public long WaitFor(IConsumer[] consumers, IRingBuffer <T> ringBuffer, IConsumerBarrier <T> barrier, long sequence) { long availableSequence; if (0 == consumers.Length) { while ((availableSequence = ringBuffer.Cursor) < sequence) { if (barrier.IsAlerted()) { throw AlertException.ALERT_EXCEPTION; } } } else { while ((availableSequence = Util.GetMinimumSequence(consumers)) < sequence) { if (barrier.IsAlerted()) { throw AlertException.ALERT_EXCEPTION; } } } return(availableSequence); }
public long WaitFor(IConsumer[] consumers, IRingBuffer <T> ringBuffer, IConsumerBarrier <T> barrier, long sequence, long timeout) { long availableSequence; if ((availableSequence = ringBuffer.Cursor) < sequence) { lock (_lock) { try { while ((availableSequence = ringBuffer.Cursor) < sequence) { if (barrier.IsAlerted()) { throw AlertException.ALERT_EXCEPTION; } if (!_waithandle.WaitOne((int)timeout)) { break; } } } catch { } } } if (0 != consumers.Length) { while ((availableSequence = Util.GetMinimumSequence(consumers)) < sequence) { if (barrier.IsAlerted()) { throw AlertException.ALERT_EXCEPTION; } } } return(availableSequence); }
public long WaitFor(IConsumer[] consumers, IRingBuffer <T> ringBuffer, IConsumerBarrier <T> barrier, long sequence, long timeout) { long currentTime = _timer.ElapsedMilliseconds; long cutoff = currentTime + timeout; long availableSequence; if (0 == consumers.Length) { while ((availableSequence = ringBuffer.Cursor) < sequence) { if (barrier.IsAlerted()) { throw AlertException.ALERT_EXCEPTION; } ThreadYield(); if (_timer.ElapsedMilliseconds > cutoff) { break; } } } else { while ((availableSequence = Util.GetMinimumSequence(consumers)) < sequence) { if (barrier.IsAlerted()) { throw AlertException.ALERT_EXCEPTION; } ThreadYield(); if (_timer.ElapsedMilliseconds > cutoff) { break; } } } return(availableSequence); }