optimize: Tach sensors as shared pointers
The fan and trust group objects should utilize shared pointers to the
tach sensor objects. This allows optimizing the storage of additional
attributes associated with the tach sensors.
e.g. An attribute to declare which sensors should be included in the
trust determination.
Tested: Current trust group associations & reactions are unchanged
Change-Id: I249cc7debf467e8275fae7fa157ce97078b40802
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 637a3ca..256d0cb 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -47,7 +47,7 @@
try
{
_sensors.emplace_back(
- std::make_unique<TachSensor>(
+ std::make_shared<TachSensor>(
mode,
bus,
*this,
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index 0b0c047..fb87b66 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -190,7 +190,7 @@
/**
* The sensor objects for the fan
*/
- std::vector<std::unique_ptr<TachSensor>> _sensors;
+ std::vector<std::shared_ptr<TachSensor>> _sensors;
/**
* The tach trust manager object
diff --git a/monitor/nonzero_speed_trust.hpp b/monitor/nonzero_speed_trust.hpp
index 3d14adf..93fce7d 100644
--- a/monitor/nonzero_speed_trust.hpp
+++ b/monitor/nonzero_speed_trust.hpp
@@ -53,7 +53,7 @@
_sensors.end(),
[](const auto& s)
{
- return s.get()->getInput() != 0;
+ return s->getInput() != 0;
});
}
};
diff --git a/monitor/trust_group.hpp b/monitor/trust_group.hpp
index e0db5c9..ff60508 100644
--- a/monitor/trust_group.hpp
+++ b/monitor/trust_group.hpp
@@ -57,7 +57,7 @@
*
* @param[in] sensor - the TachSensor to register
*/
- void registerSensor(std::unique_ptr<monitor::TachSensor>& sensor)
+ void registerSensor(std::shared_ptr<monitor::TachSensor>& sensor)
{
auto found = std::find_if(
_names.begin(),
@@ -89,7 +89,7 @@
_sensors.end(),
[&sensor](const auto& s)
{
- return sensor.name() == s.get()->name();
+ return sensor.name() == s->name();
}) != _sensors.end());
}
@@ -107,7 +107,7 @@
_sensors.end(),
[](const auto& s)
{
- s.get()->stopTimer();
+ s->stopTimer();
});
}
@@ -126,11 +126,11 @@
{
//If a sensor isn't functional, then its timer
//already expired so don't bother starting it again
- if (s.get()->functional() &&
- static_cast<uint64_t>(s.get()->getInput()) !=
- s.get()->getTarget())
+ if (s->functional() &&
+ static_cast<uint64_t>(s->getInput()) !=
+ s->getTarget())
{
- s.get()->startTimer();
+ s->startTimer();
}
});
}
@@ -194,8 +194,7 @@
*
* Added by registerSensor().
*/
- std::vector<std::reference_wrapper<
- std::unique_ptr<monitor::TachSensor>>> _sensors;
+ std::vector<std::shared_ptr<monitor::TachSensor>> _sensors;
private:
diff --git a/monitor/trust_manager.hpp b/monitor/trust_manager.hpp
index d78e647..031d890 100644
--- a/monitor/trust_manager.hpp
+++ b/monitor/trust_manager.hpp
@@ -122,7 +122,7 @@
* @param[in] sensor - the sensor to register
*/
void registerSensor(
- std::unique_ptr<monitor::TachSensor>& sensor)
+ std::shared_ptr<monitor::TachSensor>& sensor)
{
std::for_each(
groups.begin(),