sc_spawn.cc revision 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
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    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
226