gem5  v20.0.0.2
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 "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(); }),
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) {
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()) {
179  if (scheduler.delayed(t) >= delayedNotify.when())
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
std::string _name
Definition: event.hh:147
bool sc_is_running()
Definition: sc_main.cc:142
sc_core::sc_event * sc_event()
Definition: event.hh:67
sc_core::sc_object * getParentObject() const
Definition: event.cc:132
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
sc_core::sc_object * parent
Definition: event.hh:150
uint64_t _triggeredStamp
Definition: event.hh:153
const char * name() const
Definition: sc_object.cc:44
#define SC_REPORT_WARNING(msg_type, msg)
EventsIt findEvent(const std::string &name)
Definition: event.cc:222
STL vector class.
Definition: stl.hh:37
std::string pickUniqueName(::sc_core::sc_object *parent, std::string base)
Definition: object.cc:273
bool inHierarchy() const
Definition: event.cc:126
UniqueNameGen globalNameGen
Definition: module.cc:49
bool triggered() const
Definition: event.cc:203
void notifyDelayed(const sc_core::sc_time &t)
Definition: event.cc:188
const char SC_ID_INSTANCE_EXISTS_[]
Definition: messages.cc:39
Bitfield< 4 > s
StaticSensitivities staticSenseMethod
Definition: event.hh:155
ScEvent delayedNotify
Definition: event.hh:152
void deschedule(ScEvent *event)
Definition: scheduler.hh:263
Events allEvents
Definition: event.cc:219
sc_core::sc_object * pickParentObj()
Definition: object.cc:310
Events topLevelEvents
Definition: event.cc:218
Scheduler scheduler
Definition: scheduler.cc:489
const char * gen(std::string seed)
Definition: module.hh:60
void delChildEvent(sc_core::sc_event *e)
Definition: object.cc:254
uint64_t changeStamp()
Definition: scheduler.hh:364
#define ULL(N)
uint64_t constant
Definition: types.hh:48
void when(Tick w)
Definition: sched_event.hh:81
StaticSensitivities staticSenseThread
Definition: event.hh:156
Event(sc_core::sc_event *_sc_event, bool internal=false)
Definition: event.cc:44
const std::string & basename() const
Definition: event.cc:120
Tick delayed(const ::sc_core::sc_time &delay)
Definition: scheduler.hh:231
std::string _basename
Definition: event.hh:146
#define SC_REPORT_ERROR(msg_type, msg)
EventsIt addChildEvent(sc_core::sc_event *e)
Definition: object.cc:248
void notify()
Definition: event.cc:159
DynamicSensitivities dynamicSenseThread
Definition: event.hh:158
sc_core::sc_event * _sc_event
Definition: event.hh:144
Events::iterator EventsIt
Definition: object.hh:45
const std::string & name() const
Definition: event.cc:114
Bitfield< 5 > t
void clearParent()
Definition: event.cc:209
bool _inHierarchy
Definition: event.hh:148
void schedule(ScEvent *event, const ::sc_core::sc_time &delay)
Definition: scheduler.hh:238
DynamicSensitivities dynamicSenseMethod
Definition: event.hh:157
const char SC_ID_IMMEDIATE_NOTIFICATION_[]
Definition: messages.cc:66
void cancel()
Definition: event.cc:196
const char SC_ID_NOTIFY_DELAYED_[]
Definition: messages.cc:79
static Object * getFromScObject(sc_core::sc_object *sc_obj)
Definition: object.hh:81

Generated on Mon Jun 8 2020 15:45:12 for gem5 by doxygen 1.8.13