SST 16.0.0
Structural Simulation Toolkit
oneshotManager.h
1// Copyright 2009-2026 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-2026, 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_ONESHOTMANAGER_H
13#define SST_CORE_ONESHOTMANAGER_H
14
15#include "sst/core/action.h"
16#include "sst/core/sst_types.h"
17#include "sst/core/ssthandler.h"
18
19#include <cinttypes>
20#include <map>
21#include <string>
22#include <utility>
23#include <vector>
24
25namespace SST {
26
27class Simulation;
28
29namespace Core {
30
31// Forward declare OneShotManager
32class OneShotManager;
33
34// General using for these classes
35using TimeStamp_t = std::pair<SimTime_t, int>;
36
37
38class OneShot : public Action
39{
40public:
41
42 /**
43 Base handler for OneShot callbacks.
44 */
46
47 /**
48 Used to create checkpointable handlers for OneShot. The callback function is
49 expected to be in the form of:
50
51 void func()
52
53 In which case, the class is created with:
54
55 new OneShot::Handler<classname, &classname::function_name>(this)
56
57 Or, to add static data, the callback function is:
58
59 void func(dataT data)
60
61 and the class is created with:
62
63 new OneShot::Handler<classname, &classname::function_name, dataT>(this, data)
64 */
65 template <typename classT, auto funcT, typename dataT = void>
67
68 template <typename classT, auto funcT, typename dataT = void>
69 using Handler2 [[deprecated(
70 "The name Handler2 has been deprecated and will be removed in SST 17. Please rename Handler2 to Handler.")]]
72
73 using HandlerList_t = std::vector<OneShot::HandlerBase*>;
74
75 OneShotManager* manager;
76 HandlerList_t& handlers;
77 TimeStamp_t time;
78
79 OneShot(TimeStamp_t time, OneShotManager* manager, HandlerList_t& handlers) :
80 manager(manager),
81 handlers(handlers),
82 time(time)
83 {
84 setDeliveryTime(time.first);
85 setPriority(time.second);
86 }
87
88 ~OneShot() {}
89
90 void execute() override;
91};
92
93
94/**
95 Manages the OneShot actions for the core. This allows handlers to
96 be registered with the core that will be called at a specific time
97 and priority.
98*/
100{
101
102 using HandlerVectorMap_t = std::map<TimeStamp_t, std::pair<OneShot::HandlerList_t, bool>>;
103
104public:
105
106 /////////////////////////////////////////////////
107
108 /** Create a new One Shot for a specified time that will callback the
109 handler function.
110 Note: OneShot cannot be canceled, and will always callback after
111 the timedelay.
112 */
115
116 /** Add a handler to be called on this OneShot Event */
117 template <class classT, auto funcT, typename dataT>
118 void registerRelativeHandler(SimTime_t trigger_time, int priority, classT* obj, dataT metadata)
119 {
121 registerHandlerBase(trigger_time, priority, true, handler);
122 }
123
124 /** Add a handler to be called on this OneShot Event */
125 template <class classT, auto funcT>
126 void registerRelativeHandler(SimTime_t trigger_time, int priority, classT* obj)
127 {
129 registerHandlerBase(trigger_time, priority, true, handler);
130 }
131
132 /** Add a handler to be called on this OneShot Event */
133 template <class classT, auto funcT, typename dataT>
134 void registerAbsoluteHandler(SimTime_t trigger_time, int priority, classT* obj, dataT metadata)
135 {
137 registerHandlerBase(trigger_time, priority, false, handler);
138 }
139
140 /** Add a handler to be called on this OneShot Event */
141 template <class classT, auto funcT>
142 void registerAbsoluteHandler(SimTime_t trigger_time, int priority, classT* obj)
143 {
145 registerHandlerBase(trigger_time, priority, false, handler);
146 }
147
148
149private:
150 friend class OneShot;
151
152 HandlerVectorMap_t handler_vector_map_;
153 Simulation* sim_ = nullptr;
154
155 /**
156 Registers a handler for delivery at the specified time
157 */
158 void registerHandlerBase(SimTime_t trigger_time, int priority, bool relative, OneShot::HandlerBase* handler);
159
160 /**
161 Schedules the first entry in handler_vector_map_ if it is not
162 already scheduled.
163 */
164 void scheduleNextOneShot();
165
166 // Function that will be called when a oneshot is done calling its
167 // handlers. This allows the OneShotManager to clean things up
168 // and schedule the next OneShot
169 void oneshotCallback(TimeStamp_t time, OneShot* oneshot);
170};
171
172} // namespace Core
173} // namespace SST
174
175#endif // SST_CORE_ONESHOTMANAGER_H
void setPriority(uint64_t priority)
Set the priority of the Activity.
Definition activity.h:200
void setDeliveryTime(SimTime_t time)
Set the time for which this Activity should be delivered.
Definition activity.h:147
Manages the OneShot actions for the core.
Definition oneshotManager.h:100
void registerAbsoluteHandler(SimTime_t trigger_time, int priority, classT *obj)
Add a handler to be called on this OneShot Event.
Definition oneshotManager.h:142
void registerRelativeHandler(SimTime_t trigger_time, int priority, classT *obj, dataT metadata)
Add a handler to be called on this OneShot Event.
Definition oneshotManager.h:118
void registerRelativeHandler(SimTime_t trigger_time, int priority, classT *obj)
Add a handler to be called on this OneShot Event.
Definition oneshotManager.h:126
void registerAbsoluteHandler(SimTime_t trigger_time, int priority, classT *obj, dataT metadata)
Add a handler to be called on this OneShot Event.
Definition oneshotManager.h:134
OneShotManager(Simulation *sim)
Create a new One Shot for a specified time that will callback the handler function.
Definition oneshotManager.cc:37
Definition oneshotManager.h:39
void execute() override
Function which will be called when the time for this Activity comes to pass.
Definition oneshotManager.cc:24
SSTHandlerBase< void, void > HandlerBase
Base handler for OneShot callbacks.
Definition oneshotManager.h:45
SSTHandler< void, void, classT, dataT, funcT > Handler
Used to create checkpointable handlers for OneShot.
Definition oneshotManager.h:66
Base template for handlers which take a class defined argument.
Definition ssthandler.h:79
Base template for the class.
Definition ssthandler.h:1102
Main control class for a SST Simulation.
Definition simulation.h:121