From: Gabe Black Date: Wed, 26 Sep 2018 06:59:32 +0000 (-0700) Subject: systemc: Implement sc_event_queue. X-Git-Tag: v19.0.0.0~1561 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fc752d3f3c967557e28f42664b86c18e027e8eec;p=gem5.git systemc: Implement sc_event_queue. Change-Id: I58fd72b8c64ee82eb478d810f7114bab7a31cbfa Reviewed-on: https://gem5-review.googlesource.com/c/13184 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/systemc/channel/sc_event_queue.cc b/src/systemc/channel/sc_event_queue.cc index 47485fdc0..50cf2d278 100644 --- a/src/systemc/channel/sc_event_queue.cc +++ b/src/systemc/channel/sc_event_queue.cc @@ -29,41 +29,55 @@ #include "base/logging.hh" #include "systemc/ext/channel/sc_event_queue.hh" +#include "systemc/ext/core/sc_main.hh" +#include "systemc/ext/core/sc_time.hh" namespace sc_core { sc_event_queue::sc_event_queue(sc_module_name name) : sc_interface(), sc_event_queue_if(), sc_module(name) -{} +{ + SC_METHOD(_trigger); + dont_initialize(); + sensitive << _defaultEvent; +} sc_event_queue::~sc_event_queue() {} -const char *sc_event_queue::kind() const { return "sc_event_queue"; } - void -sc_event_queue::notify(double, sc_time_unit) +sc_event_queue::notify(double d, sc_time_unit tu) { - warn("%s not implemented.\n", __PRETTY_FUNCTION__); + notify(sc_time(d, tu)); } void -sc_event_queue::notify(const sc_time &) +sc_event_queue::notify(const sc_time &t) { - warn("%s not implemented.\n", __PRETTY_FUNCTION__); + _times.push(sc_time_stamp() + t); + _defaultEvent.notify(_times.top() - sc_time_stamp()); } void sc_event_queue::cancel_all() { - warn("%s not implemented.\n", __PRETTY_FUNCTION__); + _defaultEvent.cancel(); + _times = std::priority_queue< + sc_time, std::vector, std::greater >(); } const sc_event & sc_event_queue::default_event() const { - warn("%s not implemented.\n", __PRETTY_FUNCTION__); - return *(const sc_event *)nullptr; + return _defaultEvent; +} + +void +sc_event_queue::_trigger() +{ + _times.pop(); + if (!_times.empty()) + _defaultEvent.notify(_times.top() - sc_time_stamp()); } } // namespace sc_core diff --git a/src/systemc/ext/channel/sc_event_queue.hh b/src/systemc/ext/channel/sc_event_queue.hh index 1cd3c01ab..93a6e258e 100644 --- a/src/systemc/ext/channel/sc_event_queue.hh +++ b/src/systemc/ext/channel/sc_event_queue.hh @@ -30,6 +30,9 @@ #ifndef __SYSTEMC_EXT_CHANNEL_SC_EVENT_QUEUE_HH__ #define __SYSTEMC_EXT_CHANNEL_SC_EVENT_QUEUE_HH__ +#include + +#include "../core/sc_event.hh" #include "../core/sc_interface.hh" #include "../core/sc_module.hh" // for sc_gen_unique_name #include "../core/sc_module_name.hh" @@ -53,17 +56,26 @@ class sc_event_queue_if : public virtual sc_interface class sc_event_queue : public sc_event_queue_if, public sc_module { public: + SC_HAS_PROCESS(sc_event_queue); + sc_event_queue(sc_module_name name= sc_module_name(sc_gen_unique_name("event_queue"))); ~sc_event_queue(); - virtual const char *kind() const; + virtual const char *kind() const { return "sc_event_queue"; } virtual void notify(double, sc_time_unit); virtual void notify(const sc_time &); virtual void cancel_all(); virtual const sc_event &default_event() const; + + private: + void _trigger(); + + sc_event _defaultEvent; + std::priority_queue< + sc_time, std::vector, std::greater > _times; }; // Nonstandard