A disruptor queue in Varon-T is a high-performance ring buffer with memory barriers and yielding strategies to coordinate producers and consumers of value instances. A distinguishing feature of disruptor queues is that value instances are pre-allocated by the library, usually with size of a power of 2. The result is disruptor queues do little to no memory allocation during execution, and your application requests access from the library to value instances.
A Varon-T distruptor queue is defined by the following interface:
An alphanumeric name for the queue.
The array of values managed by the queue (see value objects for a discussion of custom values.)
A mask that is always equal to |queue| - 1 and used to determine the queue size efficiently through the calculation x % value_count. This works because the actual queue size is always a power of 2.
The type of values managed by the queue (see value objects for a discussion of custom value types.)
Arrays of producers and consumers feeding this queue
The ID of the last guaranteed value instanced processed by each consumer.
The ID of the last value instance claimed by a producer. This is only updated for disruptor queues with multiple produceds. It is expected that single producer disruptor queues will track this value internal to the producer instance.
The next value instance ID that can written into the queue.
We support several built-in operations for queue management.
Construct a new disruptor queue called name that stores value_count objects of type value_type in a ring buffer.
Return the ID of the value instance that was most recently published into the queue. Since this function involves a memory barrier, it should be used sparingly.
Return the number of values managed by the queue.
Return the value instance with the given ID