19#ifndef MTCORE_THREAD_BROADCAST_HPP
20#define MTCORE_THREAD_BROADCAST_HPP
50 if (
auto inboxRes =
inbox.init(alloc); inboxRes.is_error()) {
51 return inboxRes.error();
53 return inbox->init(alloc);
57 ensure(
inbox.valid(),
"SUBSCRIPTION IS NOT INITIALIZED!");
58 return inbox->receive_block();
115 return channels.init(alloc, initCapacity);
126 auto l = std::unique_lock{
mux};
134 while (
iter.next().copy_if_present(handle)) {
136 if (e.inbox.valid()) {
137 if (
auto res = e.inbox->send_block(alloc, msg); res.is_error()) {
141 if (
auto res2 = e.inbox->send_block(msg); res2.is_error()) {
142 e.inbox.release(alloc);
148 e.inbox.release(alloc);
170 if (
auto subRes = sub.
init(alloc); subRes.is_error()) {
176 auto l = std::unique_lock{
mux};
182 if (
auto addRes =
channels.add(alloc, sub); addRes.is_error()) {
187 auto acquireRes = sub.
inbox.acquire(alloc);
188 if (acquireRes.is_error()) {
202 auto l = std::unique_lock{
mux};
206 while (
iter.next().copy_if_present(cur)) {
207 if (cur.
inbox.valid()) {
220 auto l = std::unique_lock{
mux};
224 while (
iter.next().copy_if_present(cur)) {
BroadcastSubscribeError
Errors when getting a broadcast subscription.
#define ensure(check,...)
Ensures that a check holds true, aborts the program if not true Will print error if the condition is ...
Success< void > success()
Creates a successful void Result object.
Error< Underlying > error(Underlying err)
Creates an error.
Generic iterator defaults built on common contracts Does not guarantee performance of iterators Actua...
Thread-related namespace The methods and classes provided by this class are thread-safe Classes and m...
Represents a memory allocator Exact behavior depends on the underlying VTable used Should use the a_*...
Represents a generational list where removed items are marked and recycled.
Handle to an item in the list.
Represents a value that may or may not exist (an "Optional" value) Similar concept to std::optional,...
Represents a Result that may have an error (error code) or a success value A type of "void" means the...
A subscription to a broadcaster.
Result< void, AllocationError > init(Allocator &alloc)
Optional< T > receive_block()
void deinit(Allocator &alloc)
A broadcaster is able to send messages to multiple channels, with each channel having its own lock Se...
Result< BroadcastSubscription< T >, BroadcastSubscribeError > subscribe(Allocator &alloc)
Subscribes to a broadcaster Will create a new inbox for the subscription.
Result< void, ChannelSendBlockErrors > send_block(Allocator &alloc, const T &msg)
Blocks while sending data.
void deinit(Allocator &alloc)
Will close the broadcaster and will also clean up the broadcaster's references to each subscription (...
GenList< BroadcastSubscription< T > > channels
Result< void, AllocationError > init(Allocator &alloc, size_t initCapacity=64)
Initializes a broadcaster.
void close()
Closes the broadcaster which prevents messages from being sent (which aren't already being sent) and ...