microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Classes | Namespaces | Variables
sync.hpp File Reference

Locking and wait-channel building blocks shared by the logging stack (basic_logger and the extended sink fan-out). More...

#include "../microfmt_config.hpp"
#include <cstdint>
#include <reloco/mutex.hpp>
#include <reloco/unique_lock.hpp>
Include dependency graph for sync.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  microfmt::log::detail::null_mutex
 No-op mutex used as basic_logger's default Mutex so single-threaded usage pays zero synchronization cost. More...
 
struct  microfmt::log::null_wait_channel
 Wait channel that never sleeps: wait_for just evaluates the predicate once. Use for single-threaded or "discard when full" setups. More...
 
class  microfmt::log::condition_variable_wait_channel
 Hosted wait channel: a reloco::mutex plus reloco::condition_variable. More...
 
class  microfmt::log::space_notifier
 Type-erased "space was freed" callback handed to the consumer side of a sink (two words, no allocation). More...
 

Namespaces

namespace  microfmt
 
namespace  microfmt::log
 
namespace  microfmt::log::detail
 Fixed-capacity logger that formats records before dispatching to sinks.
 

Variables

constexpr std::uint64_t microfmt::log::wait_forever = ~std::uint64_t{0}
 timeout_us value meaning "wait without a deadline".
 

Detailed Description

Locking and wait-channel building blocks shared by the logging stack (basic_logger and the extended sink fan-out).

A wait channel couples the "outer" lock a blocked writer sleeps on with the primitive that sleeps/wakes it, so a port can map both onto one native facility (a condition variable + mutex on hosted targets, mtx(9) + cv(9)/wakeup(9) in a FreeBSD kernel). The required shape:

struct my_wait_channel {
void lock() noexcept; // outer lock; held while checking the predicate
void unlock() noexcept;
// Called with the lock held. Sleeps (releasing the lock while asleep)
// until pred() is true or timeout_us microseconds passed
// (`wait_forever`: no deadline). Re-evaluates
// pred() with the lock held. Returns the final pred() value.
template <typename Pred> bool wait_for(std::uint64_t timeout_us, Pred pred) noexcept;
void wake_all() noexcept; // wakes every sleeper; safe with the lock held
};
// FreeBSD kernel sketch (not compiled here):
// lock() -> mtx_lock(&mtx_)
// wait_for() -> while (!pred()) { if (cv_timedwait(&cv_, &mtx_, tick_count(us)) == EWOULDBLOCK) break; }
// wake_all() -> cv_broadcast(&cv_)