diff options
Diffstat (limited to 'control')
-rw-r--r-- | control/actions.cpp | 4 | ||||
-rw-r--r-- | control/types.hpp | 14 | ||||
-rw-r--r-- | control/zone.cpp | 42 | ||||
-rw-r--r-- | control/zone.hpp | 13 |
4 files changed, 33 insertions, 40 deletions
diff --git a/control/actions.cpp b/control/actions.cpp index 0267c10..25b6a09 100644 --- a/control/actions.cpp +++ b/control/actions.cpp @@ -41,10 +41,6 @@ Action call_actions_based_on_timer(TimerConf&& tConf, auto timer = zone.findTimer(group, actions); if (timer != std::end(zone.getTimerEvents())) { - if (std::get<timerTimerPos>(*timer)->running()) - { - std::get<timerTimerPos>(*timer)->stop(); - } zone.removeTimer(timer); } } diff --git a/control/types.hpp b/control/types.hpp index 967b0b4..239d00d 100644 --- a/control/types.hpp +++ b/control/types.hpp @@ -3,7 +3,8 @@ #include <tuple> #include <vector> #include <sdbusplus/server.hpp> -#include "timer.hpp" +#include <sdeventplus/clock.hpp> +#include <sdeventplus/utility/timer.hpp> namespace phosphor { @@ -64,7 +65,11 @@ using Service = std::tuple<std::string, bool>; constexpr auto intervalPos = 0; constexpr auto typePos = 1; -using TimerType = phosphor::fan::util::Timer::TimerType; +enum class TimerType +{ + oneshot, + repeating, +}; using TimerConf = std::tuple<std::chrono::seconds, TimerType>; @@ -89,9 +94,8 @@ using EventData = std::tuple<Group, std::string, Handler, std::vector<Action>>; constexpr auto timerEventDataPos = 0; constexpr auto timerTimerPos = 1; -using TimerEvent = - std::tuple<std::unique_ptr<EventData>, - std::unique_ptr<phosphor::fan::util::Timer>>; +using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>; +using TimerEvent = std::tuple<std::unique_ptr<EventData>, Timer>; constexpr auto signalEventDataPos = 0; constexpr auto signalMatchPos = 1; diff --git a/control/zone.cpp b/control/zone.cpp index 4531151..293945c 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -18,6 +18,7 @@ #include <phosphor-logging/log.hpp> #include <phosphor-logging/elog.hpp> #include <phosphor-logging/elog-errors.hpp> +#include <stdexcept> #include <xyz/openbmc_project/Common/error.hpp> #include "zone.hpp" #include "utility.hpp" @@ -72,10 +73,7 @@ Zone::Zone(Mode mode, initEvent(event); } // Start timer for fan speed decreases - if (!_decTimer.running() && _decInterval != seconds::zero()) - { - _decTimer.start(_decInterval, TimerType::repeating); - } + _decTimer.restart(_decInterval); } } @@ -238,14 +236,9 @@ void Zone::requestSpeedIncrease(uint64_t targetDelta) { requestTarget = _ceilingSpeed; } - // Cancel current timer countdown - if (_incTimer.running()) - { - _incTimer.stop(); - } setSpeed(requestTarget); - // Start timer countdown for fan speed increase - _incTimer.start(_incDelay, TimerType::oneshot); + // Retart timer countdown for fan speed increase + _incTimer.restartOnce(_incDelay); } } @@ -277,7 +270,7 @@ void Zone::decTimerExpired() // where no requested increases exist and // the increase timer is not running // (i.e. not in the middle of increasing) - if (decAllowed && _incSpeedDelta == 0 && !_incTimer.running()) + if (decAllowed && _incSpeedDelta == 0 && !_incTimer.isEnabled()) { auto requestTarget = getRequestSpeedBase(); // Request target speed should not start above ceiling @@ -449,26 +442,31 @@ void Zone::addTimer(const Group& group, const std::vector<Action>& actions, const TimerConf& tConf) { - // Associate event data with timer - auto data = std::make_unique<EventData>( + auto eventData = std::make_unique<EventData>( group, "", nullptr, actions ); - auto timer = std::make_unique<util::Timer>( + Timer timer( _eventLoop, std::bind(&Zone::timerExpired, this, - std::cref(std::get<Group>(*data)), - std::cref(std::get<std::vector<Action>>(*data))) - ); - if (!timer->running()) + std::cref(std::get<Group>(*eventData)), + std::cref(std::get<std::vector<Action>>(*eventData)))); + if (std::get<TimerType>(tConf) == TimerType::repeating) + { + timer.restart(std::get<intervalPos>(tConf)); + } + else if (std::get<TimerType>(tConf) == TimerType::oneshot) + { + timer.restartOnce(std::get<intervalPos>(tConf)); + } + else { - timer->start(std::get<intervalPos>(tConf), - std::get<typePos>(tConf)); + throw std::invalid_argument("Invalid Timer Type"); } - _timerEvents.emplace_back(std::move(data), std::move(timer)); + _timerEvents.emplace_back(std::move(eventData), std::move(timer)); } void Zone::timerExpired(const Group& eventGroup, diff --git a/control/zone.hpp b/control/zone.hpp index d01e972..9c85655 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -1,14 +1,12 @@ #pragma once +#include <algorithm> #include <cassert> #include <chrono> -#include <vector> -#include <cassert> -#include <algorithm> #include <sdbusplus/bus.hpp> #include <sdeventplus/event.hpp> +#include <vector> #include "fan.hpp" #include "types.hpp" -#include "timer.hpp" namespace phosphor { @@ -423,9 +421,6 @@ class Zone */ inline void removeTimer(std::vector<TimerEvent>::iterator& teIter) { - assert(teIter != std::end(_timerEvents)); - std::get<timerEventDataPos>(*teIter).reset(); - std::get<timerTimerPos>(*teIter).reset(); _timerEvents.erase(teIter); } @@ -547,12 +542,12 @@ class Zone /** * The increase timer object */ - phosphor::fan::util::Timer _incTimer; + Timer _incTimer; /** * The decrease timer object */ - phosphor::fan::util::Timer _decTimer; + Timer _decTimer; /** * Event loop used on set speed event timers |