summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/Scheduler/OneShotTimer.h
diff options
context:
space:
mode:
Diffstat (limited to 'services/surfaceflinger/Scheduler/OneShotTimer.h')
-rw-r--r--services/surfaceflinger/Scheduler/OneShotTimer.h29
1 files changed, 8 insertions, 21 deletions
diff --git a/services/surfaceflinger/Scheduler/OneShotTimer.h b/services/surfaceflinger/Scheduler/OneShotTimer.h
index 09265bb947..b005754c1a 100644
--- a/services/surfaceflinger/Scheduler/OneShotTimer.h
+++ b/services/surfaceflinger/Scheduler/OneShotTimer.h
@@ -16,11 +16,9 @@
#pragma once
-#include <semaphore.h>
#include <chrono>
#include <condition_variable>
#include <thread>
-#include "../Clock.h"
#include <android-base/thread_annotations.h>
@@ -37,9 +35,8 @@ public:
using ResetCallback = std::function<void()>;
using TimeoutCallback = std::function<void()>;
- OneShotTimer(std::string name, const Interval& interval, const ResetCallback& resetCallback,
- const TimeoutCallback& timeoutCallback,
- std::unique_ptr<Clock> clock = std::make_unique<SteadyClock>());
+ OneShotTimer(const Interval& interval, const ResetCallback& resetCallback,
+ const TimeoutCallback& timeoutCallback);
~OneShotTimer();
// Initializes and turns on the idle timer.
@@ -73,21 +70,17 @@ private:
// Function that loops until the condition for stopping is met.
void loop();
- // Checks whether mResetTriggered and mStopTriggered were set and updates
- // mState if so.
- TimerState checkForResetAndStop(TimerState state);
-
// Thread waiting for timer to expire.
std::thread mThread;
- // Clock object for the timer. Mocked in unit tests.
- std::unique_ptr<Clock> mClock;
+ // Condition used to notify mThread.
+ std::condition_variable_any mCondition;
- // Semaphore to keep mThread synchronized.
- sem_t mSemaphore;
+ // Lock used for synchronizing the waiting thread with the application thread.
+ std::mutex mMutex;
- // Timer's name.
- std::string mName;
+ // Current timer state
+ TimerState mState GUARDED_BY(mMutex) = TimerState::RESET;
// Interval after which timer expires.
const Interval mInterval;
@@ -97,12 +90,6 @@ private:
// Callback that happens when timer expires.
const TimeoutCallback mTimeoutCallback;
-
- // After removing lock guarding mState, the state can be now accessed at
- // any time. Keep a bool if the reset or stop were requested, and occasionally
- // check in the main loop if they were.
- std::atomic<bool> mResetTriggered = false;
- std::atomic<bool> mStopTriggered = false;
};
} // namespace scheduler