gem5  v22.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_event_and_list * list
Definition: sc_event.hh:141
void insert(sc_event const &e) const
Definition: sc_event.cc:225
void swap(sc_event_and_list &)
Definition: sc_event.cc:71
void insert(sc_event const &e)
Definition: sc_event.cc:109
sc_event_and_list & operator=(const sc_event_and_list &)
Definition: sc_event.cc:58
sc_event_and_list & operator&=(const sc_event &)
Definition: sc_event.cc:77
std::set< const sc_event * > events
Definition: sc_event.hh:88
sc_event_and_expr operator&(const sc_event &) const
Definition: sc_event.cc:91
sc_event_finder_t(const sc_port_base &p, const sc_event &(IF::*_method)() const)
Definition: sc_event.hh:227
const sc_event &(IF::* _method)() const
Definition: sc_event.hh:243
const sc_port_base * port() const override
Definition: sc_event.hh:237
const sc_event & find_event(sc_interface *if_p=NULL) const override
Definition: sc_event.hh:268
const sc_port_b< IF > * _port
Definition: sc_event.hh:242
virtual const sc_port_base * port() const =0
virtual ~sc_event_finder()
Definition: sc_event.hh:215
virtual const sc_event & find_event(sc_interface *if_p=NULL) const =0
void insert(sc_event const &e) const
Definition: sc_event.cc:276
sc_event_or_list * list
Definition: sc_event.hh:163
sc_event_or_expr operator|(const sc_event &) const
Definition: sc_event.cc:176
sc_event_or_list & operator|=(const sc_event &)
Definition: sc_event.cc:162
void insert(sc_event const &e)
Definition: sc_event.cc:194
std::set< const sc_event * > events
Definition: sc_event.hh:120
sc_event_or_list & operator=(const sc_event_or_list &)
Definition: sc_event.cc:141
void swap(sc_event_or_list &)
Definition: sc_event.cc:156
bool triggered() const
Definition: sc_event.cc:341
const char * basename() const
Definition: sc_event.cc:325
const char * name() const
Definition: sc_event.cc:323
bool in_hierarchy() const
Definition: sc_event.cc:329
sc_object * get_parent_object() const
Definition: sc_event.cc:332
sc_event(const sc_event &)
Definition: sc_event.hh:205
sc_event & operator=(const sc_event &)
Definition: sc_event.hh:206
void notify_delayed()
Definition: sc_event.cc:343
sc_event_or_expr operator|(const sc_event &) const
Definition: sc_event.cc:372
::sc_gem5::Event * _gem5_event
Definition: sc_event.hh:209
sc_event_and_expr operator&(const sc_event &) const
Definition: sc_event.cc:354
STL vector class.
Definition: stl.hh:37
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 54 > p
Definition: pagetable.hh:70
const FlagsType none
Nothing extra to print.
Definition: info.hh:54
sc_event_or_expr operator|(sc_event_or_expr expr, sc_event const &e)
Definition: sc_event.cc:294
const std::vector< sc_event * > & sc_get_top_level_events()
Definition: sc_event.cc:403
sc_event * sc_find_event(const char *name)
Definition: sc_event.cc:409
const char SC_ID_FIND_EVENT_[]
Definition: messages.cc:57
sc_time_unit
Definition: sc_time.hh:40
sc_event_and_expr operator&(sc_event_and_expr expr, sc_event const &e)
Definition: sc_event.cc:243
#define SC_REPORT_ERROR(msg_type, msg)
std::stringstream ss
Definition: trace.test.cc:45

Generated on Wed Dec 21 2022 10:22:41 for gem5 by doxygen 1.9.1