sc_spawn.cc revision 13131:bf07048d69e4
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright 2018 Google, Inc.
36145Snate@binkert.org *
46145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
56145Snate@binkert.org * modification, are permitted provided that the following conditions are
66145Snate@binkert.org * met: redistributions of source code must retain the above copyright
76145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
86145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
96145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
106145Snate@binkert.org * documentation and/or other materials provided with the distribution;
116145Snate@binkert.org * neither the name of the copyright holders nor the names of its
126145Snate@binkert.org * contributors may be used to endorse or promote products derived from
136145Snate@binkert.org * this software without specific prior written permission.
146145Snate@binkert.org *
156145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
166145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
176145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
186145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
196145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
206145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
216145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
256145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266145Snate@binkert.org *
276145Snate@binkert.org * Authors: Gabe Black
286145Snate@binkert.org */
296145Snate@binkert.org
307054Snate@binkert.org#include "base/logging.hh"
317054Snate@binkert.org#include "systemc/core/process.hh"
327054Snate@binkert.org#include "systemc/core/process_types.hh"
337054Snate@binkert.org#include "systemc/core/scheduler.hh"
346145Snate@binkert.org#include "systemc/ext/core/sc_main.hh"
356145Snate@binkert.org#include "systemc/ext/core/sc_module.hh"
367054Snate@binkert.org#include "systemc/ext/core/sc_spawn.hh"
377054Snate@binkert.org
386145Snate@binkert.orgnamespace sc_gem5
397002Snate@binkert.org{
408229Snate@binkert.org
417454Snate@binkert.orgProcess *
427002Snate@binkert.orgspawnWork(ProcessFuncWrapper *func, const char *name,
436154Snate@binkert.org          const ::sc_core::sc_spawn_options *opts)
446145Snate@binkert.org{
456145Snate@binkert.org    bool method = false;
466145Snate@binkert.org    bool dontInitialize = false;
476145Snate@binkert.org    if (opts) {
489274Snilay@cs.wisc.edu        if (opts->_spawnMethod)
496145Snate@binkert.org            method = true;
507054Snate@binkert.org        if (opts->_dontInitialize)
517054Snate@binkert.org            dontInitialize = true;
527054Snate@binkert.org        if (opts->_stackSize != -1)
537054Snate@binkert.org            warn("Ignoring request to set stack size.\n");
546145Snate@binkert.org    }
556145Snate@binkert.org
569554Sandreas.hansson@arm.com    if (!name || name[0] == '\0') {
579554Sandreas.hansson@arm.com        if (method)
587054Snate@binkert.org            name = ::sc_core::sc_gen_unique_name("method_p");
597054Snate@binkert.org        else
607054Snate@binkert.org            name = ::sc_core::sc_gen_unique_name("thread_p");
619274Snilay@cs.wisc.edu    }
627054Snate@binkert.org
636145Snate@binkert.org    Process *proc;
648054Sksewell@umich.edu    if (method)
658054Sksewell@umich.edu        proc = new Method(name, func);
668054Sksewell@umich.edu    else
679274Snilay@cs.wisc.edu        proc = new Thread(name, func);
689508Snilay@cs.wisc.edu
697454Snate@binkert.org    if (opts) {
709863Snilay@cs.wisc.edu        for (auto e: opts->_events)
717054Snate@binkert.org            proc->addStatic(new PendingSensitivityEvent(proc, e));
727054Snate@binkert.org
736145Snate@binkert.org        for (auto p: opts->_ports)
747054Snate@binkert.org            proc->addStatic(new PendingSensitivityPort(proc, p));
757973Snilay@cs.wisc.edu
766145Snate@binkert.org        for (auto e: opts->_exports)
777054Snate@binkert.org            proc->addStatic(new PendingSensitivityExport(proc, e));
789863Snilay@cs.wisc.edu
797054Snate@binkert.org        for (auto i: opts->_interfaces)
806145Snate@binkert.org            proc->addStatic(new PendingSensitivityInterface(proc, i));
817054Snate@binkert.org
827054Snate@binkert.org        for (auto f: opts->_finders)
837054Snate@binkert.org            proc->addStatic(new PendingSensitivityFinder(proc, f));
847054Snate@binkert.org    }
856145Snate@binkert.org
867054Snate@binkert.org    scheduler.reg(proc);
876145Snate@binkert.org
887054Snate@binkert.org    if (dontInitialize)
897454Snate@binkert.org        scheduler.dontInitialize(proc);
907454Snate@binkert.org
917454Snate@binkert.org    return proc;
927454Snate@binkert.org}
939274Snilay@cs.wisc.edu
949274Snilay@cs.wisc.edu} // namespace sc_gem5
957054Snate@binkert.org
967054Snate@binkert.orgnamespace sc_core
979274Snilay@cs.wisc.edu{
987054Snate@binkert.org
997973Snilay@cs.wisc.edusc_spawn_options::sc_spawn_options() :
1006145Snate@binkert.org    _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
1016145Snate@binkert.org{}
1027054Snate@binkert.org
1037054Snate@binkert.org
1046145Snate@binkert.orgvoid
1057054Snate@binkert.orgsc_spawn_options::spawn_method()
1067054Snate@binkert.org{
1077054Snate@binkert.org    _spawnMethod = true;
1086145Snate@binkert.org}
1096145Snate@binkert.org
1107054Snate@binkert.orgvoid
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