MT Core (C++)
Core library for replacing C++ standard in project usage
|
Channel is a message-passing primitive between two threads A channel has blocking and non-blocking (or auto timed out for a size of 0) methods Timeout methods are also present A channel will have a buffer size for how many messages can be queued up If there is a buffer size of 0, then a reader and writer must both be accessing the channel simultaneously for messages to be transmitted. More...
#include <channels.hpp>
Public Types | |
using | Message = T |
Public Member Functions | |
void | close () |
Closes the channel. | |
Result< void, ChannelTrySendErrors > | try_send (const T &msg) |
Tries to send a message Does not block If there is no room or would have to block for locking, will fail If the channel is closed, will fail. | |
Result< void, ChannelSendBlockErrors > | send_block (const T &msg) |
Will send a message (unless the channel is closed, then will fail) Will block as long as is needed to send a message. | |
template<typename Clock = std::chrono::steady_clock> | |
Result< void, ChannelSendBeforeErrors > | send_before (const T &msg, const std::chrono::time_point< Clock > &when) |
Will send a message (unless the channel is closed, will fail) Will block up to a certain time point, then will fail if unable to send before that time point. | |
Result< Optional< T >, ChannelTryReceiveErrors > | try_receive () |
Tries to receive a message Will fail if it would have to block If the channel is empty and closed, will return nullopt instead of a message. | |
Optional< Message > | receive_block () |
Receives a message from the channel Blocks indefinitely. | |
template<typename Clock> | |
Result< Optional< T >, ChannelReceiveBeforeErrors > | receive_before (const std::chrono::time_point< Clock > &when) |
Receives a message before a time point Blocks until a time point. | |
Channel is a message-passing primitive between two threads A channel has blocking and non-blocking (or auto timed out for a size of 0) methods Timeout methods are also present A channel will have a buffer size for how many messages can be queued up If there is a buffer size of 0, then a reader and writer must both be accessing the channel simultaneously for messages to be transmitted.
Guaranteed to implement the ChannelLike trait
Locks:
Condition Variables:
Non-Blocking Availability:
Definition at line 117 of file channels.hpp.
using mtcore::thread::Channel< T, Size >::Message = T |
Definition at line 128 of file channels.hpp.
|
inline |
Closes the channel.
Definition at line 133 of file channels.hpp.
|
inlinenodiscard |
Receives a message before a time point Blocks until a time point.
If does not receive before then, will fail
Clock | Clock type for the time point |
when | When should it timeout |
Definition at line 265 of file channels.hpp.
|
inlinenodiscard |
Receives a message from the channel Blocks indefinitely.
Definition at line 244 of file channels.hpp.
|
inlinenodiscard |
Will send a message (unless the channel is closed, will fail) Will block up to a certain time point, then will fail if unable to send before that time point.
Clock | Clock for tracking time with |
msg | Message to send |
when | When should there be a timeout |
Definition at line 192 of file channels.hpp.
|
inlinenodiscard |
Will send a message (unless the channel is closed, then will fail) Will block as long as is needed to send a message.
msg | Message to send |
Definition at line 172 of file channels.hpp.
|
inlinenodiscard |
Tries to receive a message Will fail if it would have to block If the channel is empty and closed, will return nullopt instead of a message.
Definition at line 221 of file channels.hpp.
|
inlinenodiscard |
Tries to send a message Does not block If there is no room or would have to block for locking, will fail If the channel is closed, will fail.
msg | Message to send |
Definition at line 148 of file channels.hpp.