36 template<
class DataT,
bool manual_update = false>
40 typedef std::array<utils::ValidValue<DataT>, 2> PSNSData;
43 uint32_t NState_()
const {
44 return (current_state_ + 1) & 0x1;
48 uint32_t PState_()
const {
49 return current_state_;
64 template<
typename U = DataT>
67 U && init_val = U()) :
70 writePS(std::forward<U>(init_val));
74 ev_update_(rhs.ev_update_),
75 current_state_(rhs.current_state_),
81 SharedData(SharedData&& rhs) :
82 ev_update_(std::move(rhs.ev_update_)),
83 current_state_(std::move(rhs.current_state_)),
84 data_(std::move(rhs.data_))
91 ev_update_ = rhs.ev_update_;
94 current_state_ = rhs.current_state_;
102 ev_update_ = std::move(rhs.ev_update_);
105 current_state_ = std::move(rhs.current_state_);
106 data_ = std::move(rhs.data_);
124 writePSImpl_(std::move(dat));
132 return data_[PState_()].isValid();
142 return data_[PState_()];
152 return data_[PState_()];
168 writeImpl_(std::move(dat));
176 return data_[NState_()].isValid();
187 return data_[NState_()];
198 return data_[NState_()];
203 data_[PState_()].clearValid();
204 data_[NState_()].clearValid();
209 data_[NState_()].clearValid();
214 data_[PState_()].clearValid();
221 static_assert(manual_update ==
true,
222 "Cannot call update on a SharedData object if manual_update == false");
228 void writePSImpl_(U && dat) {
229 data_[PState_()] = std::forward<U>(dat);
233 void writeImpl_(U && dat) {
234 data_[NState_()] = std::forward<U>(dat);
235 if constexpr (!manual_update) {
236 ev_update_.schedule(1);
242 current_state_ = NState_();
247 GlobalEvent<SchedulingPhase::Update> ev_update_;
250 uint32_t current_state_ = 0;
File that defines the GlobalEvent class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#define CREATE_SPARTA_HANDLER(clname, meth)
File that defines a ValidValue.
A representation of simulated time.
Class that allows the writing of data this cycle, but not visable until next cycle.
void clearPS()
Clear Present State valid.
DataT & accessNS()
Get a non-constant reference to the data that will be visible next cycle.
bool isValidNS() const
Is there data for the next cycle?
bool isValid() const
Is there data in the current view.
void update()
Update the SharedData class – move next cycle data to current view. Can only be called on a manually ...
void write(const DataT &dat)
Write data for the next cycle view.
SharedData(const std::string &name, const Clock *clk, U &&init_val=U())
Construct a SharedData item.
void clearNS()
Clear Next State valid.
void write(DataT &&dat)
Write data for the next cycle view.
void writePS(DataT &&dat)
Write data to the current view.
void clear()
Clear both Present State and Next State valids.
const DataT & readNS() const
Get a constant reference to the data that will be visible next cycle.
const DataT & read() const
Get a constant reference to the data visible this cycle.
DataT & access()
Get a non-constant reference to the data visible this cycle.
void writePS(const DataT &dat)
Write data to the current view.
Macros for handling exponential backoff.