sc_spawn.cc revision 13317
1545SN/A/* 21762SN/A * Copyright 2018 Google, Inc. 3545SN/A * 4545SN/A * Redistribution and use in source and binary forms, with or without 5545SN/A * modification, are permitted provided that the following conditions are 6545SN/A * met: redistributions of source code must retain the above copyright 7545SN/A * notice, this list of conditions and the following disclaimer; 8545SN/A * redistributions in binary form must reproduce the above copyright 9545SN/A * notice, this list of conditions and the following disclaimer in the 10545SN/A * documentation and/or other materials provided with the distribution; 11545SN/A * neither the name of the copyright holders nor the names of its 12545SN/A * contributors may be used to endorse or promote products derived from 13545SN/A * this software without specific prior written permission. 14545SN/A * 15545SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16545SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17545SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18545SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19545SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20545SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21545SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22545SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23545SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24545SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25545SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26545SN/A * 272665Ssaidi@eecs.umich.edu * Authors: Gabe Black 282665Ssaidi@eecs.umich.edu */ 292665Ssaidi@eecs.umich.edu 30545SN/A#include "base/logging.hh" 31545SN/A#include "systemc/core/process.hh" 321310SN/A#include "systemc/core/process_types.hh" 331310SN/A#include "systemc/core/scheduler.hh" 34545SN/A#include "systemc/ext/channel/sc_in.hh" 352542SN/A#include "systemc/ext/channel/sc_inout.hh" 362592SN/A#include "systemc/ext/channel/sc_out.hh" 372489SN/A#include "systemc/ext/channel/sc_signal_in_if.hh" 382914Ssaidi@eecs.umich.edu#include "systemc/ext/core/messages.hh" 39545SN/A#include "systemc/ext/core/sc_main.hh" 403090Sstever@eecs.umich.edu#include "systemc/ext/core/sc_module.hh" 411310SN/A#include "systemc/ext/core/sc_spawn.hh" 422384SN/A 432489SN/Anamespace sc_gem5 442522SN/A{ 45545SN/A 462489SN/AProcess * 472489SN/AspawnWork(ProcessFuncWrapper *func, const char *name, 482489SN/A const ::sc_core::sc_spawn_options *opts) 492489SN/A{ 502489SN/A bool method = false; 513090Sstever@eecs.umich.edu bool dontInitialize = false; 523090Sstever@eecs.umich.edu if (opts) { 532914Ssaidi@eecs.umich.edu if (opts->_spawnMethod) 54545SN/A method = true; 55545SN/A if (opts->_dontInitialize) 562489SN/A dontInitialize = true; 572384SN/A if (opts->_stackSize != -1) 582384SN/A warn("Ignoring request to set stack size.\n"); 592901Ssaidi@eecs.umich.edu } 602489SN/A 612901Ssaidi@eecs.umich.edu if (!name || name[0] == '\0') { 622489SN/A if (method) 632489SN/A name = ::sc_core::sc_gen_unique_name("method_p"); 642489SN/A else 652489SN/A name = ::sc_core::sc_gen_unique_name("thread_p"); 662630SN/A } 672384SN/A 682630SN/A Process *proc; 692384SN/A if (method) 702630SN/A proc = new Method(name, func); 712384SN/A else 722489SN/A proc = new Thread(name, func); 732489SN/A 742384SN/A proc->dontInitialize(dontInitialize); 753090Sstever@eecs.umich.edu 763090Sstever@eecs.umich.edu if (opts) { 772384SN/A for (auto e: opts->_events) 782384SN/A newStaticSensitivityEvent(proc, e); 792901Ssaidi@eecs.umich.edu 802901Ssaidi@eecs.umich.edu for (auto p: opts->_ports) 812384SN/A newStaticSensitivityPort(proc, p); 822384SN/A 832565SN/A for (auto e: opts->_exports) 842384SN/A newStaticSensitivityExport(proc, e); 852384SN/A 862384SN/A for (auto i: opts->_interfaces) 872784Ssaidi@eecs.umich.edu newStaticSensitivityInterface(proc, i); 882784Ssaidi@eecs.umich.edu 892784Ssaidi@eecs.umich.edu for (auto f: opts->_finders) 902784Ssaidi@eecs.umich.edu newStaticSensitivityFinder(proc, f); 912784Ssaidi@eecs.umich.edu 922784Ssaidi@eecs.umich.edu for (auto p: opts->_in_resets) 932784Ssaidi@eecs.umich.edu newReset(p.target, proc, p.sync, p.value); 942784Ssaidi@eecs.umich.edu 952784Ssaidi@eecs.umich.edu for (auto p: opts->_inout_resets) 962784Ssaidi@eecs.umich.edu newReset(p.target, proc, p.sync, p.value); 972784Ssaidi@eecs.umich.edu 982784Ssaidi@eecs.umich.edu for (auto p: opts->_out_resets) 992784Ssaidi@eecs.umich.edu newReset(p.target, proc, p.sync, p.value); 1002784Ssaidi@eecs.umich.edu 1012784Ssaidi@eecs.umich.edu for (auto i: opts->_if_resets) 1022784Ssaidi@eecs.umich.edu newReset(i.target, proc, i.sync, i.value); 1032784Ssaidi@eecs.umich.edu } 1042784Ssaidi@eecs.umich.edu 1052784Ssaidi@eecs.umich.edu if (opts && opts->_dontInitialize && 1062784Ssaidi@eecs.umich.edu opts->_events.empty() && opts->_ports.empty() && 1072565SN/A opts->_exports.empty() && opts->_interfaces.empty() && 1082384SN/A opts->_finders.empty()) { 1092384SN/A SC_REPORT_WARNING(sc_core::SC_ID_DISABLE_WILL_ORPHAN_PROCESS_, 1102901Ssaidi@eecs.umich.edu proc->name()); 1112565SN/A } 1122901Ssaidi@eecs.umich.edu 1132565SN/A scheduler.reg(proc); 1142565SN/A 1152565SN/A return proc; 1162384SN/A} 1172901Ssaidi@eecs.umich.edu 1182901Ssaidi@eecs.umich.edu} // namespace sc_gem5 1192901Ssaidi@eecs.umich.edu 1202901Ssaidi@eecs.umich.edunamespace sc_core 1212901Ssaidi@eecs.umich.edu{ 1222901Ssaidi@eecs.umich.edu 1232901Ssaidi@eecs.umich.edusc_spawn_options::sc_spawn_options() : 1242630SN/A _spawnMethod(false), _dontInitialize(false), _stackSize(-1) 1252630SN/A{} 1262384SN/A 1272630SN/A 1282384SN/Avoid 1292384SN/Asc_spawn_options::spawn_method() 1302384SN/A{ 1312384SN/A _spawnMethod = true; 1322384SN/A} 1332657Ssaidi@eecs.umich.edu 1342384SN/Avoid 1353090Sstever@eecs.umich.edusc_spawn_options::dont_initialize() 1363090Sstever@eecs.umich.edu{ 1372521SN/A _dontInitialize = true; 1382384SN/A} 1392685Ssaidi@eecs.umich.edu 1402489SN/Avoid 1412384SN/Asc_spawn_options::set_stack_size(int ss) 1422901Ssaidi@eecs.umich.edu{ 1432565SN/A _stackSize = ss; 1442641Sstever@eecs.umich.edu} 1452641Sstever@eecs.umich.edu 1462565SN/A 1472565SN/Avoid 1482384SN/Asc_spawn_options::set_sensitivity(const sc_event *e) 1492901Ssaidi@eecs.umich.edu{ 1502384SN/A _events.push_back(e); 1512384SN/A} 1522489SN/A 1532489SN/Avoid 1542489SN/Asc_spawn_options::set_sensitivity(sc_port_base *p) 1552489SN/A{ 1562489SN/A _ports.push_back(p); 1572489SN/A} 1582489SN/A 1592542SN/Avoid 1602384SN/Asc_spawn_options::set_sensitivity(sc_export_base *e) 1612384SN/A{ 1622384SN/A _exports.push_back(e); 1632489SN/A} 1642489SN/A 1651310SN/Avoid 1662384SN/Asc_spawn_options::set_sensitivity(sc_interface *i) 1672901Ssaidi@eecs.umich.edu{ 1682901Ssaidi@eecs.umich.edu _interfaces.push_back(i); 1692489SN/A} 1702489SN/A 1712384SN/Avoid 1722384SN/Asc_spawn_options::set_sensitivity(sc_event_finder *f) 1732521SN/A{ 1742384SN/A _finders.push_back(f); 1753090Sstever@eecs.umich.edu} 1763090Sstever@eecs.umich.edu 1773090Sstever@eecs.umich.edu 1782630SN/Avoid 1792641Sstever@eecs.umich.edusc_spawn_options::reset_signal_is(const sc_in<bool> &port, bool value) 1802384SN/A{ 1813090Sstever@eecs.umich.edu _in_resets.emplace_back(&port, value, true); 1823090Sstever@eecs.umich.edu} 1832523SN/A 1842523SN/Avoid 1852523SN/Asc_spawn_options::reset_signal_is(const sc_inout<bool> &port, bool value) 1862630SN/A{ 1872384SN/A _inout_resets.emplace_back(&port, value, true); 1882489SN/A} 1892523SN/A 1902523SN/Avoid 1912523SN/Asc_spawn_options::reset_signal_is(const sc_out<bool> &port, bool value) 1922523SN/A{ 1932630SN/A _out_resets.emplace_back(&port, value, true); 194545SN/A} 195545SN/A 1963090Sstever@eecs.umich.eduvoid 1973090Sstever@eecs.umich.edusc_spawn_options::reset_signal_is( 1983090Sstever@eecs.umich.edu const sc_signal_in_if<bool> &iface, bool value) 1992512SN/A{ 2002512SN/A _if_resets.emplace_back(&iface, value, true); 2012512SN/A} 2022512SN/A 2032522SN/A 2042512SN/Avoid 2052521SN/Asc_spawn_options::async_reset_signal_is(const sc_in<bool> &port, bool value) 2062512SN/A{ 2072512SN/A _in_resets.emplace_back(&port, value, false); 2082512SN/A} 2092512SN/A 2102512SN/Avoid 2112512SN/Asc_spawn_options::async_reset_signal_is(const sc_inout<bool> &port, bool value) 2122521SN/A{ 2132901Ssaidi@eecs.umich.edu _inout_resets.emplace_back(&port, value, false); 2142901Ssaidi@eecs.umich.edu} 2152512SN/A 2162384SN/Avoid 217545SN/Asc_spawn_options::async_reset_signal_is(const sc_out<bool> &port, bool value) 2182384SN/A{ 2192541SN/A _out_resets.emplace_back(&port, value, false); 2202541SN/A} 2212901Ssaidi@eecs.umich.edu 2222901Ssaidi@eecs.umich.eduvoid 2232738Sstever@eecs.umich.edusc_spawn_options::async_reset_signal_is( 2242384SN/A const sc_signal_in_if<bool> &iface, bool value) 2252521SN/A{ 2262512SN/A _if_resets.emplace_back(&iface, value, false); 2272512SN/A} 2282901Ssaidi@eecs.umich.edu 2292384SN/A} // namespace sc_core 2302521SN/A