12#ifndef SST_CORE_CLOCK_H
13#define SST_CORE_CLOCK_H
15#include "sst/core/action.h"
16#include "sst/core/ssthandler.h"
17#include "sst/core/timeConverter.h"
18#include "sst/core/util/bit_util.h"
25#define _CLE_DBG(fmt, args...) __DBG(DBG_CLOCK, Clock, fmt, ##args)
45 friend class BaseComponent;
46 friend class Component;
47 friend class Simulation;
53 std::vector<HandlerBase*> handlers_;
54 int32_t inactive_start_ = 0;
55 uint16_t handler_count_ = 0;
56 Clock* clock_ =
nullptr;
69 int getClockPriority() {
return clock_->
getPriority(); }
95 void activateOnRestart();
100 bool execute(Cycle_t current_cycle);
113 int32_t tmp = -1 - inactive->index_;
114 inactive->index_ = -1 - active->index_;
115 active->index_ = tmp;
117 std::swap(active, inactive);
127 std::swap(h1->index_, h2->index_);
148 HandlerBase() =
default;
149 ~HandlerBase() =
default;
153 SSTHandlerBase<bool, Cycle_t>::serialize_order(ser);
159 ImplementVirtualSerializable(HandlerBase);
166 return (order_ == bit_util::type_max<uint32_t>) ? clock_->
getPeriod() : group_->getClockPeriod();
174 return (order_ == bit_util::type_max<uint32_t>) ? clock_->getPriority() : group_->getClockPriority();
189 if ( order_ == bit_util::type_max<uint32_t> ) {
190 clock_->registerHandler(
this);
191 return clock_->getNextCycle();
194 group_->activateHandler(
this);
195 return group_->getNextCycle();
204 if ( order_ == bit_util::type_max<uint32_t> ) {
206 clock_->unregisterHandler(
this, empty);
209 group_->deactivateHandler(
this);
214 friend class BaseComponent;
225 Clock* clock_ =
nullptr;
234 uint32_t order_ = bit_util::type_max<uint32_t>;
252 if ( index_ >= 0 )
return;
253 index_ = -1 - index_;
259 void markAsInactive()
261 if ( index_ < 0 )
return;
262 index_ = -1 - index_;
268 void toggleActiveState() { index_ = -1 - index_; }
294 template <
typename classT, auto funcT,
typename dataT =
void>
300 template <
typename classT, auto funcT,
typename dataT =
void>
302 "The name Handler2 has been deprecated and will be removed in SST 17. Please rename Handler2 to Handler.")]]
353 std::string
toString()
const override;
369 std::vector<HandlerBase*> handlers_;
370 std::vector<Group*> groups_;
371 int32_t groups_inactive_start_ = 0;
373 Cycle_t current_cycle_ = 0;
376 bool scheduled_ =
false;
384class ClockHandlerMetaData :
public AttachPointMetaData
387 const ComponentId_t comp_id;
388 const std::string comp_name;
389 const std::string comp_type;
391 ClockHandlerMetaData(ComponentId_t
id,
const std::string& cname,
const std::string& ctype) :
397 ~ClockHandlerMetaData() {}
virtual void execute()=0
Function which will be called when the time for this Activity comes to pass.
int getPriority() const
Return the Priority of this Activity.
Definition activity.h:153
Main component object for the simulation.
Definition baseComponent.h:98
Base classes for clock handlers.
Definition clock.h:146
Cycle_t activate()
Activate this Clock Handler.
Definition clock.h:187
TimeConverter getClockPeriod()
Get the period of the associated clock as a SimTime_t in units of the core atomic timebase.
Definition clock.h:164
int getClockPriority()
Get the priority of the associated clock as a SimTime_t in units of the core atomic timebase.
Definition clock.h:172
void deactivate()
Deactivate this Clock Handler.
Definition clock.h:202
bool isActive()
Query whether handler is currently active.
Definition clock.h:180
A Clock class.
Definition clock.h:40
Cycle_t getNextCycle()
Return the time of the next clock tick.
Definition clock.cc:306
SSTHandler< bool, Cycle_t, classT, dataT, funcT, HandlerBase > Handler
Used to create handlers for clock.
Definition clock.h:295
void schedule()
Activates this clock object, by inserting into the simulation's timeVortex for future execution.
Definition clock.cc:400
void registerHandler(Clock::HandlerBase *handler)
Add a handler to be called on this clock's tick.
Definition clock.cc:193
std::string toString() const override
Get a string represenation of the event.
Definition clock.cc:430
void activateGroup(Group *group)
Activates a group that is inactive.
Definition clock.cc:288
bool isHandlerRegistered(Clock::HandlerBase *handler)
Checks to see if a handler is registered with this clock.
Definition clock.cc:268
bool unregisterHandler(Clock::HandlerBase *handler, bool &empty)
Remove a handler from the list of handlers to be called on the clock tick.
Definition clock.cc:234
void registerHandler_restart(Clock::HandlerBase *handler)
Add a handler to this Clock object during restart.
Definition clock.cc:254
void registerGroup(Group *group)
Register a group with this Clock object.
Definition clock.cc:278
TimeConverter getPeriod()
Get the period of the clock as a TimeConverter.
Definition clock.h:357
Clock(TimeConverter period, int priority=CLOCKPRIORITY)
Create a new clock with a specified period.
Definition clock.cc:182
SSTHandler< bool, Cycle_t, classT, dataT, funcT, HandlerBase > Handler2
Handler2 version which is now the same as Handler and is provided for backward compatibility until SS...
void updateCurrentCycle()
Update current cycle count - needed at simulation end if clock has run ahead of simulation end and to...
Definition clock.cc:423
Main component object for the simulation.
Definition component.h:32
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Base template for handlers which take a class defined argument.
Definition ssthandler.h:110
Base template for the class.
Definition ssthandler.h:1128
Main control class for a SST Simulation.
Definition simulation.h:121
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:31
UnitAlgebra getPeriod() const
Definition timeLord.cc:119