sc_spawn.cc revision 13129
112839Sgabeblack@google.com/*
212839Sgabeblack@google.com * Copyright 2018 Google, Inc.
312839Sgabeblack@google.com *
412839Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512839Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612839Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712839Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812839Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912839Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012839Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112839Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212839Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312839Sgabeblack@google.com * this software without specific prior written permission.
1412839Sgabeblack@google.com *
1512839Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612839Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712839Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812839Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912839Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012839Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112839Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212839Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312839Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412839Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512839Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612839Sgabeblack@google.com *
2712839Sgabeblack@google.com * Authors: Gabe Black
2812839Sgabeblack@google.com */
2912839Sgabeblack@google.com
3012839Sgabeblack@google.com#include "base/logging.hh"
3112993Sgabeblack@google.com#include "systemc/core/process.hh"
3212993Sgabeblack@google.com#include "systemc/core/process_types.hh"
3312993Sgabeblack@google.com#include "systemc/core/scheduler.hh"
3413129Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh"
3512993Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
3612839Sgabeblack@google.com#include "systemc/ext/core/sc_spawn.hh"
3712839Sgabeblack@google.com
3812993Sgabeblack@google.comnamespace sc_gem5
3912993Sgabeblack@google.com{
4012993Sgabeblack@google.com
4112993Sgabeblack@google.comProcess *
4212993Sgabeblack@google.comspawnWork(ProcessFuncWrapper *func, const char *name,
4312993Sgabeblack@google.com          const ::sc_core::sc_spawn_options *opts)
4412993Sgabeblack@google.com{
4512993Sgabeblack@google.com    bool method = false;
4612993Sgabeblack@google.com    bool dontInitialize = false;
4712993Sgabeblack@google.com    if (opts) {
4812993Sgabeblack@google.com        if (opts->_spawnMethod)
4912993Sgabeblack@google.com            method = true;
5012993Sgabeblack@google.com        if (opts->_dontInitialize)
5112993Sgabeblack@google.com            dontInitialize = true;
5212993Sgabeblack@google.com        if (opts->_stackSize != -1)
5312993Sgabeblack@google.com            warn("Ignoring request to set stack size.\n");
5412993Sgabeblack@google.com    }
5512993Sgabeblack@google.com
5612993Sgabeblack@google.com    if (!name || name[0] == '\0') {
5712993Sgabeblack@google.com        if (method)
5812993Sgabeblack@google.com            name = ::sc_core::sc_gen_unique_name("method_p");
5912993Sgabeblack@google.com        else
6012993Sgabeblack@google.com            name = ::sc_core::sc_gen_unique_name("thread_p");
6112993Sgabeblack@google.com    }
6212993Sgabeblack@google.com
6313129Sgabeblack@google.com    bool dynamic =
6413129Sgabeblack@google.com        (::sc_core::sc_get_status() >
6513129Sgabeblack@google.com         ::sc_core::SC_BEFORE_END_OF_ELABORATION);
6613129Sgabeblack@google.com
6712993Sgabeblack@google.com    Process *proc;
6812993Sgabeblack@google.com    if (method)
6913129Sgabeblack@google.com        proc = new Method(name, func, dynamic);
7012993Sgabeblack@google.com    else
7113129Sgabeblack@google.com        proc = new Thread(name, func, dynamic);
7212993Sgabeblack@google.com
7312993Sgabeblack@google.com    if (opts) {
7412993Sgabeblack@google.com        for (auto e: opts->_events)
7512993Sgabeblack@google.com            proc->addStatic(new PendingSensitivityEvent(proc, e));
7612993Sgabeblack@google.com
7712993Sgabeblack@google.com        for (auto p: opts->_ports)
7812993Sgabeblack@google.com            proc->addStatic(new PendingSensitivityPort(proc, p));
7912993Sgabeblack@google.com
8012993Sgabeblack@google.com        for (auto e: opts->_exports)
8112993Sgabeblack@google.com            proc->addStatic(new PendingSensitivityExport(proc, e));
8212993Sgabeblack@google.com
8312993Sgabeblack@google.com        for (auto i: opts->_interfaces)
8412993Sgabeblack@google.com            proc->addStatic(new PendingSensitivityInterface(proc, i));
8512993Sgabeblack@google.com
8612993Sgabeblack@google.com        for (auto f: opts->_finders)
8712993Sgabeblack@google.com            proc->addStatic(new PendingSensitivityFinder(proc, f));
8812993Sgabeblack@google.com    }
8912993Sgabeblack@google.com
9012993Sgabeblack@google.com    scheduler.reg(proc);
9112993Sgabeblack@google.com
9212993Sgabeblack@google.com    if (dontInitialize)
9312993Sgabeblack@google.com        scheduler.dontInitialize(proc);
9412993Sgabeblack@google.com
9512993Sgabeblack@google.com    return proc;
9612993Sgabeblack@google.com}
9712993Sgabeblack@google.com
9812993Sgabeblack@google.com} // namespace sc_gem5
9912993Sgabeblack@google.com
10012839Sgabeblack@google.comnamespace sc_core
10112839Sgabeblack@google.com{
10212839Sgabeblack@google.com
10312993Sgabeblack@google.comsc_spawn_options::sc_spawn_options() :
10412993Sgabeblack@google.com    _spawnMethod(false), _dontInitialize(false), _stackSize(-1)
10512993Sgabeblack@google.com{}
10612839Sgabeblack@google.com
10712839Sgabeblack@google.com
10812839Sgabeblack@google.comvoid
10912839Sgabeblack@google.comsc_spawn_options::spawn_method()
11012839Sgabeblack@google.com{
11112993Sgabeblack@google.com    _spawnMethod = true;
11212839Sgabeblack@google.com}
11312839Sgabeblack@google.com
11412839Sgabeblack@google.comvoid
11512839Sgabeblack@google.comsc_spawn_options::dont_initialize()
11612839Sgabeblack@google.com{
11712993Sgabeblack@google.com    _dontInitialize = true;
11812839Sgabeblack@google.com}
11912839Sgabeblack@google.com
12012839Sgabeblack@google.comvoid
12112993Sgabeblack@google.comsc_spawn_options::set_stack_size(int ss)
12212839Sgabeblack@google.com{
12312993Sgabeblack@google.com    _stackSize = ss;
12412839Sgabeblack@google.com}
12512839Sgabeblack@google.com
12612839Sgabeblack@google.com
12712839Sgabeblack@google.comvoid
12812993Sgabeblack@google.comsc_spawn_options::set_sensitivity(const sc_event *e)
12912839Sgabeblack@google.com{
13012993Sgabeblack@google.com    _events.push_back(e);
13112839Sgabeblack@google.com}
13212839Sgabeblack@google.com
13312839Sgabeblack@google.comvoid
13412993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_port_base *p)
13512839Sgabeblack@google.com{
13612993Sgabeblack@google.com    _ports.push_back(p);
13712839Sgabeblack@google.com}
13812839Sgabeblack@google.com
13912839Sgabeblack@google.comvoid
14012993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_export_base *e)
14112839Sgabeblack@google.com{
14212993Sgabeblack@google.com    _exports.push_back(e);
14312839Sgabeblack@google.com}
14412839Sgabeblack@google.com
14512839Sgabeblack@google.comvoid
14612993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_interface *i)
14712839Sgabeblack@google.com{
14812993Sgabeblack@google.com    _interfaces.push_back(i);
14912839Sgabeblack@google.com}
15012839Sgabeblack@google.com
15112839Sgabeblack@google.comvoid
15212993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_event_finder *f)
15312839Sgabeblack@google.com{
15412993Sgabeblack@google.com    _finders.push_back(f);
15512839Sgabeblack@google.com}
15612839Sgabeblack@google.com
15712839Sgabeblack@google.com
15812839Sgabeblack@google.comvoid
15912839Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_in<bool> &, bool)
16012839Sgabeblack@google.com{
16112839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
16212839Sgabeblack@google.com}
16312839Sgabeblack@google.com
16412839Sgabeblack@google.comvoid
16512839Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_inout<bool> &, bool)
16612839Sgabeblack@google.com{
16712839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
16812839Sgabeblack@google.com}
16912839Sgabeblack@google.com
17012839Sgabeblack@google.comvoid
17112839Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_out<bool> &, bool)
17212839Sgabeblack@google.com{
17312839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
17412839Sgabeblack@google.com}
17512839Sgabeblack@google.com
17612839Sgabeblack@google.comvoid
17712839Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_signal_in_if<bool> &, bool)
17812839Sgabeblack@google.com{
17912839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
18012839Sgabeblack@google.com}
18112839Sgabeblack@google.com
18212839Sgabeblack@google.com
18312839Sgabeblack@google.comvoid
18412839Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_in<bool> &, bool)
18512839Sgabeblack@google.com{
18612839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
18712839Sgabeblack@google.com}
18812839Sgabeblack@google.com
18912839Sgabeblack@google.comvoid
19012839Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_inout<bool> &, bool)
19112839Sgabeblack@google.com{
19212839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
19312839Sgabeblack@google.com}
19412839Sgabeblack@google.com
19512839Sgabeblack@google.comvoid
19612839Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_out<bool> &, bool)
19712839Sgabeblack@google.com{
19812839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
19912839Sgabeblack@google.com}
20012839Sgabeblack@google.com
20112839Sgabeblack@google.comvoid
20212839Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_signal_in_if<bool> &, bool)
20312839Sgabeblack@google.com{
20412839Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
20512839Sgabeblack@google.com}
20612839Sgabeblack@google.com
20712839Sgabeblack@google.com
20812839Sgabeblack@google.comvoid
20912839Sgabeblack@google.comsc_spawn_warn_unimpl(const char *func)
21012839Sgabeblack@google.com{
21112839Sgabeblack@google.com    warn("%s not implemented.\n", func);
21212839Sgabeblack@google.com}
21312839Sgabeblack@google.com
21412839Sgabeblack@google.com} // namespace sc_core
21512839Sgabeblack@google.com
21612839Sgabeblack@google.comnamespace sc_unnamed
21712839Sgabeblack@google.com{
21812839Sgabeblack@google.com
21912839Sgabeblack@google.comImplementationDefined _1;
22012839Sgabeblack@google.comImplementationDefined _2;
22112839Sgabeblack@google.comImplementationDefined _3;
22212839Sgabeblack@google.comImplementationDefined _4;
22312839Sgabeblack@google.comImplementationDefined _5;
22412839Sgabeblack@google.comImplementationDefined _6;
22512839Sgabeblack@google.comImplementationDefined _7;
22612839Sgabeblack@google.comImplementationDefined _8;
22712839Sgabeblack@google.comImplementationDefined _9;
22812839Sgabeblack@google.com
22912839Sgabeblack@google.com} // namespace sc_unnamed
230