gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_spawn.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  * Authors: Gabe Black
28  */
29 
30 #ifndef __SYSTEMC_EXT_CORE_SC_SPAWN_HH__
31 #define __SYSTEMC_EXT_CORE_SC_SPAWN_HH__
32 
33 #include <functional>
34 #include <vector>
35 
36 #include "sc_join.hh"
37 #include "sc_process_handle.hh"
38 
39 namespace sc_core
40 {
41 
42 class sc_spawn_options;
43 
44 } // namespace sc_core
45 
46 namespace sc_gem5
47 {
48 
49 class Process;
50 
51 template <typename T>
53 {
54  T t;
55 
56  ProcessObjFuncWrapper(T t) : t(t) {}
57 
58  void call() override { t(); }
59 };
60 
61 template <typename T, typename R>
63 {
64  T t;
65  R *r;
66 
67  ProcessObjRetFuncWrapper(T t, R *r) : t(t), r(r) {}
68 
69  void call() override { *r = t(); }
70 };
71 
72 Process *spawnWork(ProcessFuncWrapper *func, const char *name,
73  const ::sc_core::sc_spawn_options *);
74 
75 } // namespace sc_gem5
76 
77 namespace sc_core
78 {
79 
80 template <class T>
81 class sc_in;
82 template <class T>
83 class sc_inout;
84 template <class T>
85 class sc_out;
86 template <class T>
87 class sc_signal_in_if;
88 
89 class sc_event;
90 class sc_event_finder;
91 class sc_export_base;
92 class sc_interface;
93 class sc_port_base;
94 
96 {
97  public:
98  friend ::sc_gem5::Process *::sc_gem5::spawnWork(
99  ::sc_gem5::ProcessFuncWrapper *, const char *,
100  const sc_spawn_options *);
101 
103 
104  void spawn_method();
105  void dont_initialize();
106  void set_stack_size(int);
107 
108  void set_sensitivity(const sc_event *);
109  void set_sensitivity(sc_port_base *);
110  void set_sensitivity(sc_export_base *);
111  void set_sensitivity(sc_interface *);
112  void set_sensitivity(sc_event_finder *);
113 
114  void reset_signal_is(const sc_in<bool> &, bool);
115  void reset_signal_is(const sc_inout<bool> &, bool);
116  void reset_signal_is(const sc_out<bool> &, bool);
117  void reset_signal_is(const sc_signal_in_if<bool> &, bool);
118 
119  void async_reset_signal_is(const sc_in<bool> &, bool);
120  void async_reset_signal_is(const sc_inout<bool> &, bool);
121  void async_reset_signal_is(const sc_out<bool> &, bool);
122  void async_reset_signal_is(const sc_signal_in_if<bool> &, bool);
123 
124  private:
133 
134  template <typename T>
135  struct Reset
136  {
137  Reset(T *t, bool v, bool s) : target(t), value(v), sync(s) {}
138 
139  T *target;
140  bool value;
141  bool sync;
142  };
143 
148 
149  // Disabled
151  sc_spawn_options &operator = (const sc_spawn_options &) { return *this; }
152 };
153 
154 template <typename T>
156 sc_spawn(T object, const char *name_p=nullptr,
157  const sc_spawn_options *opt_p=nullptr)
158 {
159  auto func = new ::sc_gem5::ProcessObjFuncWrapper<T>(object);
160  ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p);
161  return sc_process_handle() = p;
162 }
163 
164 template <typename T>
166 sc_spawn(typename T::result_type *r_p, T object, const char *name_p=nullptr,
167  const sc_spawn_options *opt_p=nullptr)
168 {
169  auto func = new ::sc_gem5::ProcessObjRetFuncWrapper<
170  T, typename T::result_type>(object, r_p);
171  ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p);
172  return sc_process_handle() = p;
173 }
174 
175 #define SC_FORK \
176 { \
177  ::sc_core::sc_process_handle forkees[] = {
178 
179 #define SC_JOIN \
180  }; \
181  ::sc_core::sc_join join; \
182  for (int i = 0; i < sizeof(forkees) / sizeof(forkees[0]); i++) \
183  join.add_process(forkees[i]); \
184  join.wait(); \
185 }
186 
187 // Non-standard
188 #define SC_CJOIN \
189  }; \
190  ::sc_core::sc_join join; \
191  for (int i = 0; i < sizeof(forkees) / sizeof(forkees[0]); i++) \
192  join.add_process(forkees[i]); \
193  join.wait_clocked(); \
194 }
195 
196 // This avoids boost introduces a dependency on c++11. If that's a problem,
197 // we could imitate Accellera and pick which one to use on the fly.
198 
199 template <typename F, typename... Args>
200 auto sc_bind(F &&f, Args && ...args) ->
201  decltype(std::bind(std::forward<F>(f), std::forward<Args>(args)...))
202 {
203  return std::bind(std::forward<F>(f), std::forward<Args>(args)...);
204 }
205 
206 template <typename T>
207 auto sc_ref(T &&v) -> decltype(std::ref(std::forward<T>(v)))
208 {
209  return std::ref(std::forward<T>(v));
210 }
211 
212 template <typename T>
213 auto sc_cref(T &&v) -> decltype(std::cref(std::forward<T>(v)))
214 {
215  return std::cref(std::forward<T>(v));
216 }
217 
218 } // namespace sc_core
219 
220 using sc_core::sc_bind;
221 using sc_core::sc_ref;
222 using sc_core::sc_cref;
223 
224 namespace sc_unnamed
225 {
226 
227 using namespace std::placeholders;
228 
229 } // namespace sc_unnamed
230 
231 #endif //__SYSTEMC_EXT_CORE_SC_SPAWN_HH__
Process * spawnWork(ProcessFuncWrapper *func, const char *name, const ::sc_core::sc_spawn_options *opts)
Definition: sc_spawn.cc:47
Bitfield< 28 > v
std::vector< sc_interface * > _interfaces
Definition: sc_spawn.hh:131
const std::string & name()
Definition: trace.cc:54
std::vector< sc_port_base * > _ports
Definition: sc_spawn.hh:129
std::vector< Reset< const sc_out< bool > > > _out_resets
Definition: sc_spawn.hh:146
std::vector< Reset< const sc_in< bool > > > _in_resets
Definition: sc_spawn.hh:144
sc_process_handle sc_spawn(T object, const char *name_p=nullptr, const sc_spawn_options *opt_p=nullptr)
Definition: sc_spawn.hh:156
std::vector< const sc_event * > _events
Definition: sc_spawn.hh:128
STL vector class.
Definition: stl.hh:40
Bitfield< 6 > f
sc_spawn_options(const sc_spawn_options &)
Definition: sc_spawn.hh:150
Bitfield< 4 > s
auto sc_ref(T &&v) -> decltype(std::ref(std::forward< T >(v)))
Definition: sc_spawn.hh:207
auto sc_cref(T &&v) -> decltype(std::cref(std::forward< T >(v)))
Definition: sc_spawn.hh:213
auto sc_bind(F &&f, Args &&...args) -> decltype(std::bind(std::forward< F >(f), std::forward< Args >(args)...))
Definition: sc_spawn.hh:200
std::vector< sc_export_base * > _exports
Definition: sc_spawn.hh:130
std::vector< Reset< const sc_signal_in_if< bool > > > _if_resets
Definition: sc_spawn.hh:147
std::vector< Reset< const sc_inout< bool > > > _inout_resets
Definition: sc_spawn.hh:145
Bitfield< 5 > t
R
Definition: int.hh:51
std::vector< sc_event_finder * > _finders
Definition: sc_spawn.hh:132
Bitfield< 0 > p
Reset(T *t, bool v, bool s)
Definition: sc_spawn.hh:137

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