SST 12.1.0
Structural Simulation Toolkit
clock.h
1// Copyright 2009-2022 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2022, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_CLOCK_H
13#define SST_CORE_CLOCK_H
14
15#include "sst/core/action.h"
16#include "sst/core/ssthandler.h"
17
18#include <cinttypes>
19#include <vector>
20
21#define _CLE_DBG(fmt, args...) __DBG(DBG_CLOCK, Clock, fmt, ##args)
22
23namespace SST {
24
25class TimeConverter;
26
27/**
28 * A Clock class.
29 *
30 * Calls callback functions (handlers) on a specified period
31 */
32class Clock : public Action
33{
34public:
35 /** Create a new clock with a specified period */
36 Clock(TimeConverter* period, int priority = CLOCKPRIORITY);
37 ~Clock();
38
39 /**
40 Base handler for clock functions.
41 */
43
44 /**
45 Used to create handlers for clock. The callback function is
46 expected to be in the form of:
47
48 bool func(Cycle_t cycle)
49
50 In which case, the class is created with:
51
52 new Clock::Handler<classname>(this, &classname::function_name)
53
54 Or, to add static data, the callback function is:
55
56 bool func(Cycle_t cycle, dataT data)
57
58 and the class is created with:
59
60 new Clock::Handler<classname, dataT>(this, &classname::function_name, data)
61
62 In both cases, the boolean that's returned indicates whether
63 the handler should be removed from the list or not. On return
64 of true, the handler will be removed. On return of false, the
65 handler will be left in the clock list.
66 */
67 template <typename classT, typename dataT = void>
69
70 /**
71 * Activates this clock object, by inserting into the simulation's
72 * timeVortex for future execution.
73 */
74 void schedule();
75
76 /** Return the time of the next clock tick */
77 Cycle_t getNextCycle();
78
79 /** Add a handler to be called on this clock's tick */
81 /** Remove a handler from the list of handlers to be called on the clock tick */
82 bool unregisterHandler(Clock::HandlerBase* handler, bool& empty);
83
84 std::string toString() const override;
85
86private:
87 /* typedef std::list<Clock::HandlerBase*> HandlerMap_t; */
88 typedef std::vector<Clock::HandlerBase*> StaticHandlerMap_t;
89
90 Clock() {}
91
92 void execute(void) override;
93
94 Cycle_t currentCycle;
95 TimeConverter* period;
96 StaticHandlerMap_t staticHandlerMap;
97 SimTime_t next;
98 bool scheduled;
99
100 NotSerializable(SST::Clock)
101};
102
103
105{
106public:
107 const ComponentId_t comp_id;
108 const std::string comp_name;
109 const std::string comp_type;
110
111 ClockHandlerMetaData(ComponentId_t id, const std::string& cname, const std::string& ctype) :
112 comp_id(id),
113 comp_name(cname),
114 comp_type(ctype)
115 {}
116
118};
119
120
121} // namespace SST
122
123#endif // SST_CORE_CLOCK_H
An Action is a schedulable Activity which is not an Event.
Definition: action.h:27
Definition: clock.h:105
A Clock class.
Definition: clock.h:33
Cycle_t getNextCycle()
Return the time of the next clock tick.
Definition: clock.cc:65
void schedule()
Activates this clock object, by inserting into the simulation's timeVortex for future execution.
Definition: clock.cc:106
std::string toString() const override
Get a string represenation of the event.
Definition: clock.cc:128
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:47
bool registerHandler(Clock::HandlerBase *handler)
Add a handler to be called on this clock's tick.
Definition: clock.cc:39
Just a tag class for the various metadata that will need to be stored in the simulation object to all...
Definition: ssthandler.h:28
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:171
Handler class with user-data argument.
Definition: ssthandler.h:220
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:27