tachsensor: Similar fixes from HwmonTempSensor

Ported the substance of the changes from here to TachSensor:
https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/56019

The goal is to provide similar fixes to I/O and buffering, catching up
to similar changes made recently in HwmonTempSensor.

Tested: Fan RPM now shows up correctly on my machine again.

Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: I49c539e3713e9d02d4584f305e4ced6d4b2ba572
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 9367aac..13902c7 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -154,7 +154,7 @@
     return true;
 }
 void createRedundancySensor(
-    const boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>&
+    const boost::container::flat_map<std::string, std::shared_ptr<TachSensor>>&
         sensors,
     const std::shared_ptr<sdbusplus::asio::connection>& conn,
     sdbusplus::asio::object_server& objectServer)
@@ -206,7 +206,7 @@
 
 void createSensors(
     boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
-    boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>&
+    boost::container::flat_map<std::string, std::shared_ptr<TachSensor>>&
         tachSensors,
     boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>&
         pwmSensors,
@@ -489,11 +489,15 @@
             }
 
             findLimits(limits, baseConfiguration);
-            tachSensors[sensorName] = std::make_unique<TachSensor>(
+
+            auto& tachSensor = tachSensors[sensorName];
+            tachSensor = nullptr;
+            tachSensor = std::make_shared<TachSensor>(
                 path.string(), baseType, objectServer, dbusConnection,
                 std::move(presenceSensor), redundancy, io, sensorName,
                 std::move(sensorThresholds), *interfacePath, limits, powerState,
                 led);
+            tachSensor->setupRead();
 
             if (!pwmPath.empty() && fs::exists(pwmPath) &&
                 (pwmSensors.count(pwmPath) == 0U))
@@ -517,7 +521,7 @@
     auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
     systemBus->request_name("xyz.openbmc_project.FanSensor");
     sdbusplus::asio::object_server objectServer(systemBus);
-    boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>
+    boost::container::flat_map<std::string, std::shared_ptr<TachSensor>>
         tachSensors;
     boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
         pwmSensors;