diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2018-02-16 16:11:13 -0600 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2018-03-01 09:09:06 -0600 |
commit | 32affb9879b18226b3a026072ce1753f03b7ca58 (patch) | |
tree | 904d3601317005055d5b7c9a7e08ed6896d9733f | |
parent | 069e4405a6926cdacc33c0826075356da2cd9dbd (diff) | |
download | phosphor-fan-presence-32affb9879b18226b3a026072ce1753f03b7ca58.tar.gz phosphor-fan-presence-32affb9879b18226b3a026072ce1753f03b7ca58.zip |
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>
-rw-r--r-- | monitor/fan.cpp | 2 | ||||
-rw-r--r-- | monitor/fan.hpp | 2 | ||||
-rw-r--r-- | monitor/nonzero_speed_trust.hpp | 2 | ||||
-rw-r--r-- | monitor/trust_group.hpp | 17 | ||||
-rw-r--r-- | monitor/trust_manager.hpp | 2 |
5 files changed, 12 insertions, 13 deletions
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<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 @@ class Fan /** * 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 @@ 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<monitor::TachSensor>& sensor) + void registerSensor(std::shared_ptr<monitor::TachSensor>& 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<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 @@ class Group * * 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 @@ class Manager * @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(), |