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

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