From 32affb9879b18226b3a026072ce1753f03b7ca58 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Fri, 16 Feb 2018 16:11:13 -0600 Subject: 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 --- monitor/fan.cpp | 2 +- monitor/fan.hpp | 2 +- monitor/nonzero_speed_trust.hpp | 2 +- monitor/trust_group.hpp | 17 ++++++++--------- monitor/trust_manager.hpp | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) (limited to 'monitor') 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 @@ Fan::Fan(Mode mode, try { _sensors.emplace_back( - std::make_unique( + std::make_shared( 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 @@ class Fan /** * The sensor objects for the fan */ - std::vector> _sensors; + std::vector> _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 @@ class NonzeroSpeed : public Group _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 @@ class Group * * @param[in] sensor - the TachSensor to register */ - void registerSensor(std::unique_ptr& sensor) + void registerSensor(std::shared_ptr& sensor) { auto found = std::find_if( _names.begin(), @@ -89,7 +89,7 @@ class Group _sensors.end(), [&sensor](const auto& s) { - return sensor.name() == s.get()->name(); + return sensor.name() == s->name(); }) != _sensors.end()); } @@ -107,7 +107,7 @@ class Group _sensors.end(), [](const auto& s) { - s.get()->stopTimer(); + s->stopTimer(); }); } @@ -126,11 +126,11 @@ class Group { //If a sensor isn't functional, then its timer //already expired so don't bother starting it again - if (s.get()->functional() && - static_cast(s.get()->getInput()) != - s.get()->getTarget()) + if (s->functional() && + static_cast(s->getInput()) != + s->getTarget()) { - s.get()->startTimer(); + s->startTimer(); } }); } @@ -194,8 +194,7 @@ class Group * * Added by registerSensor(). */ - std::vector>> _sensors; + std::vector> _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 @@ class Manager * @param[in] sensor - the sensor to register */ void registerSensor( - std::unique_ptr& sensor) + std::shared_ptr& sensor) { std::for_each( groups.begin(), -- cgit v1.2.1