process.hh revision 13285:86dc66ffac35
13806SN/A/* 23806SN/A * Copyright 2018 Google, Inc. 33806SN/A * 43806SN/A * Redistribution and use in source and binary forms, with or without 53806SN/A * modification, are permitted provided that the following conditions are 63806SN/A * met: redistributions of source code must retain the above copyright 73806SN/A * notice, this list of conditions and the following disclaimer; 83806SN/A * redistributions in binary form must reproduce the above copyright 93806SN/A * notice, this list of conditions and the following disclaimer in the 103806SN/A * documentation and/or other materials provided with the distribution; 113806SN/A * neither the name of the copyright holders nor the names of its 123806SN/A * contributors may be used to endorse or promote products derived from 133806SN/A * this software without specific prior written permission. 143806SN/A * 153806SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 163806SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 173806SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 183806SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 193806SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 203806SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 213806SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 223806SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 233806SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 243806SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 253806SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 263806SN/A * 273806SN/A * Authors: Gabe Black 283806SN/A */ 293806SN/A 303806SN/A#ifndef __SYSTEMC_CORE_PROCESS_HH__ 318105Sgblack@eecs.umich.edu#define __SYSTEMC_CORE_PROCESS_HH__ 328105Sgblack@eecs.umich.edu 333806SN/A#include <functional> 343806SN/A#include <memory> 353806SN/A#include <vector> 363806SN/A 373806SN/A#include "base/fiber.hh" 383806SN/A#include "systemc/core/list.hh" 393806SN/A#include "systemc/core/module.hh" 403817SN/A#include "systemc/core/object.hh" 413806SN/A#include "systemc/core/sched_event.hh" 423806SN/A#include "systemc/core/sensitivity.hh" 433806SN/A#include "systemc/ext/core/sc_event.hh" 443806SN/A#include "systemc/ext/core/sc_module.hh" 453806SN/A#include "systemc/ext/core/sc_process_handle.hh" 463806SN/A 473806SN/Anamespace sc_core 487741SN/A{ 493806SN/A 503806SN/Aclass sc_join; 513806SN/A 523817SN/A} // namespace sc_core 533806SN/A 543817SN/Anamespace sc_gem5 553817SN/A{ 563817SN/A 573806SN/Aclass ScHalt 583806SN/A{}; 593806SN/A 603806SN/Aclass Process : public ::sc_core::sc_process_b, public ListNode 613806SN/A{ 623817SN/A public: 633806SN/A virtual ::sc_core::sc_curr_proc_kind procKind() const = 0; 643817SN/A bool needsStart() const { return _needsStart; } 653817SN/A void needsStart(bool ns) { _needsStart = ns; } 663817SN/A bool dynamic() const { return _dynamic; } 673806SN/A bool isUnwinding() const { return _isUnwinding; } 683806SN/A void isUnwinding(bool v) { _isUnwinding = v; } 693806SN/A bool terminated() const { return _terminated; } 703806SN/A 713806SN/A void forEachKid(const std::function<void(Process *)> &work); 723806SN/A 73 bool suspended() const { return _suspended; } 74 bool disabled() const { return _disabled; } 75 76 void suspend(bool inc_kids); 77 void resume(bool inc_kids); 78 void disable(bool inc_kids); 79 void enable(bool inc_kids); 80 81 void kill(bool inc_kids); 82 void reset(bool inc_kids); 83 virtual void throw_it(ExceptionWrapperBase &exc, bool inc_kids); 84 85 void injectException(ExceptionWrapperBase &exc); 86 ExceptionWrapperBase *excWrapper; 87 88 void syncResetOn(bool inc_kids); 89 void syncResetOff(bool inc_kids); 90 91 void signalReset(bool set, bool sync); 92 93 void incref() { refCount++; } 94 void decref() { refCount--; } 95 96 const ::sc_core::sc_event &resetEvent() { return _resetEvent; } 97 const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; } 98 99 void setStackSize(size_t size) { stackSize = size; } 100 101 void run(); 102 103 void addStatic(StaticSensitivity *); 104 void setDynamic(DynamicSensitivity *); 105 void clearDynamic() { setDynamic(nullptr); } 106 void addReset(ResetSensitivity *); 107 108 ScEvent timeoutEvent; 109 void setTimeout(::sc_core::sc_time t); 110 void cancelTimeout(); 111 112 void satisfySensitivity(Sensitivity *); 113 114 void ready(); 115 116 virtual Fiber *fiber() { return Fiber::primaryFiber(); } 117 118 static Process *newest() { return _newest; } 119 120 void lastReport(::sc_core::sc_report *report); 121 ::sc_core::sc_report *lastReport() const; 122 123 bool hasStaticSensitivities() { return !staticSensitivities.empty(); } 124 bool internal() { return _internal; } 125 bool timedOut() { return _timedOut; } 126 bool inReset() { return _syncReset || syncResetCount || asyncResetCount; } 127 128 bool dontInitialize() { return _dontInitialize; } 129 void dontInitialize(bool di) { _dontInitialize = di; } 130 131 void joinWait(::sc_core::sc_join *join) { joinWaiters.push_back(join); } 132 133 void waitCount(int count) { _waitCount = count; } 134 135 const char *uniqueName(const char *seed) { return nameGen.gen(seed); } 136 137 protected: 138 void timeout(); 139 140 Process(const char *name, ProcessFuncWrapper *func, bool internal=false); 141 142 static Process *_newest; 143 144 virtual ~Process() 145 { 146 popListNode(); 147 delete func; 148 for (auto s: staticSensitivities) { 149 s->clear(); 150 delete s; 151 } 152 clearDynamic(); 153 } 154 155 ::sc_core::sc_event _resetEvent; 156 ::sc_core::sc_event _terminatedEvent; 157 158 ProcessFuncWrapper *func; 159 sc_core::sc_curr_proc_kind _procKind; 160 161 bool _internal; 162 163 // Needed to support the deprecated "timed_out" function. 164 bool _timedOut; 165 166 bool _dontInitialize; 167 168 bool _needsStart; 169 bool _dynamic; 170 bool _isUnwinding; 171 bool _terminated; 172 173 void terminate(); 174 175 bool _suspended; 176 bool _suspendedReady; 177 bool _disabled; 178 179 bool _syncReset; 180 181 int syncResetCount; 182 int asyncResetCount; 183 184 int _waitCount; 185 186 int refCount; 187 188 size_t stackSize; 189 190 StaticSensitivities staticSensitivities; 191 DynamicSensitivity *dynamicSensitivity; 192 ResetSensitivities resetSensitivities; 193 194 std::unique_ptr<::sc_core::sc_report> _lastReport; 195 196 std::vector<::sc_core::sc_join *> joinWaiters; 197 198 UniqueNameGen nameGen; 199}; 200 201} // namespace sc_gem5 202 203#endif //__SYSTEMC_CORE_PROCESS_HH__ 204