Gabe Black has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/13184 )

Change subject: systemc: Implement sc_event_queue.
......................................................................

systemc: Implement sc_event_queue.

Change-Id: I58fd72b8c64ee82eb478d810f7114bab7a31cbfa
Reviewed-on: https://gem5-review.googlesource.com/c/13184
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/systemc/channel/sc_event_queue.cc
M src/systemc/ext/channel/sc_event_queue.hh
2 files changed, 37 insertions(+), 11 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved



diff --git a/src/systemc/channel/sc_event_queue.cc b/src/systemc/channel/sc_event_queue.cc
index 47485fd..50cf2d2 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<sc_time>, std::greater<sc_time> >();
 }

 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 1cd3c01..93a6e25 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 <queue>
+
+#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 : 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<sc_time>, std::greater<sc_time> > _times;
 };

 // Nonstandard

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/13184
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I58fd72b8c64ee82eb478d810f7114bab7a31cbfa
Gerrit-Change-Number: 13184
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthias Jung <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to