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