summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-09-25 23:59:32 -0700
committerGabe Black <gabeblack@google.com>2018-10-16 00:34:41 +0000
commitfc752d3f3c967557e28f42664b86c18e027e8eec (patch)
treea524f68308f65859c3180adfb0b2356ef74ceffc /src
parent028e1c56b62b9cab90cbd98dbcb1b5698024b936 (diff)
downloadgem5-fc752d3f3c967557e28f42664b86c18e027e8eec.tar.xz
systemc: Implement sc_event_queue.
Change-Id: I58fd72b8c64ee82eb478d810f7114bab7a31cbfa Reviewed-on: https://gem5-review.googlesource.com/c/13184 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/systemc/channel/sc_event_queue.cc34
-rw-r--r--src/systemc/ext/channel/sc_event_queue.hh14
2 files changed, 37 insertions, 11 deletions
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<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 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 <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_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<sc_time>, std::greater<sc_time> > _times;
};
// Nonstandard