microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
microfmt::log::fanout_log_sink< MaxSinks, Channel > Class Template Reference

Fixed-capacity sink that forwards each record to up to MaxSinks advanced sinks ("pins"), applies back-pressure when one is full, and keeps thread-context writers in FIFO order. Nothing here busy-waits. More...

#include <extended_sink.hpp>

Public Types

using tag = fanout_log_sink_tag< MaxSinks, Channel >
 

Public Member Functions

 fanout_log_sink () noexcept=default
 
 fanout_log_sink (const fanout_log_sink &)=delete
 
fanout_log_sink & operator= (const fanout_log_sink &)=delete
 
bool add_sink (extended_log_sink s) noexcept
 Appends s; returns false when the table is full. Thread context only. Safe against concurrent writers of both classes.
 
void set_wait_timeout_us (std::uint64_t us) noexcept
 Longest a turn holder sleeps for space, per record.
 
extended_log_sink as_sink (level lvl=level::trace) &noexcept RELOCO_LIFETIMEBOUND
 Handle for use as a sink (e.g. by extended_logger).
 
void notify_space () noexcept
 Reader side: tells waiting writers that space may have been freed. Thread context.
 
space_notifier notifier () &noexcept RELOCO_LIFETIMEBOUND
 notify_space as a callback for a pin's consumer.
 
std::size_t dropped () const noexcept
 Thread records discarded because a pin stayed full for the whole wait.
 
void log_impl (const extended_log_msg &msg) noexcept
 
bool full_impl (const extended_log_msg &msg) noexcept
 
void flush_impl () noexcept
 

Detailed Description

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
class microfmt::log::fanout_log_sink< MaxSinks, Channel >

Fixed-capacity sink that forwards each record to up to MaxSinks advanced sinks ("pins"), applies back-pressure when one is full, and keeps thread-context writers in FIFO order. Nothing here busy-waits.

Two classes of writer:

Readers take only their pin's own lock; afterwards they call notify_space (thread context: it takes the channel lock) to wake the writers. Lock order: channel lock, then pin lock. Call notify_space after releasing the pin lock.

Pins must make log safe against concurrent priority writers (their own short lock). A priority writer may refill a pin after the turn holder saw space; the pin then drops that thread record (its can_wait is set).

// Two pins; thread writers sleep on a condition variable, FIFO.
fan.add_sink(uart_ring_sink); // advanced sinks, bound to their own contexts
fan.add_sink(flash_ring_sink);
fan.set_wait_timeout_us(5000); // a thread waits up to 5 ms for space, per record
// Consumer thread: drain one pin (under that pin's own lock), then:
fan.notify_space(); // or hand fan.notifier() to the pin's reader
Logger for advanced sinks. Derives from basic_logger, so the whole formatting/level/locking API is in...
Definition extended_logger.hpp:70
Fixed-capacity sink that forwards each record to up to MaxSinks advanced sinks ("pins"),...
Definition extended_sink.hpp:210
extended_log_sink as_sink(level lvl=level::trace) &noexcept RELOCO_LIFETIMEBOUND
Handle for use as a sink (e.g. by extended_logger).
Definition extended_sink.hpp:247
bool add_sink(extended_log_sink s) noexcept
Appends s; returns false when the table is full. Thread context only. Safe against concurrent writers...
Definition extended_sink.hpp:232
void notify_space() noexcept
Reader side: tells waiting writers that space may have been freed. Thread context.
Definition extended_sink.hpp:252
void set_wait_timeout_us(std::uint64_t us) noexcept
Longest a turn holder sleeps for space, per record.
Definition extended_sink.hpp:244
basic_logger< 4, 256 > logger
Definition logger.hpp:242
Template Parameters
MaxSinksCapacity of the sink table.
ChannelOuter lock + sleep/wake primitive, see sync.hpp.

Member Typedef Documentation

◆ tag

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
using microfmt::log::fanout_log_sink< MaxSinks, Channel >::tag = fanout_log_sink_tag<MaxSinks, Channel>

Constructor & Destructor Documentation

◆ fanout_log_sink() [1/2]

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
microfmt::log::fanout_log_sink< MaxSinks, Channel >::fanout_log_sink ( )
defaultnoexcept

◆ fanout_log_sink() [2/2]

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
microfmt::log::fanout_log_sink< MaxSinks, Channel >::fanout_log_sink ( const fanout_log_sink< MaxSinks, Channel > &  )
delete

Member Function Documentation

◆ add_sink()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
bool microfmt::log::fanout_log_sink< MaxSinks, Channel >::add_sink ( extended_log_sink  s)
inlinenoexcept

Appends s; returns false when the table is full. Thread context only. Safe against concurrent writers of both classes.

◆ as_sink()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
extended_log_sink microfmt::log::fanout_log_sink< MaxSinks, Channel >::as_sink ( level  lvl = level::trace) &
inlinenoexcept

Handle for use as a sink (e.g. by extended_logger).

◆ dropped()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
std::size_t microfmt::log::fanout_log_sink< MaxSinks, Channel >::dropped ( ) const
inlinenoexcept

Thread records discarded because a pin stayed full for the whole wait.

◆ flush_impl()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
void microfmt::log::fanout_log_sink< MaxSinks, Channel >::flush_impl ( )
inlinenoexcept

◆ full_impl()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
bool microfmt::log::fanout_log_sink< MaxSinks, Channel >::full_impl ( const extended_log_msg &  msg)
inlinenoexcept

◆ log_impl()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
void microfmt::log::fanout_log_sink< MaxSinks, Channel >::log_impl ( const extended_log_msg &  msg)
inlinenoexcept

◆ notifier()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
space_notifier microfmt::log::fanout_log_sink< MaxSinks, Channel >::notifier ( ) &
inlinenoexcept

notify_space as a callback for a pin's consumer.

◆ notify_space()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
void microfmt::log::fanout_log_sink< MaxSinks, Channel >::notify_space ( )
inlinenoexcept

Reader side: tells waiting writers that space may have been freed. Thread context.

◆ operator=()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
fanout_log_sink & microfmt::log::fanout_log_sink< MaxSinks, Channel >::operator= ( const fanout_log_sink< MaxSinks, Channel > &  )
delete

◆ set_wait_timeout_us()

template<std::size_t MaxSinks, typename Channel = null_wait_channel>
void microfmt::log::fanout_log_sink< MaxSinks, Channel >::set_wait_timeout_us ( std::uint64_t  us)
inlinenoexcept

Longest a turn holder sleeps for space, per record.


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