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