chronon::sender::Unit
#include <Unit.hpp>
Inherited by chronon::sender::TickableUnit
Public Functions
| Name | |
|---|---|
| virtual | ~Unit() =default |
| void | useFastCycleCounter() Default mode. Eliminates atomic overhead (~80% of tight-loop time). |
| void | useAtomicCycleCounter() |
| tree::TreeNode * | treeNode() const |
| UnitState | state() const |
| void | setTreeNode(tree::TreeNode * node) Triggers registration of all pending ports to PortDirectory. |
| void | registerPort(PortBase * port) |
| const std::vector< PortBase * > & | ports() const |
| Unit & | operator=(const Unit & ) =delete |
| Unit & | operator=(Unit && ) =delete |
| 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. |
| uint8_t | crashNameLen() const |
| const char * | crashName() const |
| void | addPendingPortRegistration(std::function< void(const std::string &)> registration) |
| Unit(std::string name) | |
| Unit(const Unit & ) =delete | |
| Unit(Unit && ) =delete |
Protected Functions
| Name | |
|---|---|
| void | setState(UnitState state) |
| void | setLocalCycle(uint64_t cycle) |
| void | setId(uint32_t id) |
| uint64_t | localCycleAtomic() const |
| void | advanceLocalCycle(uint64_t delta =1) Fast path: ~0.3ns increment. Slow path (atomic): ~15ns. |
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 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 state
inline UnitState state() const
function setTreeNode
inline void setTreeNode(
tree::TreeNode * node
)
Triggers registration of all pending ports to PortDirectory.
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 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 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 Unit
inline explicit Unit(
std::string name
)
function Unit
Unit(
const Unit &
) =delete
function Unit
Unit(
Unit &&
) =delete
Protected Functions Documentation
function setState
inline void setState(
UnitState state
)
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 advanceLocalCycle
inline void advanceLocalCycle(
uint64_t delta =1
)
Fast path: ~0.3ns increment. Slow path (atomic): ~15ns.
Friends
friend TickSimulation
friend class TickSimulation(
TickSimulation
);
Updated on 2026-05-26 at 05:42:32 +0000