Daniel Carvalho has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/38178 )
Change subject: base: Use smart pointer for info's storageParams
......................................................................
base: Use smart pointer for info's storageParams
Previously the storage params were not being deallocated. Make
sure this happens by managing it with smart pointers.
As a side effect, encapsulate this variable to facilitate future
changes.
Change-Id: I4c2496d08241f155793ed35e3463512d9ea06f83
Signed-off-by: Daniel R. Carvalho <[email protected]>
---
M src/base/statistics.cc
M src/base/statistics.hh
M src/base/stats/info.cc
M src/base/stats/info.hh
4 files changed, 43 insertions(+), 21 deletions(-)
diff --git a/src/base/statistics.cc b/src/base/statistics.cc
index bc411f7..844e54a 100644
--- a/src/base/statistics.cc
+++ b/src/base/statistics.cc
@@ -96,7 +96,7 @@
void
InfoAccess::setParams(const StorageParams *params)
{
- info()->storageParams = params;
+ info()->setStorageParams(params);
}
void
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index b562837..d0d26ca 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.hh
@@ -410,7 +410,7 @@
size_t size = self.size();
for (off_type i = 0; i < size; ++i)
- self.data(i)->prepare(info->storageParams);
+ self.data(i)->prepare(info->getStorageParams());
}
void
@@ -421,7 +421,7 @@
size_t size = self.size();
for (off_type i = 0; i < size; ++i)
- self.data(i)->reset(info->storageParams);
+ self.data(i)->reset(info->getStorageParams());
}
};
@@ -520,7 +520,7 @@
void
doInit()
{
- new (storage) Storage(this->info()->storageParams);
+ new (storage) Storage(this->info()->getStorageParams());
this->setInit();
}
@@ -592,8 +592,8 @@
bool zero() const { return result() == 0.0; }
- void reset() { data()->reset(this->info()->storageParams); }
- void prepare() { data()->prepare(this->info()->storageParams); }
+ void reset() { data()->reset(this->info()->getStorageParams()); }
+ void prepare() { data()->prepare(this->info()->getStorageParams()); }
};
class ProxyInfo : public ScalarInfo
@@ -918,7 +918,7 @@
fatal_if(s <= 0, "Storage size must be positive");
fatal_if(check(), "Stat has already been initialized");
- storage.resize(s, new Storage(this->info()->storageParams));
+ storage.resize(s, new Storage(this->info()->getStorageParams()));
this->setInit();
}
@@ -1140,7 +1140,7 @@
info->x = _x;
info->y = _y;
- storage.resize(x * y, new Storage(info->storageParams));
+ storage.resize(x * y, new Storage(info->getStorageParams()));
this->setInit();
return self;
@@ -1187,7 +1187,7 @@
size_type size = this->size();
for (off_type i = 0; i < size; ++i)
- data(i)->prepare(info->storageParams);
+ data(i)->prepare(info->getStorageParams());
info->cvec.resize(size);
for (off_type i = 0; i < size; ++i)
@@ -1203,7 +1203,7 @@
Info *info = this->info();
size_type size = this->size();
for (off_type i = 0; i < size; ++i)
- data(i)->reset(info->storageParams);
+ data(i)->reset(info->getStorageParams());
}
bool
@@ -1259,7 +1259,7 @@
void
doInit()
{
- new (storage) Storage(this->info()->storageParams);
+ new (storage) Storage(this->info()->getStorageParams());
this->setInit();
}
@@ -1293,7 +1293,7 @@
prepare()
{
Info *info = this->info();
- data()->prepare(info->storageParams, info->data);
+ data()->prepare(info->getStorageParams(), info->data);
}
/**
@@ -1302,7 +1302,7 @@
void
reset()
{
- data()->reset(this->info()->storageParams);
+ data()->reset(this->info()->getStorageParams());
}
/**
@@ -1347,7 +1347,7 @@
fatal_if(s <= 0, "Storage size must be positive");
fatal_if(check(), "Stat has already been initialized");
- storage.resize(s, new Storage(this->info()->storageParams));
+ storage.resize(s, new Storage(this->info()->getStorageParams()));
this->setInit();
}
@@ -1392,7 +1392,7 @@
size_type size = this->size();
info->data.resize(size);
for (off_type i = 0; i < size; ++i)
- data(i)->prepare(info->storageParams, info->data[i]);
+ data(i)->prepare(info->getStorageParams(), info->data[i]);
}
bool
@@ -2213,7 +2213,7 @@
void
doInit()
{
- new (storage) Storage(this->info()->storageParams);
+ new (storage) Storage(this->info()->getStorageParams());
this->setInit();
}
@@ -2247,7 +2247,7 @@
prepare()
{
Info *info = this->info();
- data()->prepare(info->storageParams, info->data);
+ data()->prepare(info->getStorageParams(), info->data);
}
/**
@@ -2256,7 +2256,7 @@
void
reset()
{
- data()->reset(this->info()->storageParams);
+ data()->reset(this->info()->getStorageParams());
}
};
diff --git a/src/base/stats/info.cc b/src/base/stats/info.cc
index b0f777c..ab46199 100644
--- a/src/base/stats/info.cc
+++ b/src/base/stats/info.cc
@@ -48,6 +48,7 @@
#include "base/cprintf.hh"
#include "base/debug.hh"
#include "base/logging.hh"
+#include "base/stats/storage.hh"
#include "base/str.hh"
namespace Stats {
@@ -97,7 +98,7 @@
}
Info::Info()
- : flags(none), precision(-1), prereq(0), storageParams(NULL)
+ : flags(none), precision(-1), prereq(0), storageParams()
{
id = id_count++;
if (debug_break_id >= 0 and debug_break_id == id)
@@ -108,6 +109,18 @@
{
}
+StorageParams const*
+Info::getStorageParams() const
+{
+ return storageParams.get();
+}
+
+void
+Info::setStorageParams(const StorageParams *const params)
+{
+ return storageParams.reset(params);
+}
+
void
Info::setName(const std::string &name)
{
diff --git a/src/base/stats/info.hh b/src/base/stats/info.hh
index 632d13c..37921f7 100644
--- a/src/base/stats/info.hh
+++ b/src/base/stats/info.hh
@@ -88,13 +88,22 @@
static int id_count;
int id;
- public:
- const StorageParams *storageParams;
+ private:
+ std::unique_ptr<const StorageParams> storageParams;
public:
Info();
virtual ~Info();
+ /**
+ * Getter for the storage params. These parameters should only be
modified
+ * using the respective setter.
+ * @sa setStorageParams
+ */
+ StorageParams const* getStorageParams() const;
+ /** Setter for the storage params. */
+ void setStorageParams(const StorageParams *const params);
+
/** Set the name of this statistic */
void setName(const std::string &name);
void setName(const Group *parent, const std::string &name);
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/38178
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I4c2496d08241f155793ed35e3463512d9ea06f83
Gerrit-Change-Number: 38178
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s