gem5  v20.1.0.0
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 "sim/core.hh"
35 #include "systemc/core/module.hh"
40 
41 namespace sc_gem5
42 {
43 
44 Event::Event(sc_core::sc_event *_sc_event, bool internal) :
45  Event(_sc_event, nullptr, internal)
46 {}
47 
48 Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr,
49  bool internal) :
50  _sc_event(_sc_event), _basename(_basename_cstr ? _basename_cstr : ""),
51  _inHierarchy(!internal), delayedNotify([this]() { this->notify(); }),
52  _triggeredStamp(~0ULL)
53 {
54  if (_basename == "" && ::sc_core::sc_is_running())
56 
57  parent = internal ? nullptr : pickParentObj();
58 
59  if (internal) {
61  _name = _basename;
62  } else {
63  std::string original_name = _basename;
65 
66  if (parent) {
67  Object *obj = Object::getFromScObject(parent);
68  obj->addChildEvent(_sc_event);
69  } else {
70  topLevelEvents.emplace(topLevelEvents.end(), _sc_event);
71  }
72 
73  std::string path = parent ? (std::string(parent->name()) + ".") : "";
74 
75  if (original_name != "" && _basename != original_name) {
76  std::string message = path + original_name +
77  ". Latter declaration will be renamed to " +
78  path + _basename;
80  message.c_str());
81  }
82 
83  _name = path + _basename;
84  }
85 
86  allEvents.emplace(allEvents.end(), _sc_event);
87 
88  // Determine if we're in the hierarchy (created once initialization starts
89  // means no).
90 }
91 
93 {
94  if (parent) {
97  } else if (inHierarchy()) {
98  EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(),
99  _sc_event);
100  assert(it != topLevelEvents.end());
101  std::swap(*it, topLevelEvents.back());
102  topLevelEvents.pop_back();
103  }
104 
105  EventsIt it = findEvent(_name);
106  std::swap(*it, allEvents.back());
107  allEvents.pop_back();
108 
109  if (delayedNotify.scheduled())
111 }
112 
113 const std::string &
114 Event::name() const
115 {
116  return _name;
117 }
118 
119 const std::string &
121 {
122  return _basename;
123 }
124 
125 bool
127 {
128  return _inHierarchy;
129 }
130 
133 {
134  return parent;
135 }
136 
137 void
139 {
140  for (auto s: senses)
141  s->notify(this);
142 }
143 
144 void
146 {
147  int size = senses.size();
148  int pos = 0;
149  while (pos < size) {
150  if (senses[pos]->notify(this))
151  senses[pos] = senses[--size];
152  else
153  pos++;
154  }
155  senses.resize(size);
156 }
157 
158 void
160 {
161  if (scheduler.inUpdate())
163 
164  // An immediate notification overrides any pending delayed notification.
165  if (delayedNotify.scheduled())
167 
173 }
174 
175 void
177 {
178  if (delayedNotify.scheduled()) {
180  return;
181 
183  }
185 }
186 
187 void
189 {
190  if (delayedNotify.scheduled())
192  notify(t);
193 }
194 
195 void
197 {
198  if (delayedNotify.scheduled())
200 }
201 
202 bool
204 {
206 }
207 
208 void
210 {
211  if (!parent)
212  return;
214  parent = nullptr;
215  topLevelEvents.emplace(topLevelEvents.end(), sc_event());
216 }
217 
220 
221 EventsIt
222 findEvent(const std::string &name)
223 {
224  EventsIt it;
225  for (it = allEvents.begin(); it != allEvents.end(); it++)
226  if (!strcmp((*it)->name(), name.c_str()))
227  break;
228 
229  return it;
230 }
231 
232 } // namespace sc_gem5
sc_gem5::Event::getParentObject
sc_core::sc_object * getParentObject() const
Definition: event.cc:132
sc_gem5::ScEvent::when
void when(Tick w)
Definition: sched_event.hh:81
sc_gem5::globalNameGen
UniqueNameGen globalNameGen
Definition: module.cc:49
sc_gem5::pickParentObj
sc_core::sc_object * pickParentObj()
Definition: object.cc:310
sc_gem5::Scheduler::delayed
Tick delayed(const ::sc_core::sc_time &delay)
Definition: scheduler.hh:231
sc_gem5::Object::getFromScObject
static Object * getFromScObject(sc_core::sc_object *sc_obj)
Definition: object.hh:81
sc_gem5::Event::dynamicSenseThread
DynamicSensitivities dynamicSenseThread
Definition: event.hh:158
sc_gem5::Event::cancel
void cancel()
Definition: event.cc:196
module.hh
sc_gem5::Scheduler::deschedule
void deschedule(ScEvent *event)
Definition: scheduler.hh:263
sc_gem5::Event::notifyDelayed
void notifyDelayed(const sc_core::sc_time &t)
Definition: event.cc:188
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:360
sc_gem5::pickUniqueName
std::string pickUniqueName(::sc_core::sc_object *parent, std::string base)
Definition: object.cc:273
sc_gem5::UniqueNameGen::gen
const char * gen(std::string seed)
Definition: module.hh:60
sc_gem5::Event::~Event
~Event()
Definition: event.cc:92
sc_gem5::Event::delayedNotify
ScEvent delayedNotify
Definition: event.hh:152
sc_gem5::Scheduler::changeStamp
uint64_t changeStamp()
Definition: scheduler.hh:364
sc_gem5::Event::_triggeredStamp
uint64_t _triggeredStamp
Definition: event.hh:153
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_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
sc_gem5::Event::parent
sc_core::sc_object * parent
Definition: event.hh:150
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_main.hh
sc_gem5::Object
Definition: object.hh:47
sc_core::sc_time
Definition: sc_time.hh:49
sc_gem5::Event::Event
Event(sc_core::sc_event *_sc_event, bool internal=false)
Definition: event.cc:44
sc_gem5::allEvents
Events allEvents
Definition: event.cc:219
sc_gem5::Event::triggered
bool triggered() const
Definition: event.cc:203
sc_gem5::findEvent
EventsIt findEvent(const std::string &name)
Definition: event.cc:222
messages.hh
sc_core::sc_gen_unique_name
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
sc_gem5::Event::inHierarchy
bool inHierarchy() const
Definition: event.cc:126
sc_gem5::Event::staticSenseMethod
StaticSensitivities staticSenseMethod
Definition: event.hh:155
core.hh
sc_gem5::Event::_basename
std::string _basename
Definition: event.hh:146
sc_gem5::Event::name
const std::string & name() const
Definition: event.cc:114
sc_core::sc_object
Definition: sc_object.hh:50
name
const std::string & name()
Definition: trace.cc:50
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:209
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
sc_gem5::Event::dynamicSenseMethod
DynamicSensitivities dynamicSenseMethod
Definition: event.hh:157
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
sc_gem5::topLevelEvents
Events topLevelEvents
Definition: event.cc:218
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:238
sc_gem5
Definition: sc_clock.cc:42
event.hh
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:489
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
sc_gem5::Event::sc_event
sc_core::sc_event * sc_event()
Definition: event.hh:67
sc_gem5::Event::basename
const std::string & basename() const
Definition: event.cc:120
scheduler.hh
ULL
#define ULL(N)
uint64_t constant
Definition: types.hh:50
sc_gem5::Event::notify
void notify()
Definition: event.cc:159
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:142

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17