surfaceflinger: use std::queue for mPendingEvents
Replace Vector by std::queue for mPendingEvents. It is used for
pending hotplug events, which happen rarely and are consumed one by
one quickly by an RT thread. std::queue is likely no better than
std::vector in that scenario, but is more expressive.
Bug: 115738279
Test: boots
Change-Id: Ia906a7f08ecbe6d5534cd6ec42e5af2ac865a911
diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp
index fa2b0a6..a75235c 100644
--- a/services/surfaceflinger/Scheduler/EventThread.cpp
+++ b/services/surfaceflinger/Scheduler/EventThread.cpp
@@ -181,7 +181,7 @@
event.header.timestamp = systemTime();
event.hotplug.connected = connected;
- mPendingEvents.add(event);
+ mPendingEvents.push(event);
mCondition.notify_all();
}
@@ -244,11 +244,11 @@
if (!timestamp) {
// no vsync event, see if there are some other event
- eventPending = !mPendingEvents.isEmpty();
+ eventPending = !mPendingEvents.empty();
if (eventPending) {
// we have some other event to dispatch
- *outEvent = mPendingEvents[0];
- mPendingEvents.removeAt(0);
+ *outEvent = mPendingEvents.front();
+ mPendingEvents.pop();
}
}
@@ -384,6 +384,7 @@
result.appendFormat(" %p: count=%d\n", connection.get(),
connection != nullptr ? connection->count : 0);
}
+ result.appendFormat(" other-events-pending: %zu\n", mPendingEvents.size());
}
// ---------------------------------------------------------------------------
diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h
index 127891e..3879ae4 100644
--- a/services/surfaceflinger/Scheduler/EventThread.h
+++ b/services/surfaceflinger/Scheduler/EventThread.h
@@ -22,6 +22,7 @@
#include <condition_variable>
#include <cstdint>
#include <mutex>
+#include <queue>
#include <thread>
#include <android-base/thread_annotations.h>
@@ -168,7 +169,7 @@
// protected by mLock
SortedVector<wp<Connection>> mDisplayEventConnections GUARDED_BY(mMutex);
- Vector<DisplayEventReceiver::Event> mPendingEvents GUARDED_BY(mMutex);
+ std::queue<DisplayEventReceiver::Event> mPendingEvents GUARDED_BY(mMutex);
std::array<DisplayEventReceiver::Event, 2> mVSyncEvent GUARDED_BY(mMutex);
bool mUseSoftwareVSync GUARDED_BY(mMutex) = false;
bool mVsyncEnabled GUARDED_BY(mMutex) = false;