gem5  v22.1.0.0
sc_spawn.cc
Go to the documentation of this file.
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 
28 #include "base/logging.hh"
29 #include "systemc/core/process.hh"
40 
41 namespace sc_gem5
42 {
43 
44 Process *
45 spawnWork(ProcessFuncWrapper *func, const char *name,
46  const ::sc_core::sc_spawn_options *opts)
47 {
48  bool method = false;
49  bool dontInitialize = false;
50  if (opts) {
51  if (opts->_spawnMethod)
52  method = true;
53  if (opts->_dontInitialize)
54  dontInitialize = true;
55  if (opts->_stackSize != -1)
56  warn_once("Ignoring request to set stack size.\n");
57  }
58 
59  if (!name || name[0] == '\0') {
60  if (method)
61  name = ::sc_core::sc_gen_unique_name("method_p");
62  else
63  name = ::sc_core::sc_gen_unique_name("thread_p");
64  }
65 
66  Process *proc;
67  if (method)
68  proc = new Method(name, func);
69  else
70  proc = new Thread(name, func);
71 
72  proc->dontInitialize(dontInitialize);
73 
74  if (opts) {
75  for (auto e: opts->_events)
77 
78  for (auto p: opts->_ports)
80 
81  for (auto e: opts->_exports)
83 
84  for (auto i: opts->_interfaces)
86 
87  for (auto f: opts->_finders)
89 
90  for (auto p: opts->_in_resets)
91  newReset(p.target, proc, p.sync, p.value);
92 
93  for (auto p: opts->_inout_resets)
94  newReset(p.target, proc, p.sync, p.value);
95 
96  for (auto p: opts->_out_resets)
97  newReset(p.target, proc, p.sync, p.value);
98 
99  for (auto i: opts->_if_resets)
100  newReset(i.target, proc, i.sync, i.value);
101  }
102 
103  if (opts && opts->_dontInitialize &&
104  opts->_events.empty() && opts->_ports.empty() &&
105  opts->_exports.empty() && opts->_interfaces.empty() &&
106  opts->_finders.empty()) {
108  proc->name());
109  }
110 
111  scheduler.reg(proc);
112 
113  return proc;
114 }
115 
116 } // namespace sc_gem5
117 
118 namespace sc_core
119 {
120 
122  _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
123 {}
124 
125 
126 void
128 {
129  _spawnMethod = true;
130 }
131 
132 void
134 {
135  _dontInitialize = true;
136 }
137 
138 void
140 {
141  _stackSize = ss;
142 }
143 
144 
145 void
147 {
148  _events.push_back(e);
149 }
150 
151 void
153 {
154  _ports.push_back(p);
155 }
156 
157 void
159 {
160  _exports.push_back(e);
161 }
162 
163 void
165 {
166  _interfaces.push_back(i);
167 }
168 
169 void
171 {
172  _finders.push_back(f);
173 }
174 
175 
176 void
178 {
179  _in_resets.emplace_back(&port, value, true);
180 }
181 
182 void
184 {
185  _inout_resets.emplace_back(&port, value, true);
186 }
187 
188 void
190 {
191  _out_resets.emplace_back(&port, value, true);
192 }
193 
194 void
196  const sc_signal_in_if<bool> &iface, bool value)
197 {
198  _if_resets.emplace_back(&iface, value, true);
199 }
200 
201 
202 void
204 {
205  _in_resets.emplace_back(&port, value, false);
206 }
207 
208 void
210 {
211  _inout_resets.emplace_back(&port, value, false);
212 }
213 
214 void
216 {
217  _out_resets.emplace_back(&port, value, false);
218 }
219 
220 void
222  const sc_signal_in_if<bool> &iface, bool value)
223 {
224  _if_resets.emplace_back(&iface, value, false);
225 }
226 
227 } // namespace sc_core
const char * name() const
Definition: sc_object.cc:44
std::vector< const sc_event * > _events
Definition: sc_spawn.hh:126
std::vector< sc_port_base * > _ports
Definition: sc_spawn.hh:127
std::vector< Reset< const sc_signal_in_if< bool > > > _if_resets
Definition: sc_spawn.hh:145
void set_sensitivity(const sc_event *)
Definition: sc_spawn.cc:146
std::vector< sc_interface * > _interfaces
Definition: sc_spawn.hh:129
std::vector< sc_export_base * > _exports
Definition: sc_spawn.hh:128
std::vector< Reset< const sc_out< bool > > > _out_resets
Definition: sc_spawn.hh:144
std::vector< Reset< const sc_inout< bool > > > _inout_resets
Definition: sc_spawn.hh:143
void async_reset_signal_is(const sc_in< bool > &, bool)
Definition: sc_spawn.cc:203
std::vector< sc_event_finder * > _finders
Definition: sc_spawn.hh:130
void reset_signal_is(const sc_in< bool > &, bool)
Definition: sc_spawn.cc:177
std::vector< Reset< const sc_in< bool > > > _in_resets
Definition: sc_spawn.hh:142
bool dontInitialize()
Definition: process.hh:133
void reg(Process *p)
Definition: scheduler.cc:146
#define warn_once(...)
Definition: logging.hh:250
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 56 > f
Definition: pagetable.hh:53
Bitfield< 54 > p
Definition: pagetable.hh:70
const char SC_ID_DISABLE_WILL_ORPHAN_PROCESS_[]
Definition: messages.cc:132
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
void newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
Definition: sensitivity.cc:130
void newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
Definition: sensitivity.cc:155
void newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
Definition: sensitivity.cc:122
void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v)
Definition: process.cc:425
void newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
Definition: sensitivity.cc:138
Process * spawnWork(ProcessFuncWrapper *func, const char *name, const ::sc_core::sc_spawn_options *opts)
Definition: sc_spawn.cc:45
Scheduler scheduler
Definition: scheduler.cc:494
void newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
Definition: sensitivity.cc:147
#define SC_REPORT_WARNING(msg_type, msg)
const std::string & name()
Definition: trace.cc:49
std::stringstream ss
Definition: trace.test.cc:45

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1