process.hh revision 12953
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"
3612953Sgabeblack@google.com#include "systemc/core/list.hh"
3712952Sgabeblack@google.com#include "systemc/core/object.hh"
3812952Sgabeblack@google.com#include "systemc/ext/core/sc_event.hh"
3912952Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
4012952Sgabeblack@google.com#include "systemc/ext/core/sc_process_handle.hh"
4112952Sgabeblack@google.com
4212952Sgabeblack@google.comnamespace sc_gem5
4312952Sgabeblack@google.com{
4412952Sgabeblack@google.com
4512953Sgabeblack@google.comclass Process : public ::sc_core::sc_object, public ListNode
4612952Sgabeblack@google.com{
4712952Sgabeblack@google.com  public:
4812952Sgabeblack@google.com    virtual ::sc_core::sc_curr_proc_kind procKind() const = 0;
4912953Sgabeblack@google.com    bool running() const { return _running; }
5012952Sgabeblack@google.com    bool dynamic() const { return _dynamic; }
5112952Sgabeblack@google.com    bool isUnwinding() const { return _isUnwinding; }
5212952Sgabeblack@google.com    bool terminated() const { return _terminated; }
5312952Sgabeblack@google.com
5412952Sgabeblack@google.com    void forEachKid(const std::function<void(Process *)> &work);
5512952Sgabeblack@google.com
5612952Sgabeblack@google.com    bool suspended() const { return _suspended; }
5712952Sgabeblack@google.com    bool disabled() const { return _disabled; }
5812952Sgabeblack@google.com
5912952Sgabeblack@google.com    void suspend(bool inc_kids);
6012952Sgabeblack@google.com    void resume(bool inc_kids);
6112952Sgabeblack@google.com    void disable(bool inc_kids);
6212952Sgabeblack@google.com    void enable(bool inc_kids);
6312952Sgabeblack@google.com
6412952Sgabeblack@google.com    void kill(bool inc_kids);
6512952Sgabeblack@google.com    void reset(bool inc_kids);
6612952Sgabeblack@google.com    virtual void throw_it(ExceptionWrapperBase &exc, bool inc_kids);
6712952Sgabeblack@google.com
6812952Sgabeblack@google.com    void injectException(ExceptionWrapperBase &exc);
6912952Sgabeblack@google.com    ExceptionWrapperBase *excWrapper;
7012952Sgabeblack@google.com
7112952Sgabeblack@google.com    void syncResetOn(bool inc_kids);
7212952Sgabeblack@google.com    void syncResetOff(bool inc_kids);
7312952Sgabeblack@google.com
7412952Sgabeblack@google.com    void incref() { refCount++; }
7512952Sgabeblack@google.com    void decref() { refCount--; }
7612952Sgabeblack@google.com
7712952Sgabeblack@google.com    const ::sc_core::sc_event &resetEvent() { return _resetEvent; }
7812952Sgabeblack@google.com    const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; }
7912952Sgabeblack@google.com
8012953Sgabeblack@google.com    // This should only be called before initialization.
8112953Sgabeblack@google.com    void dontInitialize() { popListNode(); }
8212953Sgabeblack@google.com
8312953Sgabeblack@google.com    void setStackSize(size_t size) { stackSize = size; }
8412953Sgabeblack@google.com
8512953Sgabeblack@google.com    void run();
8612953Sgabeblack@google.com
8712953Sgabeblack@google.com    virtual Fiber *fiber() { return Fiber::primaryFiber(); }
8812953Sgabeblack@google.com
8912953Sgabeblack@google.com    static Process *newest() { return _newest; }
9012953Sgabeblack@google.com
9112952Sgabeblack@google.com  protected:
9212953Sgabeblack@google.com    Process(const char *name, ProcessFuncWrapper *func, bool _dynamic);
9312953Sgabeblack@google.com
9412953Sgabeblack@google.com    static Process *_newest;
9512952Sgabeblack@google.com
9612952Sgabeblack@google.com    virtual ~Process() { delete func; }
9712952Sgabeblack@google.com
9812952Sgabeblack@google.com    ::sc_core::sc_event _resetEvent;
9912952Sgabeblack@google.com    ::sc_core::sc_event _terminatedEvent;
10012952Sgabeblack@google.com
10112952Sgabeblack@google.com    ProcessFuncWrapper *func;
10212952Sgabeblack@google.com    sc_core::sc_curr_proc_kind _procKind;
10312953Sgabeblack@google.com    bool _running;
10412952Sgabeblack@google.com    bool _dynamic;
10512952Sgabeblack@google.com    bool _isUnwinding;
10612952Sgabeblack@google.com    bool _terminated;
10712952Sgabeblack@google.com
10812952Sgabeblack@google.com    bool _suspended;
10912952Sgabeblack@google.com    bool _disabled;
11012952Sgabeblack@google.com
11112952Sgabeblack@google.com    bool _syncReset;
11212952Sgabeblack@google.com
11312952Sgabeblack@google.com    int refCount;
11412952Sgabeblack@google.com
11512953Sgabeblack@google.com    size_t stackSize;
11612952Sgabeblack@google.com};
11712952Sgabeblack@google.com
11812952Sgabeblack@google.com} // namespace sc_gem5
11912952Sgabeblack@google.com
12012952Sgabeblack@google.com#endif  //__SYSTEMC_CORE_PROCESS_HH__
121