gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
34 #include "systemc/core/module.hh"
39 
40 namespace sc_gem5
41 {
42 
43 Event::Event(sc_core::sc_event *_sc_event, bool internal) :
44  Event(_sc_event, nullptr, internal)
45 {}
46 
47 Event::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 {
53  if (_basename == "" && ::sc_core::sc_is_running())
55 
56  parent = internal ? nullptr : pickParentObj();
57 
58  if (internal) {
60  _name = _basename;
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 {
69  topLevelEvents.emplace(topLevelEvents.end(), _sc_event);
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 
104  EventsIt it = findEvent(_name);
105  std::swap(*it, allEvents.back());
106  allEvents.pop_back();
107 
108  if (delayedNotify.scheduled())
110 }
111 
112 const std::string &
113 Event::name() const
114 {
115  return _name;
116 }
117 
118 const std::string &
120 {
121  return _basename;
122 }
123 
124 bool
126 {
127  return _inHierarchy;
128 }
129 
132 {
133  return parent;
134 }
135 
136 void
138 {
139  for (auto s: senses)
140  s->notify(this);
141 }
142 
143 void
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 
157 void
159 {
160  if (scheduler.inUpdate())
162 
163  // An immediate notification overrides any pending delayed notification.
164  if (delayedNotify.scheduled())
166 
172 }
173 
174 void
176 {
177  if (delayedNotify.scheduled()) {
179  return;
180 
182  }
184 }
185 
186 void
188 {
189  if (delayedNotify.scheduled())
191  notify(t);
192 }
193 
194 void
196 {
197  if (delayedNotify.scheduled())
199 }
200 
201 bool
203 {
205 }
206 
207 void
209 {
210  if (!parent)
211  return;
213  parent = nullptr;
214  topLevelEvents.emplace(topLevelEvents.end(), sc_event());
215 }
216 
219 
220 EventsIt
221 findEvent(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
sc_gem5::globalNameGen
UniqueNameGen globalNameGen
Definition: module.cc:49
gem5::VegaISA::s
Bitfield< 1 > s
Definition: pagetable.hh:64
sc_gem5::pickParentObj
sc_core::sc_object * pickParentObj()
Definition: object.cc:310
sc_gem5::Object::getFromScObject
static Object * getFromScObject(sc_core::sc_object *sc_obj)
Definition: object.hh:81
sc_gem5::Event::inHierarchy
bool inHierarchy() const
Definition: event.cc:125
sc_gem5::Event::dynamicSenseThread
DynamicSensitivities dynamicSenseThread
Definition: event.hh:158
module.hh
sc_gem5::Scheduler::deschedule
void deschedule(ScEvent *event)
Definition: scheduler.hh:280
sc_gem5::Event
Definition: event.hh:58
sc_gem5::EventsIt
Events::iterator EventsIt
Definition: object.hh:45
std::vector< StaticSensitivity * >
sc_gem5::Scheduler::inUpdate
bool inUpdate()
Definition: scheduler.hh:384
sc_gem5::pickUniqueName
std::string pickUniqueName(::sc_core::sc_object *parent, std::string base)
Definition: object.cc:273
sc_gem5::Event::getParentObject
sc_core::sc_object * getParentObject() const
Definition: event.cc:131
sc_gem5::UniqueNameGen::gen
const char * gen(std::string seed)
Definition: module.hh:60
sc_gem5::Event::delayedNotify
ScEvent delayedNotify
Definition: event.hh:152
sc_gem5::Scheduler::changeStamp
uint64_t changeStamp()
Definition: scheduler.hh:388
sc_gem5::Event::_triggeredStamp
uint64_t _triggeredStamp
Definition: event.hh:153
sc_gem5::Event::name
const std::string & name() const
Definition: event.cc:113
sc_gem5::Event::notifyDelayed
void notifyDelayed(const sc_core::sc_time &t)
Definition: event.cc:187
sc_core::SC_ID_NOTIFY_DELAYED_
const char SC_ID_NOTIFY_DELAYED_[]
Definition: messages.cc:79
sc_gem5::Event::staticSenseThread
StaticSensitivities staticSenseThread
Definition: event.hh:156
sc_gem5::ScEvent::when
void when(gem5::Tick w)
Definition: sched_event.hh:81
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
sc_gem5::Event::parent
sc_core::sc_object * parent
Definition: event.hh:150
sc_gem5::Event::~Event
~Event()
Definition: event.cc:91
sc_core::SC_ID_IMMEDIATE_NOTIFICATION_
const char SC_ID_IMMEDIATE_NOTIFICATION_[]
Definition: messages.cc:66
sc_core::sc_event
Definition: sc_event.hh:169
sc_gem5::Event::Event
Event(sc_core::sc_event *_sc_event, bool internal=false)
Definition: event.cc:43
sc_main.hh
sc_gem5::Event::basename
const std::string & basename() const
Definition: event.cc:119
sc_gem5::Object
Definition: object.hh:47
sc_core::sc_time
Definition: sc_time.hh:49
sc_gem5::allEvents
Events allEvents
Definition: event.cc:218
sc_gem5::Event::notify
void notify()
Definition: event.cc:158
sc_gem5::findEvent
EventsIt findEvent(const std::string &name)
Definition: event.cc:221
messages.hh
sc_gem5::Event::cancel
void cancel()
Definition: event.cc:195
sc_core::sc_gen_unique_name
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
sc_gem5::Event::staticSenseMethod
StaticSensitivities staticSenseMethod
Definition: event.hh:155
sc_gem5::Event::_basename
std::string _basename
Definition: event.hh:146
sc_core::sc_object
Definition: sc_object.hh:50
name
const std::string & name()
Definition: trace.cc:48
sc_gem5::Event::_inHierarchy
bool _inHierarchy
Definition: event.hh:148
sc_module.hh
sc_core::SC_ID_INSTANCE_EXISTS_
const char SC_ID_INSTANCE_EXISTS_[]
Definition: messages.cc:39
sc_gem5::ScEvent::scheduled
bool scheduled()
Definition: sched_event.hh:78
sc_gem5::Object::delChildEvent
void delChildEvent(sc_core::sc_event *e)
Definition: object.cc:254
SC_REPORT_WARNING
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report_handler.hh:123
sc_gem5::Event::clearParent
void clearParent()
Definition: event.cc:208
sc_gem5::Scheduler::delayed
gem5::Tick delayed(const ::sc_core::sc_time &delay)
Definition: scheduler.hh:246
sc_gem5::Event::dynamicSenseMethod
DynamicSensitivities dynamicSenseMethod
Definition: event.hh:157
sc_gem5::Event::triggered
bool triggered() const
Definition: event.cc:202
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
sc_gem5::topLevelEvents
Events topLevelEvents
Definition: event.cc:217
sc_gem5::Event::_name
std::string _name
Definition: event.hh:147
sc_gem5::Scheduler::schedule
void schedule(ScEvent *event, const ::sc_core::sc_time &delay)
Definition: scheduler.hh:253
sc_gem5
Definition: sc_clock.cc:41
event.hh
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:494
sc_gem5::Event::sc_event
sc_core::sc_event * sc_event()
Definition: event.hh:67
scheduler.hh
sc_gem5::Event::_sc_event
sc_core::sc_event * _sc_event
Definition: event.hh:144
sc_core::sc_is_running
bool sc_is_running()
Definition: sc_main.cc:141

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17