process.hh revision 12952
112952Sgabeblack@google.com/*
212952Sgabeblack@google.com * Copyright 2018 Google, Inc.
312952Sgabeblack@google.com *
412952Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512952Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612952Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812952Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012952Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112952Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212952Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312952Sgabeblack@google.com * this software without specific prior written permission.
1412952Sgabeblack@google.com *
1512952Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612952Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712952Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812952Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912952Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012952Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112952Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212952Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312952Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412952Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512952Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612952Sgabeblack@google.com *
2712952Sgabeblack@google.com * Authors: Gabe Black
2812952Sgabeblack@google.com */
2912952Sgabeblack@google.com
3012952Sgabeblack@google.com#ifndef __SYSTEMC_CORE_PROCESS_HH__
3112952Sgabeblack@google.com#define __SYSTEMC_CORE_PROCESS_HH__
3212952Sgabeblack@google.com
3312952Sgabeblack@google.com#include <functional>
3412952Sgabeblack@google.com
3512952Sgabeblack@google.com#include "base/fiber.hh"
3612952Sgabeblack@google.com#include "systemc/core/object.hh"
3712952Sgabeblack@google.com#include "systemc/ext/core/sc_event.hh"
3812952Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
3912952Sgabeblack@google.com#include "systemc/ext/core/sc_process_handle.hh"
4012952Sgabeblack@google.com
4112952Sgabeblack@google.comnamespace sc_gem5
4212952Sgabeblack@google.com{
4312952Sgabeblack@google.com
4412952Sgabeblack@google.comclass Process : public ::sc_core::sc_object
4512952Sgabeblack@google.com{
4612952Sgabeblack@google.com  public:
4712952Sgabeblack@google.com    virtual ::sc_core::sc_curr_proc_kind procKind() const = 0;
4812952Sgabeblack@google.com    bool dynamic() const { return _dynamic; }
4912952Sgabeblack@google.com    bool isUnwinding() const { return _isUnwinding; }
5012952Sgabeblack@google.com    bool terminated() const { return _terminated; }
5112952Sgabeblack@google.com
5212952Sgabeblack@google.com    void forEachKid(const std::function<void(Process *)> &work);
5312952Sgabeblack@google.com
5412952Sgabeblack@google.com    bool suspended() const { return _suspended; }
5512952Sgabeblack@google.com    bool disabled() const { return _disabled; }
5612952Sgabeblack@google.com
5712952Sgabeblack@google.com    void suspend(bool inc_kids);
5812952Sgabeblack@google.com    void resume(bool inc_kids);
5912952Sgabeblack@google.com    void disable(bool inc_kids);
6012952Sgabeblack@google.com    void enable(bool inc_kids);
6112952Sgabeblack@google.com
6212952Sgabeblack@google.com    void kill(bool inc_kids);
6312952Sgabeblack@google.com    void reset(bool inc_kids);
6412952Sgabeblack@google.com    virtual void throw_it(ExceptionWrapperBase &exc, bool inc_kids);
6512952Sgabeblack@google.com
6612952Sgabeblack@google.com    void injectException(ExceptionWrapperBase &exc);
6712952Sgabeblack@google.com    ExceptionWrapperBase *excWrapper;
6812952Sgabeblack@google.com
6912952Sgabeblack@google.com    void syncResetOn(bool inc_kids);
7012952Sgabeblack@google.com    void syncResetOff(bool inc_kids);
7112952Sgabeblack@google.com
7212952Sgabeblack@google.com    void incref() { refCount++; }
7312952Sgabeblack@google.com    void decref() { refCount--; }
7412952Sgabeblack@google.com
7512952Sgabeblack@google.com    const ::sc_core::sc_event &resetEvent() { return _resetEvent; }
7612952Sgabeblack@google.com    const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; }
7712952Sgabeblack@google.com
7812952Sgabeblack@google.com  protected:
7912952Sgabeblack@google.com    Process(const char *name, ProcessFuncWrapper *func, bool _dynamic) :
8012952Sgabeblack@google.com        ::sc_core::sc_object(name), func(func), _dynamic(_dynamic),
8112952Sgabeblack@google.com        _isUnwinding(false), _terminated(false), _suspended(false),
8212952Sgabeblack@google.com        _disabled(false), _syncReset(false), refCount(0)
8312952Sgabeblack@google.com    {}
8412952Sgabeblack@google.com
8512952Sgabeblack@google.com    virtual ~Process() { delete func; }
8612952Sgabeblack@google.com
8712952Sgabeblack@google.com    ::sc_core::sc_event _resetEvent;
8812952Sgabeblack@google.com    ::sc_core::sc_event _terminatedEvent;
8912952Sgabeblack@google.com
9012952Sgabeblack@google.com    ProcessFuncWrapper *func;
9112952Sgabeblack@google.com    sc_core::sc_curr_proc_kind _procKind;
9212952Sgabeblack@google.com    bool _dynamic;
9312952Sgabeblack@google.com    bool _isUnwinding;
9412952Sgabeblack@google.com    bool _terminated;
9512952Sgabeblack@google.com
9612952Sgabeblack@google.com    bool _suspended;
9712952Sgabeblack@google.com    bool _disabled;
9812952Sgabeblack@google.com
9912952Sgabeblack@google.com    bool _syncReset;
10012952Sgabeblack@google.com
10112952Sgabeblack@google.com    int refCount;
10212952Sgabeblack@google.com};
10312952Sgabeblack@google.com
10412952Sgabeblack@google.comclass Method : public Process
10512952Sgabeblack@google.com{
10612952Sgabeblack@google.com  public:
10712952Sgabeblack@google.com    Method(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) :
10812952Sgabeblack@google.com        Process(name, func, _dynamic)
10912952Sgabeblack@google.com    {}
11012952Sgabeblack@google.com
11112952Sgabeblack@google.com    const char *kind() const override { return "sc_method_process"; }
11212952Sgabeblack@google.com
11312952Sgabeblack@google.com    sc_core::sc_curr_proc_kind
11412952Sgabeblack@google.com    procKind() const override
11512952Sgabeblack@google.com    {
11612952Sgabeblack@google.com        return sc_core::SC_METHOD_PROC_;
11712952Sgabeblack@google.com    }
11812952Sgabeblack@google.com};
11912952Sgabeblack@google.com
12012952Sgabeblack@google.comclass Thread : public Process
12112952Sgabeblack@google.com{
12212952Sgabeblack@google.com  public:
12312952Sgabeblack@google.com    Thread(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) :
12412952Sgabeblack@google.com        Process(name, func, _dynamic)
12512952Sgabeblack@google.com    {}
12612952Sgabeblack@google.com
12712952Sgabeblack@google.com    const char *kind() const override { return "sc_thread_process"; }
12812952Sgabeblack@google.com
12912952Sgabeblack@google.com    void throw_it(ExceptionWrapperBase &exc, bool inc_kids) override;
13012952Sgabeblack@google.com
13112952Sgabeblack@google.com    sc_core::sc_curr_proc_kind
13212952Sgabeblack@google.com    procKind() const override
13312952Sgabeblack@google.com    {
13412952Sgabeblack@google.com        return sc_core::SC_THREAD_PROC_;
13512952Sgabeblack@google.com    }
13612952Sgabeblack@google.com};
13712952Sgabeblack@google.com
13812952Sgabeblack@google.comclass CThread : public Thread
13912952Sgabeblack@google.com{
14012952Sgabeblack@google.com  public:
14112952Sgabeblack@google.com    CThread(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) :
14212952Sgabeblack@google.com        Thread(name, func, _dynamic)
14312952Sgabeblack@google.com    {}
14412952Sgabeblack@google.com
14512952Sgabeblack@google.com    const char *kind() const override { return "sc_cthread_process"; }
14612952Sgabeblack@google.com
14712952Sgabeblack@google.com    sc_core::sc_curr_proc_kind
14812952Sgabeblack@google.com    procKind() const override
14912952Sgabeblack@google.com    {
15012952Sgabeblack@google.com        return sc_core::SC_CTHREAD_PROC_;
15112952Sgabeblack@google.com    }
15212952Sgabeblack@google.com};
15312952Sgabeblack@google.com
15412952Sgabeblack@google.com} // namespace sc_gem5
15512952Sgabeblack@google.com
15612952Sgabeblack@google.com#endif  //__SYSTEMC_CORE_PROCESS_HH__
157