gem5  v19.0.0.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  * Authors: Gabe Black
28  */
29 
30 #include "systemc/core/event.hh"
31 
32 #include <algorithm>
33 #include <cstring>
34 #include <utility>
35 
36 #include "sim/core.hh"
37 #include "systemc/core/module.hh"
42 
43 namespace sc_gem5
44 {
45 
46 Event::Event(sc_core::sc_event *_sc_event, bool internal) :
47  Event(_sc_event, nullptr, internal)
48 {}
49 
50 Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr,
51  bool internal) :
52  _sc_event(_sc_event), _basename(_basename_cstr ? _basename_cstr : ""),
53  _inHierarchy(!internal), delayedNotify([this]() { this->notify(); }),
55 {
56  if (_basename == "" && ::sc_core::sc_is_running())
58 
59  parent = internal ? nullptr : pickParentObj();
60 
61  if (internal) {
63  _name = _basename;
64  } else {
65  std::string original_name = _basename;
67 
68  if (parent) {
71  } else {
72  topLevelEvents.emplace(topLevelEvents.end(), _sc_event);
73  }
74 
75  std::string path = parent ? (std::string(parent->name()) + ".") : "";
76 
77  if (original_name != "" && _basename != original_name) {
78  std::string message = path + original_name +
79  ". Latter declaration will be renamed to " +
80  path + _basename;
82  message.c_str());
83  }
84 
85  _name = path + _basename;
86  }
87 
88  allEvents.emplace(allEvents.end(), _sc_event);
89 
90  // Determine if we're in the hierarchy (created once initialization starts
91  // means no).
92 }
93 
95 {
96  if (parent) {
99  } else if (inHierarchy()) {
100  EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(),
101  _sc_event);
102  assert(it != topLevelEvents.end());
103  std::swap(*it, topLevelEvents.back());
104  topLevelEvents.pop_back();
105  }
106 
107  EventsIt it = findEvent(_name);
108  std::swap(*it, allEvents.back());
109  allEvents.pop_back();
110 
111  if (delayedNotify.scheduled())
113 }
114 
115 const std::string &
116 Event::name() const
117 {
118  return _name;
119 }
120 
121 const std::string &
123 {
124  return _basename;
125 }
126 
127 bool
129 {
130  return _inHierarchy;
131 }
132 
135 {
136  return parent;
137 }
138 
139 void
141 {
142  for (auto s: senses)
143  s->notify(this);
144 }
145 
146 void
148 {
149  int size = senses.size();
150  int pos = 0;
151  while (pos < size) {
152  if (senses[pos]->notify(this))
153  senses[pos] = senses[--size];
154  else
155  pos++;
156  }
157  senses.resize(size);
158 }
159 
160 void
162 {
163  if (scheduler.inUpdate())
165 
166  // An immediate notification overrides any pending delayed notification.
167  if (delayedNotify.scheduled())
169 
175 }
176 
177 void
179 {
180  if (delayedNotify.scheduled()) {
181  if (scheduler.delayed(t) >= delayedNotify.when())
182  return;
183 
185  }
187 }
188 
189 void
191 {
192  if (delayedNotify.scheduled())
194  notify(t);
195 }
196 
197 void
199 {
200  if (delayedNotify.scheduled())
202 }
203 
204 bool
206 {
208 }
209 
210 void
212 {
213  if (!parent)
214  return;
216  parent = nullptr;
217  topLevelEvents.emplace(topLevelEvents.end(), sc_event());
218 }
219 
222 
223 EventsIt
224 findEvent(const std::string &name)
225 {
226  EventsIt it;
227  for (it = allEvents.begin(); it != allEvents.end(); it++)
228  if (!strcmp((*it)->name(), name.c_str()))
229  break;
230 
231  return it;
232 }
233 
234 } // namespace sc_gem5
std::string _name
Definition: event.hh:149
bool sc_is_running()
Definition: sc_main.cc:144
sc_core::sc_event * sc_event()
Definition: event.hh:69
sc_core::sc_object * getParentObject() const
Definition: event.cc:134
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:822
sc_core::sc_object * parent
Definition: event.hh:152
uint64_t _triggeredStamp
Definition: event.hh:155
const char * name() const
Definition: sc_object.cc:46
#define SC_REPORT_WARNING(msg_type, msg)
EventsIt findEvent(const std::string &name)
Definition: event.cc:224
STL vector class.
Definition: stl.hh:40
std::string pickUniqueName(::sc_core::sc_object *parent, std::string base)
Definition: object.cc:275
bool inHierarchy() const
Definition: event.cc:128
UniqueNameGen globalNameGen
Definition: module.cc:51
bool triggered() const
Definition: event.cc:205
void notifyDelayed(const sc_core::sc_time &t)
Definition: event.cc:190
const char SC_ID_INSTANCE_EXISTS_[]
Definition: messages.cc:41
Bitfield< 4 > s
StaticSensitivities staticSenseMethod
Definition: event.hh:157
ScEvent delayedNotify
Definition: event.hh:154
void deschedule(ScEvent *event)
Definition: scheduler.hh:265
Events allEvents
Definition: event.cc:221
sc_core::sc_object * pickParentObj()
Definition: object.cc:312
Events topLevelEvents
Definition: event.cc:220
Scheduler scheduler
Definition: scheduler.cc:491
const char * gen(std::string seed)
Definition: module.hh:62
void delChildEvent(sc_core::sc_event *e)
Definition: object.cc:256
uint64_t changeStamp()
Definition: scheduler.hh:366
#define ULL(N)
uint64_t constant
Definition: types.hh:50
void when(Tick w)
Definition: sched_event.hh:83
StaticSensitivities staticSenseThread
Definition: event.hh:158
Event(sc_core::sc_event *_sc_event, bool internal=false)
Definition: event.cc:46
const std::string & basename() const
Definition: event.cc:122
Tick delayed(const ::sc_core::sc_time &delay)
Definition: scheduler.hh:233
std::string _basename
Definition: event.hh:148
#define SC_REPORT_ERROR(msg_type, msg)
EventsIt addChildEvent(sc_core::sc_event *e)
Definition: object.cc:250
void notify()
Definition: event.cc:161
DynamicSensitivities dynamicSenseThread
Definition: event.hh:160
sc_core::sc_event * _sc_event
Definition: event.hh:146
Events::iterator EventsIt
Definition: object.hh:47
const std::string & name() const
Definition: event.cc:116
Bitfield< 5 > t
void clearParent()
Definition: event.cc:211
bool _inHierarchy
Definition: event.hh:150
void schedule(ScEvent *event, const ::sc_core::sc_time &delay)
Definition: scheduler.hh:240
DynamicSensitivities dynamicSenseMethod
Definition: event.hh:159
const char SC_ID_IMMEDIATE_NOTIFICATION_[]
Definition: messages.cc:68
void cancel()
Definition: event.cc:198
const char SC_ID_NOTIFY_DELAYED_[]
Definition: messages.cc:81
static Object * getFromScObject(sc_core::sc_object *sc_obj)
Definition: object.hh:83

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13