sc_spawn.cc revision 13129:7346c328de41
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 bool dynamic = 64 (::sc_core::sc_get_status() > 65 ::sc_core::SC_BEFORE_END_OF_ELABORATION); 66 67 Process *proc; 68 if (method) 69 proc = new Method(name, func, dynamic); 70 else 71 proc = new Thread(name, func, dynamic); 72 73 if (opts) { 74 for (auto e: opts->_events) 75 proc->addStatic(new PendingSensitivityEvent(proc, e)); 76 77 for (auto p: opts->_ports) 78 proc->addStatic(new PendingSensitivityPort(proc, p)); 79 80 for (auto e: opts->_exports) 81 proc->addStatic(new PendingSensitivityExport(proc, e)); 82 83 for (auto i: opts->_interfaces) 84 proc->addStatic(new PendingSensitivityInterface(proc, i)); 85 86 for (auto f: opts->_finders) 87 proc->addStatic(new PendingSensitivityFinder(proc, f)); 88 } 89 90 scheduler.reg(proc); 91 92 if (dontInitialize) 93 scheduler.dontInitialize(proc); 94 95 return proc; 96} 97 98} // namespace sc_gem5 99 100namespace sc_core 101{ 102 103sc_spawn_options::sc_spawn_options() : 104 _spawnMethod(false), _dontInitialize(false), _stackSize(-1) 105{} 106 107 108void 109sc_spawn_options::spawn_method() 110{ 111 _spawnMethod = true; 112} 113 114void 115sc_spawn_options::dont_initialize() 116{ 117 _dontInitialize = true; 118} 119 120void 121sc_spawn_options::set_stack_size(int ss) 122{ 123 _stackSize = ss; 124} 125 126 127void 128sc_spawn_options::set_sensitivity(const sc_event *e) 129{ 130 _events.push_back(e); 131} 132 133void 134sc_spawn_options::set_sensitivity(sc_port_base *p) 135{ 136 _ports.push_back(p); 137} 138 139void 140sc_spawn_options::set_sensitivity(sc_export_base *e) 141{ 142 _exports.push_back(e); 143} 144 145void 146sc_spawn_options::set_sensitivity(sc_interface *i) 147{ 148 _interfaces.push_back(i); 149} 150 151void 152sc_spawn_options::set_sensitivity(sc_event_finder *f) 153{ 154 _finders.push_back(f); 155} 156 157 158void 159sc_spawn_options::reset_signal_is(const sc_in<bool> &, bool) 160{ 161 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 162} 163 164void 165sc_spawn_options::reset_signal_is(const sc_inout<bool> &, bool) 166{ 167 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 168} 169 170void 171sc_spawn_options::reset_signal_is(const sc_out<bool> &, bool) 172{ 173 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 174} 175 176void 177sc_spawn_options::reset_signal_is(const sc_signal_in_if<bool> &, bool) 178{ 179 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 180} 181 182 183void 184sc_spawn_options::async_reset_signal_is(const sc_in<bool> &, bool) 185{ 186 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 187} 188 189void 190sc_spawn_options::async_reset_signal_is(const sc_inout<bool> &, bool) 191{ 192 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 193} 194 195void 196sc_spawn_options::async_reset_signal_is(const sc_out<bool> &, bool) 197{ 198 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 199} 200 201void 202sc_spawn_options::async_reset_signal_is(const sc_signal_in_if<bool> &, bool) 203{ 204 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 205} 206 207 208void 209sc_spawn_warn_unimpl(const char *func) 210{ 211 warn("%s not implemented.\n", func); 212} 213 214} // namespace sc_core 215 216namespace sc_unnamed 217{ 218 219ImplementationDefined _1; 220ImplementationDefined _2; 221ImplementationDefined _3; 222ImplementationDefined _4; 223ImplementationDefined _5; 224ImplementationDefined _6; 225ImplementationDefined _7; 226ImplementationDefined _8; 227ImplementationDefined _9; 228 229} // namespace sc_unnamed 230