gem5  v20.1.0.0
sc_event.hh
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 #ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
29 #define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
30 
31 #include <cassert>
32 #include <set>
33 #include <sstream>
34 #include <vector>
35 
36 #include "../channel/messages.hh"
37 #include "../utils/sc_report_handler.hh"
38 #include "sc_port.hh"
39 #include "sc_time.hh"
40 
41 namespace sc_gem5
42 {
43 
44 class Event;
45 class DynamicSensitivityEventAndList;
46 class DynamicSensitivityEventOrList;
47 class InternalScEvent;
48 
49 }
50 
51 namespace sc_core
52 {
53 
54 class sc_event;
55 class sc_event_and_expr;
56 class sc_event_or_expr;
57 class sc_interface;
58 class sc_object;
59 class sc_port_base;
60 
62 {
63  public:
66  sc_event_and_list(const sc_event &);
69 
70  int size() const;
71  void swap(sc_event_and_list &);
72 
75 
76  sc_event_and_expr operator & (const sc_event &) const;
78 
79  private:
80  friend class sc_event_and_expr;
82 
83  explicit sc_event_and_list(bool auto_delete);
84 
85  void insert(sc_event const &e);
86  void insert(sc_event_and_list const &eal);
87 
88  std::set<const sc_event *> events;
89  bool autoDelete;
90  mutable unsigned busy;
91 };
92 
94 {
95  public:
98  sc_event_or_list(const sc_event &);
101 
102  int size() const;
103  void swap(sc_event_or_list &);
104 
107 
108  sc_event_or_expr operator | (const sc_event &) const;
110 
111  private:
112  friend class sc_event_or_expr;
114 
115  explicit sc_event_or_list(bool auto_delete);
116 
117  void insert(sc_event const &e);
118  void insert(sc_event_or_list const &eol);
119 
120  std::set<const sc_event *> events;
122  mutable unsigned busy;
123 };
124 
126 {
127  public:
129  operator const sc_event_and_list &() const;
130 
131  void insert(sc_event const &e) const;
132  void insert(sc_event_and_list const &eal) const;
133 
135 
136  private:
137  friend class sc_event_and_list;
138  friend class sc_event;
139 
142 };
143 
146 
148 {
149  public:
151  operator const sc_event_or_list &() const;
152 
153  void insert(sc_event const &e) const;
154  void insert(sc_event_or_list const &eol) const;
155 
157 
158  private:
159  friend class sc_event_or_list;
160  friend class sc_event;
161 
164 };
165 
168 
169 class sc_event
170 {
171  public:
172  sc_event();
173  explicit sc_event(const char *);
174  ~sc_event();
175 
176  const char *name() const;
177  const char *basename() const;
178  bool in_hierarchy() const;
179  sc_object *get_parent_object() const;
180 
181  void notify();
182  void notify(const sc_time &);
183  void notify(double, sc_time_unit);
184  void cancel();
185 
186  // Nonstandard
187  // Returns whether this event is currently triggered.
188  bool triggered() const;
189 
190  // Deprecated
191  void notify_delayed();
192  void notify_delayed(const sc_time &);
193 
194  sc_event_and_expr operator & (const sc_event &) const;
196  sc_event_or_expr operator | (const sc_event &) const;
198 
199  protected:
200  explicit sc_event(bool);
201  explicit sc_event(bool, const char *);
202 
203  private:
204  // Disabled
205  sc_event(const sc_event &) {}
206  sc_event &operator = (const sc_event &) { return *this; }
207 
208  friend class ::sc_gem5::Event;
210 };
211 
213 {
214  protected:
215  virtual ~sc_event_finder() {}
216 
217  public:
218  // Should be "implementation defined" but used in the tests.
219  virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
220  virtual const sc_port_base *port() const = 0;
221 };
222 
223 template <class IF>
225 {
226  public:
228  const sc_event & (IF::*_method)() const) :
230  {
231  _port = dynamic_cast<const sc_port_b<IF> *>(&p);
232  assert(_port);
233  }
234 
235  virtual ~sc_event_finder_t() {}
236 
237  const sc_port_base *port() const override { return _port; }
238 
239  const sc_event &find_event(sc_interface *if_p=NULL) const override;
240 
241  private:
243  const sc_event &(IF::*_method)() const;
244 };
245 
247 sc_event *sc_find_event(const char *);
248 
249 } // namespace sc_core
250 
251 namespace sc_gem5
252 {
253 
255 {
256  public:
257  InternalScEvent();
258  InternalScEvent(const char *);
259 };
260 
261 } // namespace sc_gem5
262 
263 namespace sc_core
264 {
265 
266 template <class IF>
267 const sc_event &
269 {
270  static const sc_gem5::InternalScEvent none;
271  const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
272  dynamic_cast<const IF *>(_port->get_interface());
273  if (!iface) {
274  std::ostringstream ss;
275  ss << "port is not bound: port '" << _port->name() << "' (" <<
276  _port->kind() << ")";
277  SC_REPORT_ERROR(SC_ID_FIND_EVENT_, ss.str().c_str());
278  return none;
279  }
280  return (const_cast<IF *>(iface)->*_method)();
281 }
282 
283 } // namespace sc_core
284 
285 #endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
sc_core::sc_port_b
Definition: sc_port.hh:118
sc_core::sc_port_base
Definition: sc_port.hh:74
sc_core::sc_event_and_list::operator&=
sc_event_and_list & operator&=(const sc_event &)
Definition: sc_event.cc:77
sc_gem5::DynamicSensitivityEventAndList
Definition: sensitivity.hh:284
sc_core::sc_event_or_list::size
int size() const
Definition: sc_event.cc:150
sc_core::sc_event::get_parent_object
sc_object * get_parent_object() const
Definition: sc_event.cc:332
sc_core::SC_ID_FIND_EVENT_
const char SC_ID_FIND_EVENT_[]
Definition: messages.cc:57
sc_core::operator|
sc_event_or_expr operator|(sc_event_or_expr expr, sc_event const &e)
Definition: sc_event.cc:294
sc_core::sc_event_and_list::size
int size() const
Definition: sc_event.cc:65
sc_core::sc_event_or_list::operator|=
sc_event_or_list & operator|=(const sc_event &)
Definition: sc_event.cc:162
sc_core::sc_event::in_hierarchy
bool in_hierarchy() const
Definition: sc_event.cc:329
sc_core::sc_event_finder_t::_port
const sc_port_b< IF > * _port
Definition: sc_event.hh:242
sc_core
Definition: messages.cc:31
sc_core::sc_time_unit
sc_time_unit
Definition: sc_time.hh:40
sc_core::sc_event_or_expr
Definition: sc_event.hh:147
sc_core::sc_event::basename
const char * basename() const
Definition: sc_event.cc:325
sc_core::sc_event_and_expr::~sc_event_and_expr
~sc_event_and_expr()
Definition: sc_event.cc:238
sc_core::sc_event_and_list
Definition: sc_event.hh:61
sc_core::sc_interface
Definition: sc_interface.hh:37
sc_gem5::Event
Definition: event.hh:58
sc_core::sc_event_or_list
Definition: sc_event.hh:93
sc_port.hh
sc_core::sc_event_or_expr::insert
void insert(sc_event const &e) const
Definition: sc_event.cc:276
sc_core::sc_event_or_list::operator=
sc_event_or_list & operator=(const sc_event_or_list &)
Definition: sc_event.cc:141
sc_core::sc_event::~sc_event
~sc_event()
Definition: sc_event.cc:321
std::vector
STL vector class.
Definition: stl.hh:37
sc_core::sc_event_or_expr::sc_event_or_expr
sc_event_or_expr()
Definition: sc_event.cc:291
sc_core::sc_event_or_list::operator|
sc_event_or_expr operator|(const sc_event &) const
Definition: sc_event.cc:176
Stats::none
const FlagsType none
Nothing extra to print.
Definition: info.hh:43
sc_core::sc_find_event
sc_event * sc_find_event(const char *name)
Definition: sc_event.cc:409
sc_core::sc_event_or_list::insert
void insert(sc_event const &e)
Definition: sc_event.cc:194
sc_core::sc_event_and_list::swap
void swap(sc_event_and_list &)
Definition: sc_event.cc:71
sc_core::sc_event_and_list::operator&
sc_event_and_expr operator&(const sc_event &) const
Definition: sc_event.cc:91
sc_core::sc_event_or_list::busy
unsigned busy
Definition: sc_event.hh:122
sc_core::sc_event_and_list::operator=
sc_event_and_list & operator=(const sc_event_and_list &)
Definition: sc_event.cc:58
sc_core::sc_event::notify_delayed
void notify_delayed()
Definition: sc_event.cc:343
sc_gem5::InternalScEvent
Definition: sc_event.hh:254
ArmISA::ss
Bitfield< 21 > ss
Definition: miscregs_types.hh:56
sc_core::sc_event_and_expr::insert
void insert(sc_event const &e) const
Definition: sc_event.cc:225
sc_core::operator&
sc_event_and_expr operator&(sc_event_and_expr expr, sc_event const &e)
Definition: sc_event.cc:243
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
Event
Definition: eventq.hh:246
sc_gem5::DynamicSensitivityEventOrList
Definition: sensitivity.hh:268
sc_core::sc_event
Definition: sc_event.hh:169
sc_core::sc_event_finder_t::~sc_event_finder_t
virtual ~sc_event_finder_t()
Definition: sc_event.hh:235
sc_core::sc_event_and_expr
Definition: sc_event.hh:125
sc_core::sc_event_finder_t::_method
const sc_event &(IF::* _method)() const
Definition: sc_event.hh:243
sc_core::sc_time
Definition: sc_time.hh:49
sc_core::sc_event::name
const char * name() const
Definition: sc_event.cc:323
sc_core::sc_event::triggered
bool triggered() const
Definition: sc_event.cc:341
sc_core::sc_event_or_list::~sc_event_or_list
~sc_event_or_list()
Definition: sc_event.cc:147
sc_core::sc_event::operator|
sc_event_or_expr operator|(const sc_event &) const
Definition: sc_event.cc:372
sc_core::sc_event_finder_t::find_event
const sc_event & find_event(sc_interface *if_p=NULL) const override
Definition: sc_event.hh:268
sc_core::sc_event_and_list::insert
void insert(sc_event const &e)
Definition: sc_event.cc:109
sc_core::sc_event_finder_t
Definition: sc_event.hh:224
sc_core::sc_object
Definition: sc_object.hh:50
sc_core::sc_event_finder::find_event
virtual const sc_event & find_event(sc_interface *if_p=NULL) const =0
sc_core::sc_event::notify
void notify()
Definition: sc_event.cc:337
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
sc_core::sc_event_finder_t::port
const sc_port_base * port() const override
Definition: sc_event.hh:237
sc_core::sc_event_and_list::events
std::set< const sc_event * > events
Definition: sc_event.hh:88
sc_core::sc_event_and_list::sc_event_and_list
sc_event_and_list()
Definition: sc_event.cc:40
sc_core::sc_event_and_list::busy
unsigned busy
Definition: sc_event.hh:90
sc_core::sc_event_or_expr::~sc_event_or_expr
~sc_event_or_expr()
Definition: sc_event.cc:289
sc_core::sc_event_finder_t::sc_event_finder_t
sc_event_finder_t(const sc_port_base &p, const sc_event &(IF::*_method)() const)
Definition: sc_event.hh:227
sc_core::sc_event_or_list::autoDelete
bool autoDelete
Definition: sc_event.hh:121
sc_core::sc_event_and_expr::sc_event_and_expr
sc_event_and_expr()
Definition: sc_event.cc:240
sc_core::sc_event::cancel
void cancel()
Definition: sc_event.cc:340
sc_gem5::InternalScEvent::InternalScEvent
InternalScEvent()
Definition: sc_event.cc:421
sc_core::sc_event::_gem5_event
::sc_gem5::Event * _gem5_event
Definition: sc_event.hh:209
sc_core::sc_event_or_list::events
std::set< const sc_event * > events
Definition: sc_event.hh:120
sc_core::sc_event_finder::port
virtual const sc_port_base * port() const =0
sc_core::sc_event_finder::~sc_event_finder
virtual ~sc_event_finder()
Definition: sc_event.hh:215
sc_core::sc_event::operator=
sc_event & operator=(const sc_event &)
Definition: sc_event.hh:206
sc_core::sc_event_and_list::autoDelete
bool autoDelete
Definition: sc_event.hh:89
sc_gem5
Definition: sc_clock.cc:42
sc_core::sc_event_finder
Definition: sc_event.hh:212
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
sc_core::sc_event_or_list::swap
void swap(sc_event_or_list &)
Definition: sc_event.cc:156
sc_time.hh
sc_core::sc_event_and_expr::list
sc_event_and_list * list
Definition: sc_event.hh:141
sc_core::sc_event_or_expr::list
sc_event_or_list * list
Definition: sc_event.hh:163
sc_core::sc_event::sc_event
sc_event(const sc_event &)
Definition: sc_event.hh:205
sc_core::sc_event_or_list::sc_event_or_list
sc_event_or_list()
Definition: sc_event.cc:125
sc_core::sc_get_top_level_events
const std::vector< sc_event * > & sc_get_top_level_events()
Definition: sc_event.cc:403
sc_core::sc_event::sc_event
sc_event()
Definition: sc_event.cc:312
sc_core::sc_event_and_list::~sc_event_and_list
~sc_event_and_list()
Definition: sc_event.cc:55
sc_core::sc_event::operator&
sc_event_and_expr operator&(const sc_event &) const
Definition: sc_event.cc:354

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