A multi-producer, multi-consumer bounded queue implemented as a ring buffer.
Types
Consumer[N; P; C; T] = object idx*: int ## The consumer's unique identifier. queue*: ptr Mupmuc[N, P, C, T] ## A reference to the consumer's queue.
- A per-thread interface for popping items from a queue. Retrieved via a call to Mupmuc.getConsumer() Source Edit
Mupmuc[N; P; C; T] = object of Mupsic[N, P, T] prevConsumerIdx*: Atomic[int] ## The ID (index) of the most recent consumer consumerHeads*: array[C, Atomic[int]] ## Array of consumer heads consumerThreadIds*: array[C, Atomic[int]] ## \ ## Array of consumer thread IDs by index
-
A multi-producer, multi-consumer bounded queue implemented as a ring buffer.
- N is the capacity of the queue.
- P is the number of producer threads.
- C is the number of consumer threads.
- T is the type of data the queue will hold.
NoConsumersAvailableError = object of CatchableError
- Raised by getConsumer() if all consumers have been assigned to other threads. Source Edit
Consts
NoConsumerIdx = -1
- The initial value of Mupmuc.prevConsumerIdx. Source Edit
Procs
proc consumerCount[N, P, C: static int; T](self: var Mupmuc[N, P, C, T]): int {. inline.}
- Returns the queue's number of consumers (C). Source Edit
proc getConsumer[N, P, C: static int; T](self: var Mupmuc[N, P, C, T]; idx: int = NoConsumerIdx): Consumer[N, P, C, T] {. ...raises: [NoConsumersAvailableError].}
- Assigns and returns a Consumer instance for the current thread. Source Edit
proc initMupmuc[N, P, C: static int; T](): Mupmuc[N, P, C, T]
- Initialize a new Mupmuc queue. Source Edit
proc pop[N, P, C: static int; T](self: Consumer[N, P, C, T]): Option[T]
- Pop a single item from the queue. If the queue is empty, none(T) is returned. Otherwise an item is popped, some(T) is returned. Source Edit
proc pop[N, P, C: static int; T](self: Consumer[N, P, C, T]; count: int): Option[ seq[T]]
- Pop count items from the queue. If the queue is empty, none(seq[T]) is returned. Otherwise some(seq[T]) is returned containing at least one item. Source Edit