sc_spawn.cc revision 13194
11154SN/A/*
21762SN/A * Copyright 2018 Google, Inc.
31154SN/A *
41154SN/A * Redistribution and use in source and binary forms, with or without
51154SN/A * modification, are permitted provided that the following conditions are
61154SN/A * met: redistributions of source code must retain the above copyright
71154SN/A * notice, this list of conditions and the following disclaimer;
81154SN/A * redistributions in binary form must reproduce the above copyright
91154SN/A * notice, this list of conditions and the following disclaimer in the
101154SN/A * documentation and/or other materials provided with the distribution;
111154SN/A * neither the name of the copyright holders nor the names of its
121154SN/A * contributors may be used to endorse or promote products derived from
131154SN/A * this software without specific prior written permission.
141154SN/A *
151154SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
161154SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
171154SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
181154SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
191154SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
201154SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
211154SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221154SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
231154SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241154SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
251154SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261154SN/A *
272665SN/A * Authors: Gabe Black
282665SN/A */
291154SN/A
301154SN/A#include "base/logging.hh"
3111263Sandreas.sandberg@arm.com#include "systemc/core/process.hh"
3211263Sandreas.sandberg@arm.com#include "systemc/core/process_types.hh"
331154SN/A#include "systemc/core/scheduler.hh"
341154SN/A#include "systemc/ext/core/sc_main.hh"
351154SN/A#include "systemc/ext/core/sc_module.hh"
361154SN/A#include "systemc/ext/core/sc_spawn.hh"
371154SN/A
3812334Sgabeblack@google.comnamespace sc_gem5
3911263Sandreas.sandberg@arm.com{
401154SN/A
411154SN/AProcess *
421154SN/AspawnWork(ProcessFuncWrapper *func, const char *name,
435483SN/A          const ::sc_core::sc_spawn_options *opts)
445483SN/A{
455483SN/A    bool method = false;
465483SN/A    bool dontInitialize = false;
475483SN/A    if (opts) {
486227SN/A        if (opts->_spawnMethod)
495483SN/A            method = true;
505483SN/A        if (opts->_dontInitialize)
515483SN/A            dontInitialize = true;
525483SN/A        if (opts->_stackSize != -1)
535483SN/A            warn("Ignoring request to set stack size.\n");
545483SN/A    }
555483SN/A
565483SN/A    if (!name || name[0] == '\0') {
575483SN/A        if (method)
585483SN/A            name = ::sc_core::sc_gen_unique_name("method_p");
595483SN/A        else
605483SN/A            name = ::sc_core::sc_gen_unique_name("thread_p");
615483SN/A    }
625483SN/A
635483SN/A    Process *proc;
645483SN/A    if (method)
655483SN/A        proc = new Method(name, func);
665483SN/A    else
675483SN/A        proc = new Thread(name, func);
685483SN/A
695483SN/A    proc->dontInitialize(dontInitialize);
705483SN/A
715483SN/A    if (opts) {
725483SN/A        for (auto e: opts->_events)
735483SN/A            proc->addStatic(new PendingSensitivityEvent(proc, e));
7410905SN/A
7510905SN/A        for (auto p: opts->_ports)
765483SN/A            proc->addStatic(new PendingSensitivityPort(proc, p));
775483SN/A
781154SN/A        for (auto e: opts->_exports)
791154SN/A            proc->addStatic(new PendingSensitivityExport(proc, e));
802007SN/A
815483SN/A        for (auto i: opts->_interfaces)
825483SN/A            proc->addStatic(new PendingSensitivityInterface(proc, i));
832007SN/A
8411006SN/A        for (auto f: opts->_finders)
852007SN/A            proc->addStatic(new PendingSensitivityFinder(proc, f));
861154SN/A    }
875483SN/A
885483SN/A    if (opts && opts->_dontInitialize &&
896227SN/A            opts->_events.empty() && opts->_ports.empty() &&
906227SN/A            opts->_exports.empty() && opts->_interfaces.empty() &&
916227SN/A            opts->_finders.empty()) {
921154SN/A        SC_REPORT_WARNING(
931154SN/A                "(W558) disable() or dont_initialize() called on process "
945483SN/A                "with no static sensitivity, it will be orphaned",
955483SN/A                proc->name());
961154SN/A    }
971154SN/A
986227SN/A    scheduler.reg(proc);
996227SN/A
1006227SN/A    return proc;
1016227SN/A}
1026227SN/A
1031214SN/A} // namespace sc_gem5
1041214SN/A
1051205SN/Anamespace sc_core
1066227SN/A{
1076227SN/A
1081205SN/Asc_spawn_options::sc_spawn_options() :
10911294Sandreas.hansson@arm.com    _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
1101205SN/A{}
1111205SN/A
1121205SN/A
1131154SN/Avoid
1142007SN/Asc_spawn_options::spawn_method()
1152007SN/A{
1162007SN/A    _spawnMethod = true;
11711006SN/A}
11811006SN/A
11911006SN/Avoid
1205483SN/Asc_spawn_options::dont_initialize()
1212007SN/A{
1222566SN/A    _dontInitialize = true;
1231154SN/A}
1242007SN/A
1251205SN/Avoid
1261205SN/Asc_spawn_options::set_stack_size(int ss)
1271154SN/A{
1281154SN/A    _stackSize = ss;
1291154SN/A}
1305483SN/A
1315483SN/A
1325483SN/Avoid
1335483SN/Asc_spawn_options::set_sensitivity(const sc_event *e)
1345483SN/A{
1351205SN/A    _events.push_back(e);
1361154SN/A}
1371154SN/A
1381154SN/Avoid
1391154SN/Asc_spawn_options::set_sensitivity(sc_port_base *p)
1401154SN/A{
1411154SN/A    _ports.push_back(p);
1421154SN/A}
1431154SN/A
1445483SN/Avoid
1455483SN/Asc_spawn_options::set_sensitivity(sc_export_base *e)
1465483SN/A{
1475483SN/A    _exports.push_back(e);
1481154SN/A}
1491154SN/A
1501154SN/Avoid
1511154SN/Asc_spawn_options::set_sensitivity(sc_interface *i)
1521154SN/A{
1532007SN/A    _interfaces.push_back(i);
1545483SN/A}
1551154SN/A
1561154SN/Avoid
1571214SN/Asc_spawn_options::set_sensitivity(sc_event_finder *f)
1581154SN/A{
1591154SN/A    _finders.push_back(f);
1602007SN/A}
1612007SN/A
1622007SN/A
1632010SN/Avoid
1642010SN/Asc_spawn_options::reset_signal_is(const sc_in<bool> &, bool)
1652010SN/A{
1665483SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
1675483SN/A}
1682007SN/A
1695483SN/Avoid
1705483SN/Asc_spawn_options::reset_signal_is(const sc_inout<bool> &, bool)
1712007SN/A{
1722007SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
1735483SN/A}
1742007SN/A
1752007SN/Avoid
1762007SN/Asc_spawn_options::reset_signal_is(const sc_out<bool> &, bool)
1776227SN/A{
1782186SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
17911006SN/A}
1802186SN/A
1815483SN/Avoid
1825483SN/Asc_spawn_options::reset_signal_is(const sc_signal_in_if<bool> &, bool)
1835483SN/A{
1842186SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
1852186SN/A}
18611006SN/A
1872186SN/A
18811006SN/Avoid
1895483SN/Asc_spawn_options::async_reset_signal_is(const sc_in<bool> &, bool)
1905483SN/A{
1915483SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
1922186SN/A}
1932186SN/A
19411006SN/Avoid
1955483SN/Asc_spawn_options::async_reset_signal_is(const sc_inout<bool> &, bool)
1966227SN/A{
19711006SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
1985483SN/A}
1995483SN/A
2005483SN/Avoid
2015483SN/Asc_spawn_options::async_reset_signal_is(const sc_out<bool> &, bool)
2025483SN/A{
2032186SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
2041154SN/A}
2051154SN/A
2061154SN/Avoid
2071154SN/Asc_spawn_options::async_reset_signal_is(const sc_signal_in_if<bool> &, bool)
20810905SN/A{
20910905SN/A    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
2101154SN/A}
2111154SN/A
21211263Sandreas.sandberg@arm.com
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