gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
37namespace sc_core
38{
39
40class sc_spawn_options;
41
42} // namespace sc_core
43
44namespace sc_gem5
45{
46
47class Process;
48
49template <typename T>
51{
52 T t;
53
55
56 void call() override { t(); }
57};
58
59template <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
70Process *spawnWork(ProcessFuncWrapper *func, const char *name,
71 const ::sc_core::sc_spawn_options *);
72
73} // namespace sc_gem5
74
75namespace sc_core
76{
77
78template <class T>
79class sc_in;
80template <class T>
82template <class T>
83class sc_out;
84template <class T>
85class sc_signal_in_if;
86
87class sc_event;
88class sc_event_finder;
89class sc_export_base;
90class sc_interface;
91class 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);
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
138 bool value;
139 bool sync;
140 };
141
146
147 // Disabled
150};
151
152template <typename T>
153sc_process_handle
154sc_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
162template <typename T>
163sc_process_handle
164sc_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
197template <typename F, typename... Args>
198auto 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
204template <typename T>
205auto sc_ref(T &&v) -> decltype(std::ref(std::forward<T>(v)))
206{
207 return std::ref(std::forward<T>(v));
208}
209
210template <typename T>
211auto 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
218using sc_core::sc_bind;
219using sc_core::sc_ref;
220using sc_core::sc_cref;
221
222namespace sc_unnamed
223{
224
225using namespace std::placeholders;
226
227} // namespace sc_unnamed
228
229#endif //__SYSTEMC_EXT_CORE_SC_SPAWN_HH__
std::vector< const sc_event * > _events
Definition sc_spawn.hh:126
std::vector< sc_port_base * > _ports
Definition sc_spawn.hh:127
sc_spawn_options(const sc_spawn_options &)
Definition sc_spawn.hh:148
std::vector< Reset< const sc_signal_in_if< bool > > > _if_resets
Definition sc_spawn.hh:145
void set_sensitivity(const sc_event *)
Definition sc_spawn.cc:146
std::vector< sc_interface * > _interfaces
Definition sc_spawn.hh:129
sc_spawn_options & operator=(const sc_spawn_options &)
Definition sc_spawn.hh:149
std::vector< sc_export_base * > _exports
Definition sc_spawn.hh:128
std::vector< Reset< const sc_out< bool > > > _out_resets
Definition sc_spawn.hh:144
std::vector< Reset< const sc_inout< bool > > > _inout_resets
Definition sc_spawn.hh:143
void async_reset_signal_is(const sc_in< bool > &, bool)
Definition sc_spawn.cc:203
std::vector< sc_event_finder * > _finders
Definition sc_spawn.hh:130
void reset_signal_is(const sc_in< bool > &, bool)
Definition sc_spawn.cc:177
std::vector< Reset< const sc_in< bool > > > _in_resets
Definition sc_spawn.hh:142
STL vector class.
Definition stl.hh:37
int f(int a, int b)
sc_process_handle sc_spawn(T object, const char *name_p=nullptr, const sc_spawn_options *opt_p=nullptr)
Definition sc_spawn.hh:154
auto sc_cref(T &&v) -> decltype(std::cref(std::forward< T >(v)))
Definition sc_spawn.hh:211
auto sc_bind(F &&f, Args &&...args) -> decltype(std::bind(std::forward< F >(f), std::forward< Args >(args)...))
Definition sc_spawn.hh:198
auto sc_ref(T &&v) -> decltype(std::ref(std::forward< T >(v)))
Definition sc_spawn.hh:205
Process * spawnWork(ProcessFuncWrapper *func, const char *name, const ::sc_core::sc_spawn_options *opts)
Definition sc_spawn.cc:45
Reset(T *t, bool v, bool s)
Definition sc_spawn.hh:135
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0