#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
#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"
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