Class Leap::ProduceConsumeBuffer

class Leap.ProduceConsumeBuffer<T>

Public Functions

ProduceConsumeBuffer (int minCapacity)

Constructs a new produce consumer buffer of at least a certain capacity. Once the buffer is created, the capacity cannot be modified.

If the minimum capacity is a power of two, it will be used as the actual capacity. If the minimum capacity is not a power of two, the next highest power of two will be used as the capacity. This behavior is an optimization, Internally this class uses a bitwise AND operation instead of a slower modulus operation for indexing, which only is possible if the array length is a power of two.

bool TryEnqueue (ref T t)

Tries to enqueue a value into the buffer. If the buffer is already full, this method will perform no action and return false. This method is only safe to be called from a single producer thread.

bool TryEnqueue (T t)

Tries to enqueue a value into the buffer. If the buffer is already full, this method will perform no action and return false. This method is only safe to be called from a single producer thread.

bool TryPeek (out T t)

Tries to get the next element that would be dequeued from this buffer. If there is no element yet, this method will return false. If there is an element ready to be dequeued, it will be copied to the out param and this method will return true.

This method is only safe to be called from a single consumer thread.

bool TryDequeue (out T t)

Tries to dequeue a value off of the buffer. If the buffer is empty this method will perform no action and return false. This method is only safe to be called from a single consumer thread.

bool TryDequeue ()

Tries to dequeue a value off of the buffer. If the buffer is empty this method will perform no action and return false. This method is only safe to be called from a single consumer thread.

bool TryDequeueAll (out T mostRecent)

Tries to dequeue all values off of the buffer, returning the most recently added element. If there was an element found, this method will return true, else it will return false.

Properties

int Capacity { get; set; }

Returns the maximum number of elements that the buffer can hold.

int Count { get; set; }

Returns the current number of elements that are held inside the buffer.