process.hh revision 12952:94fca7e8120b
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#ifndef __SYSTEMC_CORE_PROCESS_HH__ 31#define __SYSTEMC_CORE_PROCESS_HH__ 32 33#include <functional> 34 35#include "base/fiber.hh" 36#include "systemc/core/object.hh" 37#include "systemc/ext/core/sc_event.hh" 38#include "systemc/ext/core/sc_module.hh" 39#include "systemc/ext/core/sc_process_handle.hh" 40 41namespace sc_gem5 42{ 43 44class Process : public ::sc_core::sc_object 45{ 46 public: 47 virtual ::sc_core::sc_curr_proc_kind procKind() const = 0; 48 bool dynamic() const { return _dynamic; } 49 bool isUnwinding() const { return _isUnwinding; } 50 bool terminated() const { return _terminated; } 51 52 void forEachKid(const std::function<void(Process *)> &work); 53 54 bool suspended() const { return _suspended; } 55 bool disabled() const { return _disabled; } 56 57 void suspend(bool inc_kids); 58 void resume(bool inc_kids); 59 void disable(bool inc_kids); 60 void enable(bool inc_kids); 61 62 void kill(bool inc_kids); 63 void reset(bool inc_kids); 64 virtual void throw_it(ExceptionWrapperBase &exc, bool inc_kids); 65 66 void injectException(ExceptionWrapperBase &exc); 67 ExceptionWrapperBase *excWrapper; 68 69 void syncResetOn(bool inc_kids); 70 void syncResetOff(bool inc_kids); 71 72 void incref() { refCount++; } 73 void decref() { refCount--; } 74 75 const ::sc_core::sc_event &resetEvent() { return _resetEvent; } 76 const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; } 77 78 protected: 79 Process(const char *name, ProcessFuncWrapper *func, bool _dynamic) : 80 ::sc_core::sc_object(name), func(func), _dynamic(_dynamic), 81 _isUnwinding(false), _terminated(false), _suspended(false), 82 _disabled(false), _syncReset(false), refCount(0) 83 {} 84 85 virtual ~Process() { delete func; } 86 87 ::sc_core::sc_event _resetEvent; 88 ::sc_core::sc_event _terminatedEvent; 89 90 ProcessFuncWrapper *func; 91 sc_core::sc_curr_proc_kind _procKind; 92 bool _dynamic; 93 bool _isUnwinding; 94 bool _terminated; 95 96 bool _suspended; 97 bool _disabled; 98 99 bool _syncReset; 100 101 int refCount; 102}; 103 104class Method : public Process 105{ 106 public: 107 Method(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) : 108 Process(name, func, _dynamic) 109 {} 110 111 const char *kind() const override { return "sc_method_process"; } 112 113 sc_core::sc_curr_proc_kind 114 procKind() const override 115 { 116 return sc_core::SC_METHOD_PROC_; 117 } 118}; 119 120class Thread : public Process 121{ 122 public: 123 Thread(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) : 124 Process(name, func, _dynamic) 125 {} 126 127 const char *kind() const override { return "sc_thread_process"; } 128 129 void throw_it(ExceptionWrapperBase &exc, bool inc_kids) override; 130 131 sc_core::sc_curr_proc_kind 132 procKind() const override 133 { 134 return sc_core::SC_THREAD_PROC_; 135 } 136}; 137 138class CThread : public Thread 139{ 140 public: 141 CThread(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) : 142 Thread(name, func, _dynamic) 143 {} 144 145 const char *kind() const override { return "sc_cthread_process"; } 146 147 sc_core::sc_curr_proc_kind 148 procKind() const override 149 { 150 return sc_core::SC_CTHREAD_PROC_; 151 } 152}; 153 154} // namespace sc_gem5 155 156#endif //__SYSTEMC_CORE_PROCESS_HH__ 157