chronon::sender::Unit
#include <Unit.hpp>
Inherited by chronon::sender::TickableUnit
Public Functions
| Name | |
|---|---|
| virtual | ~Unit() =default |
| void | wakeAt(uint64_t cycle) Wake the unit no later than cycle. Safe for cross-thread producers. |
| bool | usesActivityScheduling() const |
| void | useFastCycleCounter() Default mode. Eliminates atomic overhead (~80% of tight-loop time). |
| void | useAtomicCycleCounter() |
| tree::TreeNode * | treeNode() const |
| uint32_t | tickInterval() const |
| UnitState | state() const |
| void | sleepUntil(uint64_t cycle) |
| void | sleepForever() Disable the tick body until an external wakeAt() or port arrival wakes it. |
| bool | shouldRunTickAt(uint64_t cycle) const |
| void | setTreeNode(tree::TreeNode * node) Triggers registration of all pending ports to PortDirectory. |
| void | setTickInterval(uint32_t interval) |
| void | registerPort(PortBase * port) |
| const std::vector< PortBase * > & | ports() const |
| Unit & | operator=(const Unit & ) =delete |
| Unit & | operator=(Unit && ) =delete |
| uint64_t | nextRunnableCycleAtOrAfter(uint64_t cycle) const |
| uint64_t | nextActiveCycle() const |
| const std::string & | name() const |
| uint64_t | localCycle() const |
| virtual void | initialize() Called after all connections are made, before run() starts. |
| uint32_t | id() const |
| std::string | fullPath() const Returns the tree path if a TreeNode is set, else the unit name. |
| virtual void | finalize() Called after run() completes or simulation is stopped. |
| void | enableActivityScheduling() |
| uint8_t | crashNameLen() const |
| const char * | crashName() const |
| void | addPendingPortRegistration(std::function< void(const std::string &)> registration) |
| bool | acceptsPortWakeups() const |
| Unit(std::string name) | |
| Unit(const Unit & ) =delete | |
| Unit(Unit && ) =delete |
Protected Functions
| Name | |
|---|---|
| void | setLocalCycle(uint64_t cycle) |
| void | setId(uint32_t id) |
| uint64_t | localCycleAtomic() const |
| void | finishActiveTick_() |
| void | beginActiveTick_() |
| void | advanceLocalCycle(uint64_t delta =1) Fast path: ~0.3ns increment. Slow path (atomic): ~15ns. |
Public Attributes
| Name | |
|---|---|
| uint64_t | NEVER_ACTIVE |
Friends
| Name | |
|---|---|
| class | TickSimulation |
Detailed Description
class chronon::sender::Unit;
Base class for simulation components.
A Unit owns input/output ports and implements tick() to define per-cycle behavior. The scheduler uses dependency analysis on connections to determine safe parallelization.
class Producer : public TickableUnit {
OutPort<int> out{this, "out"};
int count_ = 0;
public:
Producer() : TickableUnit("producer") {}
void tick() override {
if (out.canSend()) out.send(count_++);
}
bool isCompleted() const override { return count_ >= 100; }
};
Public Functions Documentation
function ~Unit
virtual ~Unit() =default
function wakeAt
inline void wakeAt(
uint64_t cycle
)
Wake the unit no later than cycle. Safe for cross-thread producers.
function usesActivityScheduling
inline bool usesActivityScheduling() const
function useFastCycleCounter
inline void useFastCycleCounter()
Default mode. Eliminates atomic overhead (~80% of tight-loop time).
function useAtomicCycleCounter
inline void useAtomicCycleCounter()
Use when localCycle() may be read from another thread. Not needed for lookahead — TickSimulation publishes progress explicitly via unit_progress_.
function treeNode
inline tree::TreeNode * treeNode() const
function tickInterval
inline uint32_t tickInterval() const
function state
inline UnitState state() const
function sleepUntil
inline void sleepUntil(
uint64_t cycle
)
Request that the unit's tick body next runs no earlier than cycle. This is expressed in the global simulation cycle domain.
function sleepForever
inline void sleepForever()
Disable the tick body until an external wakeAt() or port arrival wakes it.
function shouldRunTickAt
inline bool shouldRunTickAt(
uint64_t cycle
) const
function setTreeNode
inline void setTreeNode(
tree::TreeNode * node
)
Triggers registration of all pending ports to PortDirectory.
function setTickInterval
inline void setTickInterval(
uint32_t interval
)
function registerPort
inline void registerPort(
PortBase * port
)
function ports
inline const std::vector< PortBase * > & ports() const
function operator=
Unit & operator=(
const Unit &
) =delete
function operator=
Unit & operator=(
Unit &&
) =delete
function nextRunnableCycleAtOrAfter
inline uint64_t nextRunnableCycleAtOrAfter(
uint64_t cycle
) const
function nextActiveCycle
inline uint64_t nextActiveCycle() const
function name
inline const std::string & name() const
function localCycle
inline uint64_t localCycle() const
Fast non-atomic read. Cross-thread lookahead visibility uses TickSimulation::unit_progress_ atomics, not this counter.
function initialize
inline virtual void initialize()
Called after all connections are made, before run() starts.
function id
inline uint32_t id() const
function fullPath
inline std::string fullPath() const
Returns the tree path if a TreeNode is set, else the unit name.
function finalize
inline virtual void finalize()
Called after run() completes or simulation is stopped.
function enableActivityScheduling
inline void enableActivityScheduling()
Opt in to scheduler-controlled activity before the first tick.
Units that may sleep after their first poll but need future port arrivals sent earlier in the same cycle to wake them should call this from their constructor. sleepUntil(), sleepForever(), and setTickInterval(N > 1) enable it automatically once they are used.
function crashNameLen
inline uint8_t crashNameLen() const
function crashName
inline const char * crashName() const
function addPendingPortRegistration
inline void addPendingPortRegistration(
std::function< void(const std::string &)> registration
)
Add a port registration callback to be invoked when setTreeNode() runs. Called automatically by Port constructors for YAML-driven discovery.
function acceptsPortWakeups
inline bool acceptsPortWakeups() const
function Unit
inline explicit Unit(
std::string name
)
function Unit
Unit(
const Unit &
) =delete
function Unit
Unit(
Unit &&
) =delete
Protected Functions Documentation
function setLocalCycle
inline void setLocalCycle(
uint64_t cycle
)
function setId
inline void setId(
uint32_t id
)
function localCycleAtomic
inline uint64_t localCycleAtomic() const
Only valid when useAtomicCycleCounter() was called. Prefer TickSimulation::unit_progress_ for lookahead.
function finishActiveTick_
inline void finishActiveTick_()
function beginActiveTick_
inline void beginActiveTick_()
function advanceLocalCycle
inline void advanceLocalCycle(
uint64_t delta =1
)
Fast path: ~0.3ns increment. Slow path (atomic): ~15ns.
Public Attributes Documentation
variable NEVER_ACTIVE
static uint64_t NEVER_ACTIVE = std::numeric_limits<uint64_t>::max();
Friends
friend TickSimulation
friend class TickSimulation(
TickSimulation
);
Updated on 2026-07-06 at 09:03:33 +0000