Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60f24555 authored by Ana Krulec's avatar Ana Krulec Committed by Android (Google) Code Review
Browse files

Merge "SF: Renaming IdleTimer to OneShotTimer"

parents 7052581f f2c006d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ filegroup {
        "Scheduler/DispSyncSource.cpp",
        "Scheduler/EventControlThread.cpp",
        "Scheduler/EventThread.cpp",
        "Scheduler/IdleTimer.cpp",
        "Scheduler/OneShotTimer.cpp",
        "Scheduler/LayerHistory.cpp",
        "Scheduler/LayerInfo.cpp",
        "Scheduler/MessageQueue.cpp",
+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
#include <ui/GraphicBuffer.h>
#include <ui/Rect.h>
#include <utils/StrongPointer.h>
#include "Scheduler/IdleTimer.h"
#include "Scheduler/OneShotTimer.h"

namespace android {

@@ -107,7 +107,7 @@ private:
    SurfaceFlinger& mFlinger;
    Scheduler& mScheduler;
    const TimingTunables mTunables;
    scheduler::IdleTimer mIdleTimer;
    scheduler::OneShotTimer mIdleTimer;

    std::unique_ptr<SamplingOffsetCallback> const mPhaseCallback;

+9 −9
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

#include "IdleTimer.h"
#include "OneShotTimer.h"

#include <chrono>
#include <thread>
@@ -22,23 +22,23 @@
namespace android {
namespace scheduler {

IdleTimer::IdleTimer(const Interval& interval, const ResetCallback& resetCallback,
OneShotTimer::OneShotTimer(const Interval& interval, const ResetCallback& resetCallback,
                           const TimeoutCallback& timeoutCallback)
      : mInterval(interval), mResetCallback(resetCallback), mTimeoutCallback(timeoutCallback) {}

IdleTimer::~IdleTimer() {
OneShotTimer::~OneShotTimer() {
    stop();
}

void IdleTimer::start() {
void OneShotTimer::start() {
    {
        std::lock_guard<std::mutex> lock(mMutex);
        mState = TimerState::RESET;
    }
    mThread = std::thread(&IdleTimer::loop, this);
    mThread = std::thread(&OneShotTimer::loop, this);
}

void IdleTimer::stop() {
void OneShotTimer::stop() {
    {
        std::lock_guard<std::mutex> lock(mMutex);
        mState = TimerState::STOPPED;
@@ -49,7 +49,7 @@ void IdleTimer::stop() {
    }
}

void IdleTimer::loop() {
void OneShotTimer::loop() {
    while (true) {
        bool triggerReset = false;
        bool triggerTimeout = false;
@@ -100,7 +100,7 @@ void IdleTimer::loop() {
    }
} // namespace scheduler

void IdleTimer::reset() {
void OneShotTimer::reset() {
    {
        std::lock_guard<std::mutex> lock(mMutex);
        mState = TimerState::RESET;
+4 −4
Original line number Diff line number Diff line
@@ -29,15 +29,15 @@ namespace scheduler {
 * Class that sets off a timer for a given interval, and fires a callback when the
 * interval expires.
 */
class IdleTimer {
class OneShotTimer {
public:
    using Interval = std::chrono::milliseconds;
    using ResetCallback = std::function<void()>;
    using TimeoutCallback = std::function<void()>;

    IdleTimer(const Interval& interval, const ResetCallback& resetCallback,
    OneShotTimer(const Interval& interval, const ResetCallback& resetCallback,
                 const TimeoutCallback& timeoutCallback);
    ~IdleTimer();
    ~OneShotTimer();

    // Initializes and turns on the idle timer.
    void start();
+12 −17
Original line number Diff line number Diff line
@@ -38,9 +38,9 @@
#include "DispSyncSource.h"
#include "EventControlThread.h"
#include "EventThread.h"
#include "IdleTimer.h"
#include "InjectVSyncSource.h"
#include "LayerInfo.h"
#include "OneShotTimer.h"
#include "SchedulerUtils.h"
#include "SurfaceFlingerProperties.h"

@@ -86,17 +86,13 @@ Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function,

    if (mSetIdleTimerMs > 0) {
        if (mSupportKernelTimer) {
            mIdleTimer =
                    std::make_unique<scheduler::IdleTimer>(std::chrono::milliseconds(
                                                                   mSetIdleTimerMs),
            mIdleTimer = std::make_unique<scheduler::OneShotTimer>(
                    std::chrono::milliseconds(mSetIdleTimerMs),
                    [this] { resetKernelTimerCallback(); },
                                                           [this] {
                                                               expiredKernelTimerCallback();
                                                           });
                    [this] { expiredKernelTimerCallback(); });
        } else {
            mIdleTimer = std::make_unique<scheduler::IdleTimer>(std::chrono::milliseconds(
                                                                        mSetIdleTimerMs),
                                                                [this] { resetTimerCallback(); },
            mIdleTimer = std::make_unique<scheduler::OneShotTimer>(
                    std::chrono::milliseconds(mSetIdleTimerMs), [this] { resetTimerCallback(); },
                    [this] { expiredTimerCallback(); });
        }
        mIdleTimer->start();
@@ -104,16 +100,15 @@ Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function,

    if (mSetTouchTimerMs > 0) {
        // Touch events are coming to SF every 100ms, so the timer needs to be higher than that
        mTouchTimer =
                std::make_unique<scheduler::IdleTimer>(std::chrono::milliseconds(mSetTouchTimerMs),
                                                       [this] { resetTouchTimerCallback(); },
        mTouchTimer = std::make_unique<scheduler::OneShotTimer>(
                std::chrono::milliseconds(mSetTouchTimerMs), [this] { resetTouchTimerCallback(); },
                [this] { expiredTouchTimerCallback(); });
        mTouchTimer->start();
    }
}

Scheduler::~Scheduler() {
    // Ensure the IdleTimer thread is joined before we start destroying state.
    // Ensure the OneShotTimer threads are joined before we start destroying state.
    mTouchTimer.reset();
    mIdleTimer.reset();
}
Loading