☎️ rtchan
Realtime-safe channels (lock-free queues) for C++20
Loading...
Searching...
No Matches
rtchan::mpmc< T, N > Class Template Reference

Multiple-producer, multiple-consumer queue. More...

#include <mpmc.hpp>

Inheritance diagram for rtchan::mpmc< T, N >:
rtchan::chan< T >

Public Member Functions

auto try_send (T &&item) noexcept -> bool override
 Tries to send item over the channel, aborting if there is not enough room.
auto try_send (span< const T > &&items) noexcept -> span< const T > override
 Tries to send as many items in items over the channel as will fit.
void send (T &&item) noexcept override
 Sends item over the channel. If the channel is full, this function will block until space is available using a busy-wait loop.
void send (span< const T > &&items) noexcept override
 Sends all items in items over the channel. If the channel cannot fit all of items, this function will block until space is available using a busy-wait loop.
auto try_recv (T &dest) noexcept -> bool override
 Tries to receive an item from the channel, placing it into dest.
auto try_recv (span< T > &dest) noexcept -> span< T > override
 Tries to receive items up to the capacity of dest from the channel into dest.
void recv (T &dest) noexcept override
 Receives an item from the channel into dest. If the channel is empty, this function will block until an item is available using a busy-wait loop.
void recv (span< T > &dest) noexcept override
 Receives items equal to the capacity of dest from the channel into dest. If the channel does not have enough items to fill dest, this function will block until there are enough available items using a busy-wait loop.
auto try_reserve_send (size_t count) noexcept -> span< T > override
 Tries to reserve space for count items in the channel to be manually written into.
auto reserve_send_up_to (size_t count) noexcept -> span< T > override
 Tries to reserve space for up to count items in the channel to be manually written into.
auto reserve_send (size_t count) noexcept -> span< T > override
 Reserves space for count items in the channel to be manually written into. This function may spin until it can return a contiguous span of length count.
auto try_commit_send (span< const T > &reservation) noexcept -> bool override
 Tries to commit the items in reservation, indicating that they are finished being sent and are ready to be received. This function will fail until all previously obtained reservations to reservation have been committed.
void commit_send (span< const T > &reservation) noexcept override
 Commits the items in reservation, indicating that they are finished being sent and are ready to be received. This function may spin until all previously obtained reservations to reservation have been committed.
auto try_reserve_recv (size_t count) noexcept -> span< T > override
 Tries to reserve space for count items in the channel to be manually read from.
auto reserve_recv_up_to (size_t count) noexcept -> span< T > override
 Tries to reserve space for up to count items in the channel to be manually read from.
auto reserve_recv (size_t count) noexcept -> span< T > override
 Reserves space for count items in the channel to be manually read from.
auto try_commit_recv (span< const T > &reservation) noexcept -> bool override
 Tries to release the items in reservation, indicating that they are finished being received and are safe to be overwritten. This function may spin until all previously obtained reservations to reservation have been committed.
void commit_recv (span< const T > &reservation) noexcept override
 Releases the items in reservation, indicating that they are finished being received and are safe to be overwritten. This function may spin until all previously obtained reservations to reservation have been committed.

Detailed Description

template<typename T, size_t N>
requires (0 < N) && (std::has_single_bit(N))
class rtchan::mpmc< T, N >

Multiple-producer, multiple-consumer queue.

Template Parameters
TThe type of item or message the queue holds
NThe capacity of the queue, must be a power of 2

Member Function Documentation

◆ commit_recv()

template<typename T, size_t N>
void rtchan::mpmc< T, N >::commit_recv ( span< const T > & reservation)
inlineoverridevirtualnoexcept

Releases the items in reservation, indicating that they are finished being received and are safe to be overwritten. This function may spin until all previously obtained reservations to reservation have been committed.

Parameters
reservationThe reservation of items to mark as received

Implements rtchan::chan< T >.

◆ commit_send()

template<typename T, size_t N>
void rtchan::mpmc< T, N >::commit_send ( span< const T > & reservation)
inlineoverridevirtualnoexcept

Commits the items in reservation, indicating that they are finished being sent and are ready to be received. This function may spin until all previously obtained reservations to reservation have been committed.

Parameters
reservationThe reservation of items to mark as sent

Implements rtchan::chan< T >.

◆ recv() [1/2]

template<typename T, size_t N>
void rtchan::mpmc< T, N >::recv ( span< T > & dest)
inlineoverridevirtualnoexcept

Receives items equal to the capacity of dest from the channel into dest. If the channel does not have enough items to fill dest, this function will block until there are enough available items using a busy-wait loop.

Parameters
destThe destination to receive the items into

Implements rtchan::chan< T >.

◆ recv() [2/2]

template<typename T, size_t N>
void rtchan::mpmc< T, N >::recv ( T & dest)
inlineoverridevirtualnoexcept

Receives an item from the channel into dest. If the channel is empty, this function will block until an item is available using a busy-wait loop.

Parameters
destThe destination to receive the item into

Implements rtchan::chan< T >.

◆ reserve_recv()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::reserve_recv ( size_t count) -> span< T >
inlineoverridevirtualnoexcept

Reserves space for count items in the channel to be manually read from.

Parameters
countHow many items to try to reserve space for
Returns
A span containing the reserved space

Implements rtchan::chan< T >.

◆ reserve_recv_up_to()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::reserve_recv_up_to ( size_t count) -> span< T >
inlineoverridevirtualnoexcept

Tries to reserve space for up to count items in the channel to be manually read from.

Parameters
countHow many items to try to reserve space for
Returns
A span containing what space was reserved, if any

Implements rtchan::chan< T >.

◆ reserve_send()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::reserve_send ( size_t count) -> span< T >
inlineoverridevirtualnoexcept

Reserves space for count items in the channel to be manually written into. This function may spin until it can return a contiguous span of length count.

Parameters
countHow many items to try to reserve space for
Returns
A span containing the reserved space

Implements rtchan::chan< T >.

◆ reserve_send_up_to()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::reserve_send_up_to ( size_t count) -> span< T >
inlineoverridevirtualnoexcept

Tries to reserve space for up to count items in the channel to be manually written into.

Parameters
countHow many items to try to reserve space for
Returns
A span containing what space was reserved, if any

Implements rtchan::chan< T >.

◆ send() [1/2]

template<typename T, size_t N>
void rtchan::mpmc< T, N >::send ( span< const T > && items)
inlineoverridevirtualnoexcept

Sends all items in items over the channel. If the channel cannot fit all of items, this function will block until space is available using a busy-wait loop.

Parameters
itemsThe items to send

Implements rtchan::chan< T >.

◆ send() [2/2]

template<typename T, size_t N>
void rtchan::mpmc< T, N >::send ( T && item)
inlineoverridevirtualnoexcept

Sends item over the channel. If the channel is full, this function will block until space is available using a busy-wait loop.

Parameters
itemThe item to send

Implements rtchan::chan< T >.

◆ try_commit_recv()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_commit_recv ( span< const T > & reservation) -> bool
inlineoverridevirtualnoexcept

Tries to release the items in reservation, indicating that they are finished being received and are safe to be overwritten. This function may spin until all previously obtained reservations to reservation have been committed.

Parameters
reservationThe reservation of items to mark as received
Returns
Whether or not reservation was able to be committed or not.

Implements rtchan::chan< T >.

◆ try_commit_send()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_commit_send ( span< const T > & reservation) -> bool
inlineoverridevirtualnoexcept

Tries to commit the items in reservation, indicating that they are finished being sent and are ready to be received. This function will fail until all previously obtained reservations to reservation have been committed.

Parameters
reservationThe reservation of items to mark as sent
Returns
Whether or not reservation was able to be committed or not.

Implements rtchan::chan< T >.

◆ try_recv() [1/2]

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_recv ( span< T > & dest) -> span< T >
inlineoverridevirtualnoexcept

Tries to receive items up to the capacity of dest from the channel into dest.

Parameters
destThe destination to receive the items into
Returns
The items succesfully received (a zero-length span indicates no items were received)

Implements rtchan::chan< T >.

◆ try_recv() [2/2]

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_recv ( T & dest) -> bool
inlineoverridevirtualnoexcept

Tries to receive an item from the channel, placing it into dest.

Parameters
destThe destination to receive the item into
Returns
Whether or not there was an item to be received

Implements rtchan::chan< T >.

◆ try_reserve_recv()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_reserve_recv ( size_t count) -> span< T >
inlineoverridevirtualnoexcept

Tries to reserve space for count items in the channel to be manually read from.

Parameters
countHow many items to try to reserve space for
Returns
A span containing what space was reserved, with a zero-length span indicating failure

Implements rtchan::chan< T >.

◆ try_reserve_send()

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_reserve_send ( size_t count) -> span< T >
inlineoverridevirtualnoexcept

Tries to reserve space for count items in the channel to be manually written into.

Parameters
countHow many items to try to reserve space for
Returns
A span containing what space was reserved, with a zero-length span indicating failure

Implements rtchan::chan< T >.

◆ try_send() [1/2]

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_send ( span< const T > && items) -> span< const T >
inlineoverridevirtualnoexcept

Tries to send as many items in items over the channel as will fit.

Parameters
itemsThe items to try to send
Returns
What items were not sent, if any (a zero-length span indicates all items were sent)

Implements rtchan::chan< T >.

◆ try_send() [2/2]

template<typename T, size_t N>
auto rtchan::mpmc< T, N >::try_send ( T && item) -> bool
inlineoverridevirtualnoexcept

Tries to send item over the channel, aborting if there is not enough room.

Parameters
itemThe item to try to send
Returns
Whether or not the item was sent

Implements rtchan::chan< T >.


The documentation for this class was generated from the following file: