sc_process_handle.cc revision 12994:afce27405f70
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/scheduler.hh"
33#include "systemc/ext/core/sc_main.hh"
34#include "systemc/ext/core/sc_process_handle.hh"
35
36namespace sc_core
37{
38
39const char *
40sc_unwind_exception::what() const throw()
41{
42    return _isReset ? "RESET" : "KILL";
43}
44
45bool
46sc_unwind_exception::is_reset() const
47{
48    return _isReset;
49}
50
51sc_unwind_exception::sc_unwind_exception() : _isReset(false) {}
52sc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &e) :
53    _isReset(e._isReset)
54{}
55sc_unwind_exception::~sc_unwind_exception() throw() {}
56
57
58const char *
59sc_process_b::name()
60{
61    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
62    return "";
63}
64
65const char *
66sc_process_b::kind()
67{
68    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
69    return "";
70}
71
72
73sc_process_b *
74sc_get_curr_process_handle()
75{
76    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
77    return nullptr;
78}
79
80
81sc_process_handle::sc_process_handle() : _gem5_process(nullptr) {}
82
83sc_process_handle::sc_process_handle(const sc_process_handle &handle) :
84    _gem5_process(handle._gem5_process)
85{
86    if (_gem5_process)
87        _gem5_process->incref();
88}
89
90sc_process_handle::sc_process_handle(sc_object *obj) :
91    _gem5_process(dynamic_cast<::sc_gem5::Process *>(obj))
92{
93    if (_gem5_process)
94        _gem5_process->incref();
95}
96
97sc_process_handle::~sc_process_handle()
98{
99    if (_gem5_process)
100        _gem5_process->decref();
101}
102
103
104bool
105sc_process_handle::valid() const
106{
107    return _gem5_process != nullptr;
108}
109
110
111sc_process_handle &
112sc_process_handle::operator = (const sc_process_handle &handle)
113{
114    if (_gem5_process)
115        _gem5_process->decref();
116    _gem5_process = handle._gem5_process;
117    if (_gem5_process)
118        _gem5_process->incref();
119    return *this;
120}
121
122bool
123sc_process_handle::operator == (const sc_process_handle &handle) const
124{
125    return _gem5_process && handle._gem5_process &&
126        (_gem5_process == handle._gem5_process);
127}
128
129bool
130sc_process_handle::operator != (const sc_process_handle &handle) const
131{
132    return !(handle == *this);
133}
134
135bool
136sc_process_handle::operator < (const sc_process_handle &other) const
137{
138    return _gem5_process < other._gem5_process;
139}
140
141void
142sc_process_handle::swap(sc_process_handle &handle)
143{
144    ::sc_gem5::Process *temp = handle._gem5_process;
145    handle._gem5_process = _gem5_process;
146    _gem5_process = temp;
147}
148
149
150const char *
151sc_process_handle::name() const
152{
153    return _gem5_process ? _gem5_process->name() : "";
154}
155
156sc_curr_proc_kind
157sc_process_handle::proc_kind() const
158{
159    return _gem5_process ? _gem5_process->procKind() : SC_NO_PROC_;
160}
161
162const std::vector<sc_object *> &
163sc_process_handle::get_child_objects() const
164{
165    static const std::vector<sc_object *> empty;
166    return _gem5_process ? _gem5_process->get_child_objects() : empty;
167}
168
169const std::vector<sc_event *> &
170sc_process_handle::get_child_events() const
171{
172    static const std::vector<sc_event *> empty;
173    return _gem5_process ? _gem5_process->get_child_events() : empty;
174}
175
176sc_object *
177sc_process_handle::get_parent_object() const
178{
179    return _gem5_process ? _gem5_process->get_parent_object() : nullptr;
180}
181
182sc_object *
183sc_process_handle::get_process_object() const
184{
185    return _gem5_process;
186}
187
188bool
189sc_process_handle::dynamic() const
190{
191    return _gem5_process ? _gem5_process->dynamic() : false;
192}
193
194bool
195sc_process_handle::terminated() const
196{
197    return _gem5_process ? _gem5_process->terminated() : false;
198}
199
200const sc_event &
201sc_process_handle::terminated_event() const
202{
203    static sc_event non_event;
204    return _gem5_process ? _gem5_process->terminatedEvent() : non_event;
205}
206
207
208void
209sc_process_handle::suspend(sc_descendent_inclusion_info include_descendants)
210{
211    if (!_gem5_process)
212        return;
213    _gem5_process->suspend(include_descendants == SC_INCLUDE_DESCENDANTS);
214}
215
216void
217sc_process_handle::resume(sc_descendent_inclusion_info include_descendants)
218{
219    if (!_gem5_process)
220        return;
221    _gem5_process->resume(include_descendants == SC_INCLUDE_DESCENDANTS);
222}
223
224void
225sc_process_handle::disable(sc_descendent_inclusion_info include_descendants)
226{
227    if (!_gem5_process)
228        return;
229    _gem5_process->disable(include_descendants == SC_INCLUDE_DESCENDANTS);
230}
231
232void
233sc_process_handle::enable(sc_descendent_inclusion_info include_descendants)
234{
235    if (!_gem5_process)
236        return;
237    _gem5_process->enable(include_descendants == SC_INCLUDE_DESCENDANTS);
238}
239
240void
241sc_process_handle::kill(sc_descendent_inclusion_info include_descendants)
242{
243    if (!_gem5_process)
244        return;
245    _gem5_process->kill(include_descendants == SC_INCLUDE_DESCENDANTS);
246}
247
248void
249sc_process_handle::reset(sc_descendent_inclusion_info include_descendants)
250{
251    if (!_gem5_process)
252        return;
253    _gem5_process->reset(include_descendants == SC_INCLUDE_DESCENDANTS);
254}
255
256bool
257sc_process_handle::is_unwinding()
258{
259    if (!_gem5_process) {
260        //TODO This should generate a systemc style warning if the handle is
261        //invalid.
262        return false;
263    } else {
264        return _gem5_process->isUnwinding();
265    }
266}
267
268const sc_event &
269sc_process_handle::reset_event() const
270{
271    static sc_event non_event;
272    return _gem5_process ? _gem5_process->resetEvent() : non_event;
273}
274
275
276void
277sc_process_handle::sync_reset_on(
278        sc_descendent_inclusion_info include_descendants)
279{
280    if (!_gem5_process)
281        return;
282    _gem5_process->syncResetOn(include_descendants == SC_INCLUDE_DESCENDANTS);
283}
284
285void
286sc_process_handle::sync_reset_off(
287        sc_descendent_inclusion_info include_descendants)
288{
289    if (!_gem5_process)
290        return;
291    _gem5_process->syncResetOff(include_descendants == SC_INCLUDE_DESCENDANTS);
292}
293
294
295sc_process_handle
296sc_get_current_process_handle()
297{
298    if (sc_is_running())
299        return sc_process_handle(::sc_gem5::scheduler.current());
300    else
301        return sc_process_handle(::sc_gem5::Process::newest());
302}
303
304bool
305sc_is_unwinding()
306{
307    return sc_get_current_process_handle().is_unwinding();
308}
309
310bool sc_allow_process_control_corners;
311
312} // namespace sc_core
313