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()) :
71 writePS(std::forward<U>(init_val));
76 ev_update_(rhs.ev_update_),
77 current_state_(rhs.current_state_),
84 name_(std::move(rhs.name_)),
85 ev_update_(std::move(rhs.ev_update_)),
86 current_state_(std::move(rhs.current_state_)),
87 data_(std::move(rhs.data_))
95 ev_update_ = rhs.ev_update_;
98 current_state_ = rhs.current_state_;
106 name_ = std::move(rhs.name_);
107 ev_update_ = std::move(rhs.ev_update_);
110 current_state_ = std::move(rhs.current_state_);
111 data_ = std::move(rhs.data_);
137 writePSImpl_(std::move(dat));
145 return data_[PState_()].isValid();
155 return data_[PState_()];
165 return data_[PState_()];
181 writeImpl_(std::move(dat));
189 return data_[NState_()].isValid();
200 return data_[NState_()];
211 return data_[NState_()];
216 data_[PState_()].clearValid();
217 data_[NState_()].clearValid();
222 data_[NState_()].clearValid();
227 data_[PState_()].clearValid();
234 static_assert(manual_update ==
true,
235 "Cannot call update on a SharedData object if manual_update == false");
241 void writePSImpl_(U && dat) {
242 data_[PState_()] = std::forward<U>(dat);
246 void writeImpl_(U && dat) {
247 data_[NState_()] = std::forward<U>(dat);
248 if constexpr (!manual_update) {
249 ev_update_.schedule(1);
255 current_state_ = NState_();
263 GlobalEvent<SchedulingPhase::Update> ev_update_;
266 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 std::string & getName() const
Get the name of this SharedData.
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.