sc_spawn.cc revision 13317
112837Sgabeblack@google.com/* 212837Sgabeblack@google.com * Copyright 2018 Google, Inc. 312837Sgabeblack@google.com * 412837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512837Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012837Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312837Sgabeblack@google.com * this software without specific prior written permission. 1412837Sgabeblack@google.com * 1512837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612837Sgabeblack@google.com * 2712837Sgabeblack@google.com * Authors: Gabe Black 2812837Sgabeblack@google.com */ 2912837Sgabeblack@google.com 3012901Sgabeblack@google.com#include "base/logging.hh" 3113135Sgabeblack@google.com#include "systemc/core/process.hh" 3212901Sgabeblack@google.com#include "systemc/core/process_types.hh" 3312901Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3412837Sgabeblack@google.com#include "systemc/ext/channel/sc_in.hh" 3513280Sgabeblack@google.com#include "systemc/ext/channel/sc_inout.hh" 3612982Sgabeblack@google.com#include "systemc/ext/channel/sc_out.hh" 3712951Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh" 3813280Sgabeblack@google.com#include "systemc/ext/core/messages.hh" 3913288Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh" 4012953Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 4113260Sgabeblack@google.com#include "systemc/ext/core/sc_spawn.hh" 4213288Sgabeblack@google.com 4313288Sgabeblack@google.comnamespace sc_gem5 4413288Sgabeblack@google.com{ 4513155Sgabeblack@google.com 4612837Sgabeblack@google.comProcess * 4712951Sgabeblack@google.comspawnWork(ProcessFuncWrapper *func, const char *name, 4813155Sgabeblack@google.com const ::sc_core::sc_spawn_options *opts) 4913135Sgabeblack@google.com{ 5012837Sgabeblack@google.com bool method = false; 5112952Sgabeblack@google.com bool dontInitialize = false; 5212952Sgabeblack@google.com if (opts) { 5312952Sgabeblack@google.com if (opts->_spawnMethod) 5412952Sgabeblack@google.com method = true; 5512952Sgabeblack@google.com if (opts->_dontInitialize) 5612952Sgabeblack@google.com dontInitialize = true; 5713135Sgabeblack@google.com if (opts->_stackSize != -1) 5813135Sgabeblack@google.com warn("Ignoring request to set stack size.\n"); 5913135Sgabeblack@google.com } 6013135Sgabeblack@google.com 6113135Sgabeblack@google.com if (!name || name[0] == '\0') { 6213135Sgabeblack@google.com if (method) 6313135Sgabeblack@google.com name = ::sc_core::sc_gen_unique_name("method_p"); 6413135Sgabeblack@google.com else 6512993Sgabeblack@google.com name = ::sc_core::sc_gen_unique_name("thread_p"); 6612993Sgabeblack@google.com } 6712952Sgabeblack@google.com 6812952Sgabeblack@google.com Process *proc; 6912952Sgabeblack@google.com if (method) 7012952Sgabeblack@google.com proc = new Method(name, func); 7112952Sgabeblack@google.com else 7213135Sgabeblack@google.com proc = new Thread(name, func); 7313135Sgabeblack@google.com 7413135Sgabeblack@google.com proc->dontInitialize(dontInitialize); 7513135Sgabeblack@google.com 7613135Sgabeblack@google.com if (opts) { 7713135Sgabeblack@google.com for (auto e: opts->_events) 7813135Sgabeblack@google.com newStaticSensitivityEvent(proc, e); 7913135Sgabeblack@google.com 8012993Sgabeblack@google.com for (auto p: opts->_ports) 8112993Sgabeblack@google.com newStaticSensitivityPort(proc, p); 8212952Sgabeblack@google.com 8312952Sgabeblack@google.com for (auto e: opts->_exports) 8412952Sgabeblack@google.com newStaticSensitivityExport(proc, e); 8512952Sgabeblack@google.com 8612952Sgabeblack@google.com for (auto i: opts->_interfaces) 8713135Sgabeblack@google.com newStaticSensitivityInterface(proc, i); 8813135Sgabeblack@google.com 8913135Sgabeblack@google.com for (auto f: opts->_finders) 9013135Sgabeblack@google.com newStaticSensitivityFinder(proc, f); 9113135Sgabeblack@google.com 9213135Sgabeblack@google.com for (auto p: opts->_in_resets) 9313135Sgabeblack@google.com newReset(p.target, proc, p.sync, p.value); 9413135Sgabeblack@google.com 9512993Sgabeblack@google.com for (auto p: opts->_inout_resets) 9613194Sgabeblack@google.com newReset(p.target, proc, p.sync, p.value); 9712993Sgabeblack@google.com 9812952Sgabeblack@google.com for (auto p: opts->_out_resets) 9912952Sgabeblack@google.com newReset(p.target, proc, p.sync, p.value); 10012952Sgabeblack@google.com 10112952Sgabeblack@google.com for (auto i: opts->_if_resets) 10212837Sgabeblack@google.com newReset(i.target, proc, i.sync, i.value); 10312837Sgabeblack@google.com } 10412837Sgabeblack@google.com 10513091Sgabeblack@google.com if (opts && opts->_dontInitialize && 10612951Sgabeblack@google.com opts->_events.empty() && opts->_ports.empty() && 10712951Sgabeblack@google.com opts->_exports.empty() && opts->_interfaces.empty() && 10812837Sgabeblack@google.com opts->_finders.empty()) { 10913091Sgabeblack@google.com SC_REPORT_WARNING(sc_core::SC_ID_DISABLE_WILL_ORPHAN_PROCESS_, 11012951Sgabeblack@google.com proc->name()); 11112951Sgabeblack@google.com } 11212837Sgabeblack@google.com 11313091Sgabeblack@google.com scheduler.reg(proc); 11412837Sgabeblack@google.com 11512982Sgabeblack@google.com return proc; 11612837Sgabeblack@google.com} 11713091Sgabeblack@google.com 11812837Sgabeblack@google.com} // namespace sc_gem5 11912837Sgabeblack@google.com 12012837Sgabeblack@google.comnamespace sc_core 12112837Sgabeblack@google.com{ 12212837Sgabeblack@google.com 12312837Sgabeblack@google.comsc_spawn_options::sc_spawn_options() : 12412837Sgabeblack@google.com _spawnMethod(false), _dontInitialize(false), _stackSize(-1) 12512837Sgabeblack@google.com{} 12612837Sgabeblack@google.com 12712837Sgabeblack@google.com 12812837Sgabeblack@google.comvoid 12912837Sgabeblack@google.comsc_spawn_options::spawn_method() 13012837Sgabeblack@google.com{ 13112837Sgabeblack@google.com _spawnMethod = true; 13212837Sgabeblack@google.com} 13312837Sgabeblack@google.com 13412837Sgabeblack@google.comvoid 13512837Sgabeblack@google.comsc_spawn_options::dont_initialize() 13612837Sgabeblack@google.com{ 13712837Sgabeblack@google.com _dontInitialize = true; 13812837Sgabeblack@google.com} 13912837Sgabeblack@google.com 14012837Sgabeblack@google.comvoid 14112837Sgabeblack@google.comsc_spawn_options::set_stack_size(int ss) 14212837Sgabeblack@google.com{ 14312837Sgabeblack@google.com _stackSize = ss; 14412837Sgabeblack@google.com} 14512837Sgabeblack@google.com 14612837Sgabeblack@google.com 14712837Sgabeblack@google.comvoid 14812837Sgabeblack@google.comsc_spawn_options::set_sensitivity(const sc_event *e) 14912837Sgabeblack@google.com{ 15012837Sgabeblack@google.com _events.push_back(e); 15112837Sgabeblack@google.com} 15212837Sgabeblack@google.com 15312837Sgabeblack@google.comvoid 15412837Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_port_base *p) 15512837Sgabeblack@google.com{ 15612837Sgabeblack@google.com _ports.push_back(p); 15712837Sgabeblack@google.com} 15812837Sgabeblack@google.com 15912837Sgabeblack@google.comvoid 16012837Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_export_base *e) 16112837Sgabeblack@google.com{ 16212837Sgabeblack@google.com _exports.push_back(e); 16312837Sgabeblack@google.com} 16412837Sgabeblack@google.com 16512837Sgabeblack@google.comvoid 16612837Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_interface *i) 16712837Sgabeblack@google.com{ 16812837Sgabeblack@google.com _interfaces.push_back(i); 16912837Sgabeblack@google.com} 17012837Sgabeblack@google.com 17112837Sgabeblack@google.comvoid 17212837Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_event_finder *f) 17312837Sgabeblack@google.com{ 17412837Sgabeblack@google.com _finders.push_back(f); 17512837Sgabeblack@google.com} 17612837Sgabeblack@google.com 17712837Sgabeblack@google.com 17812837Sgabeblack@google.comvoid 17912837Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_in<bool> &port, bool value) 18012837Sgabeblack@google.com{ 18112837Sgabeblack@google.com _in_resets.emplace_back(&port, value, true); 18212837Sgabeblack@google.com} 18312837Sgabeblack@google.com 18412837Sgabeblack@google.comvoid 18513091Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_inout<bool> &port, bool value) 18613091Sgabeblack@google.com{ 18713091Sgabeblack@google.com _inout_resets.emplace_back(&port, value, true); 18813091Sgabeblack@google.com} 18913091Sgabeblack@google.com 19013091Sgabeblack@google.comvoid 19113091Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_out<bool> &port, bool value) 19213091Sgabeblack@google.com{ 19313091Sgabeblack@google.com _out_resets.emplace_back(&port, value, true); 19413091Sgabeblack@google.com} 19513091Sgabeblack@google.com 19613091Sgabeblack@google.comvoid 19713091Sgabeblack@google.comsc_spawn_options::reset_signal_is( 19813091Sgabeblack@google.com const sc_signal_in_if<bool> &iface, bool value) 19913091Sgabeblack@google.com{ 20013091Sgabeblack@google.com _if_resets.emplace_back(&iface, value, true); 20113091Sgabeblack@google.com} 20213091Sgabeblack@google.com 20313091Sgabeblack@google.com 20413091Sgabeblack@google.comvoid 20513091Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_in<bool> &port, bool value) 20613091Sgabeblack@google.com{ 20713091Sgabeblack@google.com _in_resets.emplace_back(&port, value, false); 20813091Sgabeblack@google.com} 20912837Sgabeblack@google.com 21012837Sgabeblack@google.comvoid 21113292Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_inout<bool> &port, bool value) 21213292Sgabeblack@google.com{ 21313292Sgabeblack@google.com _inout_resets.emplace_back(&port, value, false); 21413292Sgabeblack@google.com} 21513292Sgabeblack@google.com 21613292Sgabeblack@google.comvoid 21713292Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_out<bool> &port, bool value) 21813292Sgabeblack@google.com{ 21913292Sgabeblack@google.com _out_resets.emplace_back(&port, value, false); 22013292Sgabeblack@google.com} 22113292Sgabeblack@google.com 22213292Sgabeblack@google.comvoid 22313292Sgabeblack@google.comsc_spawn_options::async_reset_signal_is( 22413292Sgabeblack@google.com const sc_signal_in_if<bool> &iface, bool value) 22513292Sgabeblack@google.com{ 22613292Sgabeblack@google.com _if_resets.emplace_back(&iface, value, false); 22713292Sgabeblack@google.com} 22813292Sgabeblack@google.com 22913292Sgabeblack@google.com} // namespace sc_core 23013292Sgabeblack@google.com