|
StormByte C++ Library: Buffer module 1.2.0
StormByte-Buffer is the buffer module of the StormByte C++ suite.
|
Single-producer single-consumer (SPSC) typed item queue. More...
#include <StormByte/buffer/hopper.hxx>
Public Member Functions | |
Lifecycle | |
| Hopper () noexcept | |
| Constructs an empty unbounded Hopper. | |
| Hopper (std::size_t capacity) noexcept | |
| Constructs an empty Hopper with a capacity ceiling. | |
| Hopper (const Hopper &)=delete | |
| Copy constructor is deleted (Hopper is non-copyable). | |
| Hopper (Hopper &&) noexcept=delete | |
| Move constructor is deleted (Hopper is non-movable). | |
| ~Hopper () noexcept | |
| Destructor. | |
| Hopper & | operator= (const Hopper &)=delete |
| Copy assignment operator is deleted (Hopper is non-copyable). | |
| Hopper & | operator= (Hopper &&) noexcept=delete |
| Move assignment operator is deleted (Hopper is non-movable). | |
Capacity | |
| std::size_t | Capacity () const noexcept |
| Gets the current capacity ceiling. | |
| void | Capacity (std::size_t capacity) noexcept |
| Sets a new capacity ceiling. | |
| std::size_t | Size () const noexcept |
| Gets the number of items currently waiting in the bucket. | |
| bool | Full () const noexcept |
| Checks whether a bounded bucket cannot accept another Push without waiting. | |
Producer | |
| void | Push (T item) noexcept |
| Enqueues one item and signals the consumer if Notify was configured. | |
| Hopper & | operator<< (T item) noexcept |
Write: item flows into this Hopper. | |
| void | Eof () noexcept |
| Marks end of production and wakes waiters. | |
Consumer | |
| T | Pop () noexcept |
| Pops one item from the bucket, or returns default-constructed T if dry. | |
| Hopper & | operator>> (T &item) noexcept |
Pop one unit from this Hopper into item. | |
| bool | EoF () const noexcept |
| Checks whether Eof was called by a producer. | |
| bool | Empty () const noexcept |
| Checks whether the queue has no pending items. | |
Notification | |
| void | Notify (std::condition_variable &wake) noexcept |
| Registers the consumer condition variable to notify on Push or Eof. | |
| void | Unnotify () noexcept |
| Drops the pointer set by Notify. | |
Friends | |
| class | Sink< T > |
| Hopper & | operator>> (T &item, Hopper &hopper) noexcept |
Write: lvalue item flows into hopper. | |
| Hopper & | operator>> (T &&item, Hopper &hopper) noexcept |
Write: rvalue item flows into hopper. | |
Single-producer single-consumer (SPSC) typed item queue.
Hopper is a typed bucket queue for passing items between a single producer and a single consumer. Unlike byte-oriented FIFOs, Hopper operates on discrete typed elements.
Key characteristics:
hopper << item and item >> hopper enqueue; hopper >> item dequeues.| T | Item type stored in the queue (must be MoveConstructible). |
|
noexcept |
Constructs an empty unbounded Hopper.
|
explicitnoexcept |
Constructs an empty Hopper with a capacity ceiling.
| capacity | Maximum number of items allowed (0 = unbounded). |
|
delete |
Copy constructor is deleted (Hopper is non-copyable).
|
deletenoexcept |
Move constructor is deleted (Hopper is non-movable).
|
noexcept |
Destructor.
Wakes any Push blocked on a full bucket.
|
noexcept |
Gets the current capacity ceiling.
|
noexcept |
Sets a new capacity ceiling.
| capacity | Maximum items allowed (0 = unbounded). |
Lowering capacity does not drop queued items; subsequent Push calls wait until Size falls below the new ceiling.
|
noexcept |
Checks whether the queue has no pending items.
|
noexcept |
Checks whether Eof was called by a producer.
|
noexcept |
Marks end of production and wakes waiters.
Does not discard already queued items. After Eof, Push does not enqueue.
|
noexcept |
Checks whether a bounded bucket cannot accept another Push without waiting.
|
noexcept |
Registers the consumer condition variable to notify on Push or Eof.
| wake | Consumer condition variable reference. Not owned. |
The referent must outlive this Hopper, or the owner must call Unnotify before destroying wake. Sink wiring shares the Hopper: a producer Eof after the consumer died is the usual case.
|
noexcept |
Write: item flows into this Hopper.
| item | Unit. Moved. Empty smart pointers are discarded. |
|
delete |
Copy assignment operator is deleted (Hopper is non-copyable).
|
deletenoexcept |
Move assignment operator is deleted (Hopper is non-movable).
|
noexcept |
Pop one unit from this Hopper into item.
| item | Destination. Becomes default T if the bucket is dry. |
|
noexcept |
Pops one item from the bucket, or returns default-constructed T if dry.
Does not block. If empty and EoF is false, the consumer waits on its condition variable. Wakes one producer blocked in Push if space becomes available.
|
noexcept |
Enqueues one item and signals the consumer if Notify was configured.
| item | Item to push. Empty smart pointers are discarded. |
If Capacity > 0 and the bucket is full, waits until space becomes available, Eof is called, or the Hopper is destroyed. After Eof, Push does not enqueue.
|
noexcept |
Gets the number of items currently waiting in the bucket.
|
noexcept |
Drops the pointer set by Notify.
Safe to call more than once or when nothing was registered. After this, Push and Eof do not signal a consumer CV; producers blocked on a full bucket still wake on m_space.
Write: rvalue item flows into hopper.
| item | Unit. Empty smart pointers are discarded. |
| hopper | Destination hopper. |
hopper. Write: lvalue item flows into hopper.
| item | Unit. Moved. Empty smart pointers are discarded. |
| hopper | Destination hopper. |
hopper.Namespace declaration required by GCC next to the friend (GCC will not define a friend-only operator out of line).
|
friend |