diff options
author | 2024-02-06 20:34:36 +0000 | |
---|---|---|
committer | 2024-02-06 20:34:36 +0000 | |
commit | 036c283b3f8da1d93eb4a9bcce72d409ebe145cc (patch) | |
tree | cd4a7888c1b0dee675a21d20b6caa24cb8a5afaa | |
parent | 9a4c4ed69fe705a7a5dff7e33a2499d37a7390bb (diff) | |
parent | 0f3e5b9b3c64c378941906894787820d7293254a (diff) |
Merge "SF: Store VsyncDispatch callbacks in ftl::SmallMap" into main
3 files changed, 15 insertions, 16 deletions
diff --git a/services/surfaceflinger/Scheduler/VSyncDispatch.h b/services/surfaceflinger/Scheduler/VSyncDispatch.h index f978016c9e..434fc36f8a 100644 --- a/services/surfaceflinger/Scheduler/VSyncDispatch.h +++ b/services/surfaceflinger/Scheduler/VSyncDispatch.h @@ -35,7 +35,7 @@ enum class CancelResult { Cancelled, TooLate, Error }; */ class VSyncDispatch { public: - using CallbackToken = StrongTyping<size_t, class CallbackTokenTag, Compare, Hash>; + using CallbackToken = StrongTyping<size_t, class CallbackTokenTag, Compare>; virtual ~VSyncDispatch(); diff --git a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp index 5cb0ffbfb7..98aa5338f7 100644 --- a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp +++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp @@ -267,15 +267,15 @@ void VSyncDispatchTimerQueue::setTimer(nsecs_t targetTime, nsecs_t /*now*/) { } void VSyncDispatchTimerQueue::rearmTimer(nsecs_t now) { - rearmTimerSkippingUpdateFor(now, mCallbacks.end()); + rearmTimerSkippingUpdateFor(now, mCallbacks.cend()); } void VSyncDispatchTimerQueue::rearmTimerSkippingUpdateFor( - nsecs_t now, CallbackMap::iterator const& skipUpdateIt) { + nsecs_t now, CallbackMap::const_iterator skipUpdateIt) { std::optional<nsecs_t> min; std::optional<nsecs_t> targetVsync; std::optional<std::string_view> nextWakeupName; - for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) { + for (auto it = mCallbacks.cbegin(); it != mCallbacks.cend(); ++it) { auto& callback = it->second; if (!callback->wakeupTime() && !callback->hasPendingWorkloadUpdate()) { continue; @@ -351,13 +351,12 @@ void VSyncDispatchTimerQueue::timerCallback() { VSyncDispatchTimerQueue::CallbackToken VSyncDispatchTimerQueue::registerCallback( Callback callback, std::string callbackName) { std::lock_guard lock(mMutex); - return CallbackToken{ - mCallbacks - .emplace(++mCallbackToken, - std::make_shared<VSyncDispatchTimerQueueEntry>(std::move(callbackName), - std::move(callback), - mMinVsyncDistance)) - .first->first}; + return mCallbacks + .try_emplace(CallbackToken{++mCallbackToken}, + std::make_shared<VSyncDispatchTimerQueueEntry>(std::move(callbackName), + std::move(callback), + mMinVsyncDistance)) + .first->first; } void VSyncDispatchTimerQueue::unregisterCallback(CallbackToken token) { @@ -367,7 +366,7 @@ void VSyncDispatchTimerQueue::unregisterCallback(CallbackToken token) { auto it = mCallbacks.find(token); if (it != mCallbacks.end()) { entry = it->second; - mCallbacks.erase(it); + mCallbacks.erase(it->first); } } diff --git a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h index 3d08410df7..30e52421d4 100644 --- a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h +++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h @@ -16,14 +16,13 @@ #pragma once -#include <functional> #include <memory> #include <mutex> #include <string> #include <string_view> -#include <unordered_map> #include <android-base/thread_annotations.h> +#include <ftl/small_map.h> #include "VSyncDispatch.h" #include "VsyncSchedule.h" @@ -135,13 +134,14 @@ private: VSyncDispatchTimerQueue(const VSyncDispatchTimerQueue&) = delete; VSyncDispatchTimerQueue& operator=(const VSyncDispatchTimerQueue&) = delete; + // The static capacity was chosen to exceed the expected number of callbacks. using CallbackMap = - std::unordered_map<CallbackToken, std::shared_ptr<VSyncDispatchTimerQueueEntry>>; + ftl::SmallMap<CallbackToken, std::shared_ptr<VSyncDispatchTimerQueueEntry>, 5>; void timerCallback(); void setTimer(nsecs_t, nsecs_t) REQUIRES(mMutex); void rearmTimer(nsecs_t now) REQUIRES(mMutex); - void rearmTimerSkippingUpdateFor(nsecs_t now, CallbackMap::iterator const& skipUpdate) + void rearmTimerSkippingUpdateFor(nsecs_t now, CallbackMap::const_iterator skipUpdate) REQUIRES(mMutex); void cancelTimer() REQUIRES(mMutex); ScheduleResult scheduleLocked(CallbackToken, ScheduleTiming) REQUIRES(mMutex); |