sc_event.hh (13132:1fb4a87f550f) sc_event.hh (13206:c944ef4abb48)
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#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
31#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
32
33#include <cassert>
34#include <set>
35#include <vector>
36
37#include "sc_port.hh"
38#include "sc_time.hh"
39
40namespace sc_gem5
41{
42
43class Event;
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#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
31#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
32
33#include <cassert>
34#include <set>
35#include <vector>
36
37#include "sc_port.hh"
38#include "sc_time.hh"
39
40namespace sc_gem5
41{
42
43class Event;
44class SensitivityEventAndList;
45class SensitivityEventOrList;
44class DynamicSensitivityEventAndList;
45class DynamicSensitivityEventOrList;
46
47}
48
49namespace sc_core
50{
51
52class sc_event;
53class sc_event_and_expr;
54class sc_event_or_expr;
55class sc_interface;
56class sc_object;
57class sc_port_base;
58
59class sc_event_finder
60{
61 protected:
62 virtual ~sc_event_finder() {}
63
64 public:
65 // Should be "implementation defined" but used in the tests.
66 virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
67 virtual const sc_port_base *port() const = 0;
68};
69
70template <class IF>
71class sc_event_finder_t : public sc_event_finder
72{
73 public:
74 sc_event_finder_t(const sc_port_base &p,
75 const sc_event & (IF::*_method)() const) :
76 _method(_method)
77 {
78 _port = dynamic_cast<const sc_port_b<IF> *>(&p);
79 assert(_port);
80 }
81
82 virtual ~sc_event_finder_t() {}
83
84 const sc_port_base *port() const { return _port; }
85
86 const sc_event &
87 find_event(sc_interface *if_p=NULL) const override
88 {
89 const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
90 dynamic_cast<const IF *>(_port->get_interface());
91 return (const_cast<IF *>(iface)->*_method)();
92 }
93
94 private:
95 const sc_port_b<IF> *_port;
96 const sc_event &(IF::*_method)() const;
97};
98
99class sc_event_and_list
100{
101 public:
102 sc_event_and_list();
103 sc_event_and_list(const sc_event_and_list &);
104 sc_event_and_list(const sc_event &);
105 sc_event_and_list &operator = (const sc_event_and_list &);
106 ~sc_event_and_list();
107
108 int size() const;
109 void swap(sc_event_and_list &);
110
111 sc_event_and_list &operator &= (const sc_event &);
112 sc_event_and_list &operator &= (const sc_event_and_list &);
113
114 sc_event_and_expr operator & (const sc_event &) const;
115 sc_event_and_expr operator & (const sc_event_and_list &);
116
117 private:
118 friend class sc_event_and_expr;
46
47}
48
49namespace sc_core
50{
51
52class sc_event;
53class sc_event_and_expr;
54class sc_event_or_expr;
55class sc_interface;
56class sc_object;
57class sc_port_base;
58
59class sc_event_finder
60{
61 protected:
62 virtual ~sc_event_finder() {}
63
64 public:
65 // Should be "implementation defined" but used in the tests.
66 virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
67 virtual const sc_port_base *port() const = 0;
68};
69
70template <class IF>
71class sc_event_finder_t : public sc_event_finder
72{
73 public:
74 sc_event_finder_t(const sc_port_base &p,
75 const sc_event & (IF::*_method)() const) :
76 _method(_method)
77 {
78 _port = dynamic_cast<const sc_port_b<IF> *>(&p);
79 assert(_port);
80 }
81
82 virtual ~sc_event_finder_t() {}
83
84 const sc_port_base *port() const { return _port; }
85
86 const sc_event &
87 find_event(sc_interface *if_p=NULL) const override
88 {
89 const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
90 dynamic_cast<const IF *>(_port->get_interface());
91 return (const_cast<IF *>(iface)->*_method)();
92 }
93
94 private:
95 const sc_port_b<IF> *_port;
96 const sc_event &(IF::*_method)() const;
97};
98
99class sc_event_and_list
100{
101 public:
102 sc_event_and_list();
103 sc_event_and_list(const sc_event_and_list &);
104 sc_event_and_list(const sc_event &);
105 sc_event_and_list &operator = (const sc_event_and_list &);
106 ~sc_event_and_list();
107
108 int size() const;
109 void swap(sc_event_and_list &);
110
111 sc_event_and_list &operator &= (const sc_event &);
112 sc_event_and_list &operator &= (const sc_event_and_list &);
113
114 sc_event_and_expr operator & (const sc_event &) const;
115 sc_event_and_expr operator & (const sc_event_and_list &);
116
117 private:
118 friend class sc_event_and_expr;
119 friend class sc_gem5::SensitivityEventAndList;
119 friend class sc_gem5::DynamicSensitivityEventAndList;
120
121 explicit sc_event_and_list(bool auto_delete);
122
123 void insert(sc_event const &e);
124 void insert(sc_event_and_list const &eal);
125
126 std::set<const sc_event *> events;
127 bool autoDelete;
128 mutable unsigned busy;
129};
130
131class sc_event_or_list
132{
133 public:
134 sc_event_or_list();
135 sc_event_or_list(const sc_event_or_list &);
136 sc_event_or_list(const sc_event &);
137 sc_event_or_list& operator = (const sc_event_or_list &);
138 ~sc_event_or_list();
139
140 int size() const;
141 void swap(sc_event_or_list &);
142
143 sc_event_or_list &operator |= (const sc_event &);
144 sc_event_or_list &operator |= (const sc_event_or_list &);
145
146 sc_event_or_expr operator | (const sc_event &) const;
147 sc_event_or_expr operator | (const sc_event_or_list &) const;
148
149 private:
150 friend class sc_event_or_expr;
120
121 explicit sc_event_and_list(bool auto_delete);
122
123 void insert(sc_event const &e);
124 void insert(sc_event_and_list const &eal);
125
126 std::set<const sc_event *> events;
127 bool autoDelete;
128 mutable unsigned busy;
129};
130
131class sc_event_or_list
132{
133 public:
134 sc_event_or_list();
135 sc_event_or_list(const sc_event_or_list &);
136 sc_event_or_list(const sc_event &);
137 sc_event_or_list& operator = (const sc_event_or_list &);
138 ~sc_event_or_list();
139
140 int size() const;
141 void swap(sc_event_or_list &);
142
143 sc_event_or_list &operator |= (const sc_event &);
144 sc_event_or_list &operator |= (const sc_event_or_list &);
145
146 sc_event_or_expr operator | (const sc_event &) const;
147 sc_event_or_expr operator | (const sc_event_or_list &) const;
148
149 private:
150 friend class sc_event_or_expr;
151 friend class sc_gem5::SensitivityEventOrList;
151 friend class sc_gem5::DynamicSensitivityEventOrList;
152
153 explicit sc_event_or_list(bool auto_delete);
154
155 void insert(sc_event const &e);
156 void insert(sc_event_or_list const &eol);
157
158 std::set<const sc_event *> events;
159 bool autoDelete;
160 mutable unsigned busy;
161};
162
163class sc_event_and_expr
164{
165 public:
166 sc_event_and_expr(sc_event_and_expr const &e);
167 operator const sc_event_and_list &() const;
168
169 void insert(sc_event const &e) const;
170 void insert(sc_event_and_list const &eal) const;
171
172 ~sc_event_and_expr();
173
174 private:
175 friend class sc_event_and_list;
176 friend class sc_event;
177
178 sc_event_and_expr();
179 mutable sc_event_and_list *list;
180};
181
182sc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
183sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
184
185class sc_event_or_expr
186{
187 public:
188 sc_event_or_expr(sc_event_or_expr const &e);
189 operator const sc_event_or_list &() const;
190
191 void insert(sc_event const &e) const;
192 void insert(sc_event_or_list const &eol) const;
193
194 ~sc_event_or_expr();
195
196 private:
197 friend class sc_event_or_list;
198 friend class sc_event;
199
200 sc_event_or_expr();
201 mutable sc_event_or_list *list;
202};
203
204sc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
205sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
206
207class sc_event
208{
209 public:
210 sc_event();
211 explicit sc_event(const char *);
212 ~sc_event();
213
214 const char *name() const;
215 const char *basename() const;
216 bool in_hierarchy() const;
217 sc_object *get_parent_object() const;
218
219 void notify();
220 void notify(const sc_time &);
221 void notify(double, sc_time_unit);
222 void cancel();
223
224 // Nonstandard
225 // Returns whether this event is currently triggered.
226 bool triggered() const;
227
228 // Deprecated
229 void notify_delayed();
230 void notify_delayed(const sc_time &);
231
232 sc_event_and_expr operator & (const sc_event &) const;
233 sc_event_and_expr operator & (const sc_event_and_list &) const;
234 sc_event_or_expr operator | (const sc_event &) const;
235 sc_event_or_expr operator | (const sc_event_or_list &) const;
236
237 private:
238 // Disabled
239 sc_event(const sc_event &) {}
240 sc_event &operator = (const sc_event &) { return *this; }
241
242 friend class ::sc_gem5::Event;
243 ::sc_gem5::Event *_gem5_event;
244};
245
246const std::vector<sc_event *> &sc_get_top_level_events();
247sc_event *sc_find_event(const char *);
248
249} // namespace sc_core
250
251#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
152
153 explicit sc_event_or_list(bool auto_delete);
154
155 void insert(sc_event const &e);
156 void insert(sc_event_or_list const &eol);
157
158 std::set<const sc_event *> events;
159 bool autoDelete;
160 mutable unsigned busy;
161};
162
163class sc_event_and_expr
164{
165 public:
166 sc_event_and_expr(sc_event_and_expr const &e);
167 operator const sc_event_and_list &() const;
168
169 void insert(sc_event const &e) const;
170 void insert(sc_event_and_list const &eal) const;
171
172 ~sc_event_and_expr();
173
174 private:
175 friend class sc_event_and_list;
176 friend class sc_event;
177
178 sc_event_and_expr();
179 mutable sc_event_and_list *list;
180};
181
182sc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
183sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
184
185class sc_event_or_expr
186{
187 public:
188 sc_event_or_expr(sc_event_or_expr const &e);
189 operator const sc_event_or_list &() const;
190
191 void insert(sc_event const &e) const;
192 void insert(sc_event_or_list const &eol) const;
193
194 ~sc_event_or_expr();
195
196 private:
197 friend class sc_event_or_list;
198 friend class sc_event;
199
200 sc_event_or_expr();
201 mutable sc_event_or_list *list;
202};
203
204sc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
205sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
206
207class sc_event
208{
209 public:
210 sc_event();
211 explicit sc_event(const char *);
212 ~sc_event();
213
214 const char *name() const;
215 const char *basename() const;
216 bool in_hierarchy() const;
217 sc_object *get_parent_object() const;
218
219 void notify();
220 void notify(const sc_time &);
221 void notify(double, sc_time_unit);
222 void cancel();
223
224 // Nonstandard
225 // Returns whether this event is currently triggered.
226 bool triggered() const;
227
228 // Deprecated
229 void notify_delayed();
230 void notify_delayed(const sc_time &);
231
232 sc_event_and_expr operator & (const sc_event &) const;
233 sc_event_and_expr operator & (const sc_event_and_list &) const;
234 sc_event_or_expr operator | (const sc_event &) const;
235 sc_event_or_expr operator | (const sc_event_or_list &) const;
236
237 private:
238 // Disabled
239 sc_event(const sc_event &) {}
240 sc_event &operator = (const sc_event &) { return *this; }
241
242 friend class ::sc_gem5::Event;
243 ::sc_gem5::Event *_gem5_event;
244};
245
246const std::vector<sc_event *> &sc_get_top_level_events();
247sc_event *sc_find_event(const char *);
248
249} // namespace sc_core
250
251#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__