diff options
Diffstat (limited to 'src/systemc/core/process.hh')
-rw-r--r-- | src/systemc/core/process.hh | 277 |
1 files changed, 16 insertions, 261 deletions
diff --git a/src/systemc/core/process.hh b/src/systemc/core/process.hh index d399d7a3d..0a312e28e 100644 --- a/src/systemc/core/process.hh +++ b/src/systemc/core/process.hh @@ -35,19 +35,14 @@ #include <vector> #include "base/fiber.hh" -#include "sim/eventq.hh" #include "systemc/core/bindinfo.hh" -#include "systemc/core/event.hh" #include "systemc/core/list.hh" #include "systemc/core/object.hh" #include "systemc/core/sched_event.hh" +#include "systemc/core/sensitivity.hh" #include "systemc/ext/core/sc_event.hh" -#include "systemc/ext/core/sc_export.hh" -#include "systemc/ext/core/sc_interface.hh" #include "systemc/ext/core/sc_module.hh" -#include "systemc/ext/core/sc_port.hh" #include "systemc/ext/core/sc_process_handle.hh" -#include "systemc/ext/utils/sc_report.hh" namespace sc_core { @@ -62,233 +57,6 @@ namespace sc_gem5 class ScHalt {}; -class Sensitivity -{ - protected: - Process *process; - - public: - Sensitivity(Process *p) : process(p) {} - virtual ~Sensitivity() {} - - void satisfy(bool timedOut=false); - - virtual void notifyWork(Event *e) { satisfy(); } - void notify(Event *e); - void notify() { notify(nullptr); } - - const std::string name(); -}; - -class SensitivityTimeout : virtual public Sensitivity -{ - private: - void timeout(); - ScEvent timeoutEvent; - - public: - SensitivityTimeout(Process *p, ::sc_core::sc_time t); - ~SensitivityTimeout(); -}; - -class SensitivityEvent : virtual public Sensitivity -{ - private: - const ::sc_core::sc_event *event; - - public: - SensitivityEvent(Process *p, const ::sc_core::sc_event *e); - ~SensitivityEvent(); -}; - -//XXX This sensitivity can't be reused. To reset it, it has to be deleted and -//recreated. That works for dynamic sensitivities, but not for static. -//Fortunately processes can't be statically sensitive to sc_event_and_lists. -class SensitivityEventAndList : virtual public Sensitivity -{ - private: - const ::sc_core::sc_event_and_list *list; - int count; - - public: - SensitivityEventAndList( - Process *p, const ::sc_core::sc_event_and_list *list); - ~SensitivityEventAndList(); - - void notifyWork(Event *e) override; -}; - -class SensitivityEventOrList : virtual public Sensitivity -{ - private: - const ::sc_core::sc_event_or_list *list; - - public: - SensitivityEventOrList( - Process *p, const ::sc_core::sc_event_or_list *list); - ~SensitivityEventOrList(); -}; - -// Combined sensitivities. These trigger when any of their parts do. - -class SensitivityTimeoutAndEvent : - public SensitivityTimeout, public SensitivityEvent -{ - public: - SensitivityTimeoutAndEvent( - Process *p, ::sc_core::sc_time t, const ::sc_core::sc_event *e) : - Sensitivity(p), SensitivityTimeout(p, t), SensitivityEvent(p, e) - {} - - void notifyWork(Event *e) override { satisfy(e == nullptr); } -}; - -class SensitivityTimeoutAndEventAndList : - public SensitivityTimeout, public SensitivityEventAndList -{ - public: - SensitivityTimeoutAndEventAndList( - Process *p, ::sc_core::sc_time t, - const ::sc_core::sc_event_and_list *eal) : - Sensitivity(p), SensitivityTimeout(p, t), - SensitivityEventAndList(p, eal) - {} - - void notifyWork(Event *e) override; -}; - -class SensitivityTimeoutAndEventOrList : - public SensitivityTimeout, public SensitivityEventOrList -{ - public: - SensitivityTimeoutAndEventOrList( - Process *p, ::sc_core::sc_time t, - const ::sc_core::sc_event_or_list *eol) : - Sensitivity(p), SensitivityTimeout(p, t), - SensitivityEventOrList(p, eol) - {} - - void notifyWork(Event *e) override { satisfy(e == nullptr); } -}; - -typedef std::vector<Sensitivity *> Sensitivities; - - -/* - * Pending sensitivities. These are records of sensitivities to install later, - * once all the information to configure them is available. - */ - -class PendingSensitivity -{ - protected: - Process *process; - - public: - virtual void finalize(Sensitivities &s) = 0; - PendingSensitivity(Process *p) : process(p) {} - virtual ~PendingSensitivity() {} -}; - -class PendingSensitivityEvent : public PendingSensitivity -{ - private: - const sc_core::sc_event *event; - - public: - PendingSensitivityEvent(Process *p, const sc_core::sc_event *e) : - PendingSensitivity(p), event(e) {} - - void - finalize(Sensitivities &s) override - { - s.push_back(new SensitivityEvent(process, event)); - } -}; - -class PendingSensitivityInterface : public PendingSensitivity -{ - private: - const sc_core::sc_interface *interface; - - public: - PendingSensitivityInterface(Process *p, const sc_core::sc_interface *i) : - PendingSensitivity(p), interface(i) - {} - - void - finalize(Sensitivities &s) override - { - s.push_back(new SensitivityEvent(process, - &interface->default_event())); - } -}; - -class PendingSensitivityPort : public PendingSensitivity -{ - private: - const sc_core::sc_port_base *port; - - public: - PendingSensitivityPort(Process *p, const sc_core::sc_port_base *pb) : - PendingSensitivity(p), port(pb) - {} - - void - finalize(Sensitivities &s) override - { - for (int i = 0; i < port->size(); i++) { - const ::sc_core::sc_event *e = - &port->_gem5Interface(i)->default_event(); - s.push_back(new SensitivityEvent(process, e)); - } - } -}; - -class PendingSensitivityExport : public PendingSensitivity -{ - private: - const sc_core::sc_export_base *exp; - - public: - PendingSensitivityExport(Process *p, const sc_core::sc_export_base *exp) : - PendingSensitivity(p), exp(exp) - {} - - void - finalize(Sensitivities &s) override - { - s.push_back(new SensitivityEvent(process, - &exp->get_interface()->default_event())); - } -}; - -class PendingSensitivityFinder : public PendingSensitivity -{ - private: - const sc_core::sc_event_finder *finder; - - public: - PendingSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) : - PendingSensitivity(p), finder(f) - {} - - void - finalize(Sensitivities &s) override - { - const ::sc_core::sc_port_base *port = finder->port(); - int size = port->size(); - for (int i = 0; i < size; i++) { - ::sc_core::sc_interface *interface = port->_gem5Interface(i); - const ::sc_core::sc_event *event = &finder->find_event(interface); - s.push_back(new SensitivityEvent(process, event)); - } - } -}; - -typedef std::vector<PendingSensitivity *> PendingSensitivities; - - class Process : public ::sc_core::sc_process_b, public ListNode { public: @@ -332,8 +100,13 @@ class Process : public ::sc_core::sc_process_b, public ListNode void run(); - void addStatic(PendingSensitivity *); - void setDynamic(Sensitivity *); + void addStatic(StaticSensitivity *); + void setDynamic(DynamicSensitivity *); + void clearDynamic() { setDynamic(nullptr); } + + ScEvent timeoutEvent; + void setTimeout(::sc_core::sc_time t); + void cancelTimeout(); void satisfySensitivity(Sensitivity *); @@ -349,7 +122,6 @@ class Process : public ::sc_core::sc_process_b, public ListNode bool hasStaticSensitivities() { return !staticSensitivities.empty(); } bool internal() { return _internal; } bool timedOut() { return _timedOut; } - void timedOut(bool to) { _timedOut = to; } bool dontInitialize() { return _dontInitialize; } void dontInitialize(bool di) { _dontInitialize = di; } @@ -357,6 +129,8 @@ class Process : public ::sc_core::sc_process_b, public ListNode void joinWait(::sc_core::sc_join *join) { joinWaiters.push_back(join); } protected: + void timeout(); + Process(const char *name, ProcessFuncWrapper *func, bool internal=false); static Process *_newest; @@ -365,8 +139,11 @@ class Process : public ::sc_core::sc_process_b, public ListNode { popListNode(); delete func; - for (auto s: staticSensitivities) + for (auto s: staticSensitivities) { + s->clear(); delete s; + } + clearDynamic(); } ::sc_core::sc_event _resetEvent; @@ -399,36 +176,14 @@ class Process : public ::sc_core::sc_process_b, public ListNode size_t stackSize; - Sensitivities staticSensitivities; - PendingSensitivities pendingStaticSensitivities; - - Sensitivity *dynamicSensitivity; + StaticSensitivities staticSensitivities; + DynamicSensitivity *dynamicSensitivity; std::unique_ptr<::sc_core::sc_report> _lastReport; std::vector<::sc_core::sc_join *> joinWaiters; }; -inline void -Sensitivity::satisfy(bool timedOut) -{ - process->timedOut(timedOut); - process->satisfySensitivity(this); -} - -inline void -Sensitivity::notify(Event *e) -{ - if (!process->disabled()) - notifyWork(e); -} - -inline const std::string -Sensitivity::name() -{ - return std::string(process->name()) + ".timeout"; -} - } // namespace sc_gem5 #endif //__SYSTEMC_CORE_PROCESS_HH__ |