gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Gabe Black
28  */
29 
30 #include "base/logging.hh"
31 #include "systemc/core/process.hh"
42 
43 namespace sc_gem5
44 {
45 
46 Process *
47 spawnWork(ProcessFuncWrapper *func, const char *name,
48  const ::sc_core::sc_spawn_options *opts)
49 {
50  bool method = false;
51  bool dontInitialize = false;
52  if (opts) {
53  if (opts->_spawnMethod)
54  method = true;
55  if (opts->_dontInitialize)
56  dontInitialize = true;
57  if (opts->_stackSize != -1)
58  warn("Ignoring request to set stack size.\n");
59  }
60 
61  if (!name || name[0] == '\0') {
62  if (method)
63  name = ::sc_core::sc_gen_unique_name("method_p");
64  else
65  name = ::sc_core::sc_gen_unique_name("thread_p");
66  }
67 
68  Process *proc;
69  if (method)
70  proc = new Method(name, func);
71  else
72  proc = new Thread(name, func);
73 
74  proc->dontInitialize(dontInitialize);
75 
76  if (opts) {
77  for (auto e: opts->_events)
79 
80  for (auto p: opts->_ports)
82 
83  for (auto e: opts->_exports)
85 
86  for (auto i: opts->_interfaces)
88 
89  for (auto f: opts->_finders)
91 
92  for (auto p: opts->_in_resets)
93  newReset(p.target, proc, p.sync, p.value);
94 
95  for (auto p: opts->_inout_resets)
96  newReset(p.target, proc, p.sync, p.value);
97 
98  for (auto p: opts->_out_resets)
99  newReset(p.target, proc, p.sync, p.value);
100 
101  for (auto i: opts->_if_resets)
102  newReset(i.target, proc, i.sync, i.value);
103  }
104 
105  if (opts && opts->_dontInitialize &&
106  opts->_events.empty() && opts->_ports.empty() &&
107  opts->_exports.empty() && opts->_interfaces.empty() &&
108  opts->_finders.empty()) {
110  proc->name());
111  }
112 
113  scheduler.reg(proc);
114 
115  return proc;
116 }
117 
118 } // namespace sc_gem5
119 
120 namespace sc_core
121 {
122 
123 sc_spawn_options::sc_spawn_options() :
124  _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
125 {}
126 
127 
128 void
130 {
131  _spawnMethod = true;
132 }
133 
134 void
136 {
137  _dontInitialize = true;
138 }
139 
140 void
142 {
143  _stackSize = ss;
144 }
145 
146 
147 void
149 {
150  _events.push_back(e);
151 }
152 
153 void
155 {
156  _ports.push_back(p);
157 }
158 
159 void
161 {
162  _exports.push_back(e);
163 }
164 
165 void
167 {
168  _interfaces.push_back(i);
169 }
170 
171 void
173 {
174  _finders.push_back(f);
175 }
176 
177 
178 void
180 {
181  _in_resets.emplace_back(&port, value, true);
182 }
183 
184 void
186 {
187  _inout_resets.emplace_back(&port, value, true);
188 }
189 
190 void
192 {
193  _out_resets.emplace_back(&port, value, true);
194 }
195 
196 void
198  const sc_signal_in_if<bool> &iface, bool value)
199 {
200  _if_resets.emplace_back(&iface, value, true);
201 }
202 
203 
204 void
206 {
207  _in_resets.emplace_back(&port, value, false);
208 }
209 
210 void
212 {
213  _inout_resets.emplace_back(&port, value, false);
214 }
215 
216 void
218 {
219  _out_resets.emplace_back(&port, value, false);
220 }
221 
222 void
224  const sc_signal_in_if<bool> &iface, bool value)
225 {
226  _if_resets.emplace_back(&iface, value, false);
227 }
228 
229 } // namespace sc_core
Process * spawnWork(ProcessFuncWrapper *func, const char *name, const ::sc_core::sc_spawn_options *opts)
Definition: sc_spawn.cc:47
std::vector< sc_interface * > _interfaces
Definition: sc_spawn.hh:131
const std::string & name()
Definition: trace.cc:54
Bitfield< 7 > i
std::vector< sc_port_base * > _ports
Definition: sc_spawn.hh:129
void newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
Definition: sensitivity.cc:132
std::vector< Reset< const sc_out< bool > > > _out_resets
Definition: sc_spawn.hh:146
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:822
std::vector< Reset< const sc_in< bool > > > _in_resets
Definition: sc_spawn.hh:144
std::vector< const sc_event * > _events
Definition: sc_spawn.hh:128
const char * name() const
Definition: sc_object.cc:46
void newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
Definition: sensitivity.cc:149
bool dontInitialize()
Definition: process.hh:135
void reset_signal_is(const sc_in< bool > &, bool)
Definition: sc_spawn.cc:179
void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v)
Definition: process.cc:427
#define SC_REPORT_WARNING(msg_type, msg)
void reg(Process *p)
Definition: scheduler.cc:149
Bitfield< 6 > f
void newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
Definition: sensitivity.cc:140
Bitfield< 21 > ss
Scheduler scheduler
Definition: scheduler.cc:491
void newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
Definition: sensitivity.cc:157
void newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
Definition: sensitivity.cc:124
void set_sensitivity(const sc_event *)
Definition: sc_spawn.cc:148
void async_reset_signal_is(const sc_in< bool > &, bool)
Definition: sc_spawn.cc:205
Bitfield< 9 > e
const char SC_ID_DISABLE_WILL_ORPHAN_PROCESS_[]
Definition: messages.cc:134
std::vector< sc_export_base * > _exports
Definition: sc_spawn.hh:130
std::vector< Reset< const sc_signal_in_if< bool > > > _if_resets
Definition: sc_spawn.hh:147
std::vector< Reset< const sc_inout< bool > > > _inout_resets
Definition: sc_spawn.hh:145
#define warn(...)
Definition: logging.hh:212
std::vector< sc_event_finder * > _finders
Definition: sc_spawn.hh:132
Bitfield< 0 > p

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13