From: Gabe Black Date: Sat, 21 Jul 2018 00:18:22 +0000 (-0700) Subject: systemc: Fix a couple memory errors. X-Git-Tag: v19.0.0.0~1831 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=be38309891b4adb91e9a6b56923f1f9e82487e61;p=gem5.git systemc: Fix a couple memory errors. Because events are held in vectors, it doesn't make sense to keep an iterator into the parent to keep track of where that event is for easy removal since the iterator becomes invalid when the vector is changed. The events need to be stored in a vector because systemc defines an accessor which returns that vector, and building a vector on the fly would be cumbersome. Also, make sure the Event parent pointer is set to nullptr if there isn't a parent. Change-Id: I63a676190e7747e60baaca50009161d47bfc1c54 Reviewed-on: https://gem5-review.googlesource.com/12039 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/systemc/core/event.cc b/src/systemc/core/event.cc index 1623cf9e8..05670fe59 100644 --- a/src/systemc/core/event.cc +++ b/src/systemc/core/event.cc @@ -29,6 +29,7 @@ #include "systemc/core/event.hh" +#include #include #include @@ -51,12 +52,14 @@ Event::Event(sc_core::sc_event *_sc_event, const char *_basename) : parent = p->obj()->sc_obj(); else if (scheduler.current()) parent = scheduler.current(); + else + parent = nullptr; if (parent) { Object *obj = Object::getFromScObject(parent); - parentIt = obj->addChildEvent(_sc_event); + obj->addChildEvent(_sc_event); } else { - parentIt = topLevelEvents.emplace(topLevelEvents.end(), _sc_event); + topLevelEvents.emplace(topLevelEvents.end(), _sc_event); } if (parent) @@ -74,9 +77,12 @@ Event::~Event() { if (parent) { Object *obj = Object::getFromScObject(parent); - obj->delChildEvent(parentIt); + obj->delChildEvent(_sc_event); } else { - std::swap(*parentIt, topLevelEvents.back()); + EventsIt it = find(topLevelEvents.begin(), topLevelEvents.end(), + _sc_event); + assert(it != topLevelEvents.end()); + std::swap(*it, topLevelEvents.back()); topLevelEvents.pop_back(); } diff --git a/src/systemc/core/event.hh b/src/systemc/core/event.hh index 6d2f46d42..f9d3b2040 100644 --- a/src/systemc/core/event.hh +++ b/src/systemc/core/event.hh @@ -103,7 +103,6 @@ class Event bool _inHierarchy; sc_core::sc_object *parent; - EventsIt parentIt; void delayedNotify(); EventWrapper delayedNotifyEvent; diff --git a/src/systemc/core/object.cc b/src/systemc/core/object.cc index 39403ca34..13476619b 100644 --- a/src/systemc/core/object.cc +++ b/src/systemc/core/object.cc @@ -29,6 +29,8 @@ #include "systemc/core/object.hh" +#include + #include "base/logging.hh" #include "systemc/core/module.hh" #include "systemc/core/scheduler.hh" @@ -230,8 +232,10 @@ Object::addChildEvent(sc_core::sc_event *e) } void -Object::delChildEvent(EventsIt it) +Object::delChildEvent(sc_core::sc_event *e) { + EventsIt it = std::find(events.begin(), events.end(), e); + assert(it != events.end()); std::swap(*it, events.back()); events.pop_back(); } diff --git a/src/systemc/core/object.hh b/src/systemc/core/object.hh index c87a98b2d..cb759d890 100644 --- a/src/systemc/core/object.hh +++ b/src/systemc/core/object.hh @@ -88,7 +88,7 @@ class Object sc_core::sc_object *sc_obj() { return _sc_obj; } EventsIt addChildEvent(sc_core::sc_event *e); - void delChildEvent(EventsIt it); + void delChildEvent(sc_core::sc_event *e); private: sc_core::sc_object *_sc_obj;