gem5 v24.0.0.0
Loading...
Searching...
No Matches
event.cc
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "systemc/core/event.hh"
29
30#include <algorithm>
31#include <cstring>
32#include <utility>
33
39
40namespace sc_gem5
41{
42
43Event::Event(sc_core::sc_event *_sc_event, bool internal) :
44 Event(_sc_event, nullptr, internal)
45{}
46
47Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr,
48 bool internal) :
49 _sc_event(_sc_event), _basename(_basename_cstr ? _basename_cstr : ""),
50 _inHierarchy(!internal), delayedNotify([this]() { this->notify(); }),
51 _triggeredStamp(~0ULL)
52{
55
56 parent = internal ? nullptr : pickParentObj();
57
58 if (internal) {
61 } else {
62 std::string original_name = _basename;
64
65 if (parent) {
66 Object *obj = Object::getFromScObject(parent);
67 obj->addChildEvent(_sc_event);
68 } else {
70 }
71
72 std::string path = parent ? (std::string(parent->name()) + ".") : "";
73
74 if (original_name != "" && _basename != original_name) {
75 std::string message = path + original_name +
76 ". Latter declaration will be renamed to " +
77 path + _basename;
79 message.c_str());
80 }
81
82 _name = path + _basename;
83 }
84
85 allEvents.emplace(allEvents.end(), _sc_event);
86
87 // Determine if we're in the hierarchy (created once initialization starts
88 // means no).
89}
90
92{
93 if (parent) {
96 } else if (inHierarchy()) {
97 EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(),
98 _sc_event);
99 assert(it != topLevelEvents.end());
100 std::swap(*it, topLevelEvents.back());
101 topLevelEvents.pop_back();
102 }
103
105 std::swap(*it, allEvents.back());
106 allEvents.pop_back();
107
110}
111
112const std::string &
114{
115 return _name;
116}
117
118const std::string &
120{
121 return _basename;
122}
123
124bool
126{
127 return _inHierarchy;
128}
129
132{
133 return parent;
134}
135
136void
138{
139 for (auto s: senses)
140 s->notify(this);
141}
142
143void
145{
146 int size = senses.size();
147 int pos = 0;
148 while (pos < size) {
149 if (senses[pos]->notify(this))
150 senses[pos] = senses[--size];
151 else
152 pos++;
153 }
154 senses.resize(size);
155}
156
157void
159{
160 if (scheduler.inUpdate())
162
163 // An immediate notification overrides any pending delayed notification.
166
172}
173
174void
176{
177 if (delayedNotify.scheduled()) {
179 return;
180
182 }
184}
185
186void
193
194void
200
201bool
203{
205}
206
207void
209{
210 if (!parent)
211 return;
213 parent = nullptr;
214 topLevelEvents.emplace(topLevelEvents.end(), sc_event());
215}
216
219
221findEvent(const std::string &name)
222{
223 EventsIt it;
224 for (it = allEvents.begin(); it != allEvents.end(); it++)
225 if (!strcmp((*it)->name(), name.c_str()))
226 break;
227
228 return it;
229}
230
231} // namespace sc_gem5
const char * name() const
Definition sc_object.cc:44
void notify()
Definition event.cc:158
StaticSensitivities staticSenseMethod
Definition event.hh:155
bool triggered() const
Definition event.cc:202
sc_core::sc_event * sc_event()
Definition event.hh:67
DynamicSensitivities dynamicSenseMethod
Definition event.hh:157
sc_core::sc_object * getParentObject() const
Definition event.cc:131
StaticSensitivities staticSenseThread
Definition event.hh:156
const std::string & basename() const
Definition event.cc:119
DynamicSensitivities dynamicSenseThread
Definition event.hh:158
void clearParent()
Definition event.cc:208
bool _inHierarchy
Definition event.hh:148
Event(sc_core::sc_event *_sc_event, bool internal=false)
Definition event.cc:43
bool inHierarchy() const
Definition event.cc:125
std::string _basename
Definition event.hh:146
void notifyDelayed(const sc_core::sc_time &t)
Definition event.cc:187
sc_core::sc_event * _sc_event
Definition event.hh:144
const std::string & name() const
Definition event.cc:113
ScEvent delayedNotify
Definition event.hh:152
std::string _name
Definition event.hh:147
sc_core::sc_object * parent
Definition event.hh:150
void cancel()
Definition event.cc:195
uint64_t _triggeredStamp
Definition event.hh:153
void delChildEvent(sc_core::sc_event *e)
Definition object.cc:254
static Object * getFromScObject(sc_core::sc_object *sc_obj)
Definition object.hh:81
void when(gem5::Tick w)
uint64_t changeStamp()
Definition scheduler.hh:388
gem5::Tick delayed(const ::sc_core::sc_time &delay)
Definition scheduler.hh:246
void deschedule(ScEvent *event)
Definition scheduler.hh:280
void schedule(ScEvent *event, const ::sc_core::sc_time &delay)
Definition scheduler.hh:253
const char * gen(std::string seed)
Definition module.hh:60
const char SC_ID_INSTANCE_EXISTS_[]
Definition messages.cc:39
const char SC_ID_IMMEDIATE_NOTIFICATION_[]
Definition messages.cc:66
bool sc_is_running()
Definition sc_main.cc:141
const char SC_ID_NOTIFY_DELAYED_[]
Definition messages.cc:79
const char * sc_gen_unique_name(const char *seed)
Definition sc_module.cc:820
UniqueNameGen globalNameGen
Definition module.cc:49
std::string pickUniqueName(::sc_core::sc_object *parent, std::string base)
Definition object.cc:273
Events::iterator EventsIt
Definition object.hh:45
Events topLevelEvents
Definition event.cc:217
sc_core::sc_object * pickParentObj()
Definition object.cc:310
Scheduler scheduler
Definition scheduler.cc:494
Events allEvents
Definition event.cc:218
EventsIt findEvent(const std::string &name)
Definition event.cc:221
#define SC_REPORT_WARNING(msg_type, msg)
#define SC_REPORT_ERROR(msg_type, msg)
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0