sc_spawn.cc (13129:7346c328de41) sc_spawn.cc (13131:bf07048d69e4)
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#include "base/logging.hh"
31#include "systemc/core/process.hh"
32#include "systemc/core/process_types.hh"
33#include "systemc/core/scheduler.hh"
34#include "systemc/ext/core/sc_main.hh"
35#include "systemc/ext/core/sc_module.hh"
36#include "systemc/ext/core/sc_spawn.hh"
37
38namespace sc_gem5
39{
40
41Process *
42spawnWork(ProcessFuncWrapper *func, const char *name,
43 const ::sc_core::sc_spawn_options *opts)
44{
45 bool method = false;
46 bool dontInitialize = false;
47 if (opts) {
48 if (opts->_spawnMethod)
49 method = true;
50 if (opts->_dontInitialize)
51 dontInitialize = true;
52 if (opts->_stackSize != -1)
53 warn("Ignoring request to set stack size.\n");
54 }
55
56 if (!name || name[0] == '\0') {
57 if (method)
58 name = ::sc_core::sc_gen_unique_name("method_p");
59 else
60 name = ::sc_core::sc_gen_unique_name("thread_p");
61 }
62
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#include "base/logging.hh"
31#include "systemc/core/process.hh"
32#include "systemc/core/process_types.hh"
33#include "systemc/core/scheduler.hh"
34#include "systemc/ext/core/sc_main.hh"
35#include "systemc/ext/core/sc_module.hh"
36#include "systemc/ext/core/sc_spawn.hh"
37
38namespace sc_gem5
39{
40
41Process *
42spawnWork(ProcessFuncWrapper *func, const char *name,
43 const ::sc_core::sc_spawn_options *opts)
44{
45 bool method = false;
46 bool dontInitialize = false;
47 if (opts) {
48 if (opts->_spawnMethod)
49 method = true;
50 if (opts->_dontInitialize)
51 dontInitialize = true;
52 if (opts->_stackSize != -1)
53 warn("Ignoring request to set stack size.\n");
54 }
55
56 if (!name || name[0] == '\0') {
57 if (method)
58 name = ::sc_core::sc_gen_unique_name("method_p");
59 else
60 name = ::sc_core::sc_gen_unique_name("thread_p");
61 }
62
63 bool dynamic =
64 (::sc_core::sc_get_status() >
65 ::sc_core::SC_BEFORE_END_OF_ELABORATION);
66
67 Process *proc;
68 if (method)
63 Process *proc;
64 if (method)
69 proc = new Method(name, func, dynamic);
65 proc = new Method(name, func);
70 else
66 else
71 proc = new Thread(name, func, dynamic);
67 proc = new Thread(name, func);
72
73 if (opts) {
74 for (auto e: opts->_events)
75 proc->addStatic(new PendingSensitivityEvent(proc, e));
76
77 for (auto p: opts->_ports)
78 proc->addStatic(new PendingSensitivityPort(proc, p));
79
80 for (auto e: opts->_exports)
81 proc->addStatic(new PendingSensitivityExport(proc, e));
82
83 for (auto i: opts->_interfaces)
84 proc->addStatic(new PendingSensitivityInterface(proc, i));
85
86 for (auto f: opts->_finders)
87 proc->addStatic(new PendingSensitivityFinder(proc, f));
88 }
89
90 scheduler.reg(proc);
91
92 if (dontInitialize)
93 scheduler.dontInitialize(proc);
94
95 return proc;
96}
97
98} // namespace sc_gem5
99
100namespace sc_core
101{
102
103sc_spawn_options::sc_spawn_options() :
104 _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
105{}
106
107
108void
109sc_spawn_options::spawn_method()
110{
111 _spawnMethod = true;
112}
113
114void
115sc_spawn_options::dont_initialize()
116{
117 _dontInitialize = true;
118}
119
120void
121sc_spawn_options::set_stack_size(int ss)
122{
123 _stackSize = ss;
124}
125
126
127void
128sc_spawn_options::set_sensitivity(const sc_event *e)
129{
130 _events.push_back(e);
131}
132
133void
134sc_spawn_options::set_sensitivity(sc_port_base *p)
135{
136 _ports.push_back(p);
137}
138
139void
140sc_spawn_options::set_sensitivity(sc_export_base *e)
141{
142 _exports.push_back(e);
143}
144
145void
146sc_spawn_options::set_sensitivity(sc_interface *i)
147{
148 _interfaces.push_back(i);
149}
150
151void
152sc_spawn_options::set_sensitivity(sc_event_finder *f)
153{
154 _finders.push_back(f);
155}
156
157
158void
159sc_spawn_options::reset_signal_is(const sc_in<bool> &, bool)
160{
161 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
162}
163
164void
165sc_spawn_options::reset_signal_is(const sc_inout<bool> &, bool)
166{
167 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
168}
169
170void
171sc_spawn_options::reset_signal_is(const sc_out<bool> &, bool)
172{
173 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
174}
175
176void
177sc_spawn_options::reset_signal_is(const sc_signal_in_if<bool> &, bool)
178{
179 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
180}
181
182
183void
184sc_spawn_options::async_reset_signal_is(const sc_in<bool> &, bool)
185{
186 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
187}
188
189void
190sc_spawn_options::async_reset_signal_is(const sc_inout<bool> &, bool)
191{
192 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
193}
194
195void
196sc_spawn_options::async_reset_signal_is(const sc_out<bool> &, bool)
197{
198 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
199}
200
201void
202sc_spawn_options::async_reset_signal_is(const sc_signal_in_if<bool> &, bool)
203{
204 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
205}
206
207
208void
209sc_spawn_warn_unimpl(const char *func)
210{
211 warn("%s not implemented.\n", func);
212}
213
214} // namespace sc_core
215
216namespace sc_unnamed
217{
218
219ImplementationDefined _1;
220ImplementationDefined _2;
221ImplementationDefined _3;
222ImplementationDefined _4;
223ImplementationDefined _5;
224ImplementationDefined _6;
225ImplementationDefined _7;
226ImplementationDefined _8;
227ImplementationDefined _9;
228
229} // namespace sc_unnamed
68
69 if (opts) {
70 for (auto e: opts->_events)
71 proc->addStatic(new PendingSensitivityEvent(proc, e));
72
73 for (auto p: opts->_ports)
74 proc->addStatic(new PendingSensitivityPort(proc, p));
75
76 for (auto e: opts->_exports)
77 proc->addStatic(new PendingSensitivityExport(proc, e));
78
79 for (auto i: opts->_interfaces)
80 proc->addStatic(new PendingSensitivityInterface(proc, i));
81
82 for (auto f: opts->_finders)
83 proc->addStatic(new PendingSensitivityFinder(proc, f));
84 }
85
86 scheduler.reg(proc);
87
88 if (dontInitialize)
89 scheduler.dontInitialize(proc);
90
91 return proc;
92}
93
94} // namespace sc_gem5
95
96namespace sc_core
97{
98
99sc_spawn_options::sc_spawn_options() :
100 _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
101{}
102
103
104void
105sc_spawn_options::spawn_method()
106{
107 _spawnMethod = true;
108}
109
110void
111sc_spawn_options::dont_initialize()
112{
113 _dontInitialize = true;
114}
115
116void
117sc_spawn_options::set_stack_size(int ss)
118{
119 _stackSize = ss;
120}
121
122
123void
124sc_spawn_options::set_sensitivity(const sc_event *e)
125{
126 _events.push_back(e);
127}
128
129void
130sc_spawn_options::set_sensitivity(sc_port_base *p)
131{
132 _ports.push_back(p);
133}
134
135void
136sc_spawn_options::set_sensitivity(sc_export_base *e)
137{
138 _exports.push_back(e);
139}
140
141void
142sc_spawn_options::set_sensitivity(sc_interface *i)
143{
144 _interfaces.push_back(i);
145}
146
147void
148sc_spawn_options::set_sensitivity(sc_event_finder *f)
149{
150 _finders.push_back(f);
151}
152
153
154void
155sc_spawn_options::reset_signal_is(const sc_in<bool> &, bool)
156{
157 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
158}
159
160void
161sc_spawn_options::reset_signal_is(const sc_inout<bool> &, bool)
162{
163 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
164}
165
166void
167sc_spawn_options::reset_signal_is(const sc_out<bool> &, bool)
168{
169 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
170}
171
172void
173sc_spawn_options::reset_signal_is(const sc_signal_in_if<bool> &, bool)
174{
175 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
176}
177
178
179void
180sc_spawn_options::async_reset_signal_is(const sc_in<bool> &, bool)
181{
182 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
183}
184
185void
186sc_spawn_options::async_reset_signal_is(const sc_inout<bool> &, bool)
187{
188 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
189}
190
191void
192sc_spawn_options::async_reset_signal_is(const sc_out<bool> &, bool)
193{
194 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
195}
196
197void
198sc_spawn_options::async_reset_signal_is(const sc_signal_in_if<bool> &, bool)
199{
200 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
201}
202
203
204void
205sc_spawn_warn_unimpl(const char *func)
206{
207 warn("%s not implemented.\n", func);
208}
209
210} // namespace sc_core
211
212namespace sc_unnamed
213{
214
215ImplementationDefined _1;
216ImplementationDefined _2;
217ImplementationDefined _3;
218ImplementationDefined _4;
219ImplementationDefined _5;
220ImplementationDefined _6;
221ImplementationDefined _7;
222ImplementationDefined _8;
223ImplementationDefined _9;
224
225} // namespace sc_unnamed