本文整理汇总了C#中RingBuffer.Next方法的典型用法代码示例。如果您正苦于以下问题:C# RingBuffer.Next方法的具体用法?C# RingBuffer.Next怎么用?C# RingBuffer.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RingBuffer
的用法示例。
在下文中一共展示了RingBuffer.Next方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValuePublisher
private static void ValuePublisher(CountdownEvent countdownEvent, RingBuffer<ValueEvent> ringBuffer, long iterations)
{
countdownEvent.Signal();
countdownEvent.Wait();
for (long i = 0; i < iterations; i++)
{
var sequence = ringBuffer.Next();
var eventData = ringBuffer[sequence];
eventData.Value = i;
ringBuffer.Publish(sequence);
}
}
示例2: ValuePublisher
private static void ValuePublisher(CountdownEvent countdownEvent, RingBuffer<long[]> ringBuffer, long iterations, long arraySize)
{
countdownEvent.Signal();
countdownEvent.Wait();
for (long i = 0; i < iterations; i++)
{
var sequence = ringBuffer.Next();
var eventData = ringBuffer[sequence];
for (var j = 0; j < arraySize; j++)
{
eventData[j] = i + j;
}
ringBuffer.Publish(sequence);
}
}
示例3: ShouldPreventProducersOvertakingEventProcessorsWrapPoint
public void ShouldPreventProducersOvertakingEventProcessorsWrapPoint()
{
const int ringBufferSize = 4;
var mre = new ManualResetEvent(false);
var producerComplete = false;
var ringBuffer = new RingBuffer<StubEvent>(() => new StubEvent(-1), ringBufferSize);
var processor = new TestEventProcessor(ringBuffer.NewBarrier());
ringBuffer.SetGatingSequences(processor.Sequence);
var thread = new Thread(
() =>
{
for (int i = 0; i <= ringBufferSize; i++) // produce 5 events
{
var sequence = ringBuffer.Next();
StubEvent evt = ringBuffer[sequence];
evt.Value = i;
ringBuffer.Publish(sequence);
if (i == 3) // unblock main thread after 4th event published
{
mre.Set();
}
}
producerComplete = true;
});
thread.Start();
mre.WaitOne();
Assert.AreEqual(ringBufferSize - 1, ringBuffer.Cursor);
Assert.IsFalse(producerComplete);
processor.Run();
thread.Join();
Assert.IsTrue(producerComplete);
}