sc_spawn.cc revision 13180:79e680f62779
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    Process *proc;
64    if (method)
65        proc = new Method(name, func);
66    else
67        proc = new Thread(name, func);
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    if (opts && opts->_dontInitialize &&
87            opts->_events.empty() && opts->_ports.empty() &&
88            opts->_exports.empty() && opts->_interfaces.empty() &&
89            opts->_finders.empty()) {
90        SC_REPORT_WARNING(
91                "(W558) disable() or dont_initialize() called on process "
92                "with no static sensitivity, it will be orphaned",
93                proc->name());
94    }
95
96    scheduler.reg(proc);
97
98    if (dontInitialize)
99        scheduler.dontInitialize(proc);
100
101    return proc;
102}
103
104} // namespace sc_gem5
105
106namespace sc_core
107{
108
109sc_spawn_options::sc_spawn_options() :
110    _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
111{}
112
113
114void
115sc_spawn_options::spawn_method()
116{
117    _spawnMethod = true;
118}
119
120void
121sc_spawn_options::dont_initialize()
122{
123    _dontInitialize = true;
124}
125
126void
127sc_spawn_options::set_stack_size(int ss)
128{
129    _stackSize = ss;
130}
131
132
133void
134sc_spawn_options::set_sensitivity(const sc_event *e)
135{
136    _events.push_back(e);
137}
138
139void
140sc_spawn_options::set_sensitivity(sc_port_base *p)
141{
142    _ports.push_back(p);
143}
144
145void
146sc_spawn_options::set_sensitivity(sc_export_base *e)
147{
148    _exports.push_back(e);
149}
150
151void
152sc_spawn_options::set_sensitivity(sc_interface *i)
153{
154    _interfaces.push_back(i);
155}
156
157void
158sc_spawn_options::set_sensitivity(sc_event_finder *f)
159{
160    _finders.push_back(f);
161}
162
163
164void
165sc_spawn_options::reset_signal_is(const sc_in<bool> &, bool)
166{
167    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
168}
169
170void
171sc_spawn_options::reset_signal_is(const sc_inout<bool> &, bool)
172{
173    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
174}
175
176void
177sc_spawn_options::reset_signal_is(const sc_out<bool> &, bool)
178{
179    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
180}
181
182void
183sc_spawn_options::reset_signal_is(const sc_signal_in_if<bool> &, bool)
184{
185    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
186}
187
188
189void
190sc_spawn_options::async_reset_signal_is(const sc_in<bool> &, bool)
191{
192    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
193}
194
195void
196sc_spawn_options::async_reset_signal_is(const sc_inout<bool> &, bool)
197{
198    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
199}
200
201void
202sc_spawn_options::async_reset_signal_is(const sc_out<bool> &, bool)
203{
204    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
205}
206
207void
208sc_spawn_options::async_reset_signal_is(const sc_signal_in_if<bool> &, bool)
209{
210    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
211}
212
213
214void
215sc_spawn_warn_unimpl(const char *func)
216{
217    warn("%s not implemented.\n", func);
218}
219
220} // namespace sc_core
221
222namespace sc_unnamed
223{
224
225ImplementationDefined _1;
226ImplementationDefined _2;
227ImplementationDefined _3;
228ImplementationDefined _4;
229ImplementationDefined _5;
230ImplementationDefined _6;
231ImplementationDefined _7;
232ImplementationDefined _8;
233ImplementationDefined _9;
234
235} // namespace sc_unnamed
236