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

Commit eac3db27 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

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
parent 37846155
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -181,7 +181,7 @@ void EventThread::onHotplugReceived(DisplayType displayType, bool connected) {
    event.header.timestamp = systemTime();
    event.header.timestamp = systemTime();
    event.hotplug.connected = connected;
    event.hotplug.connected = connected;


    mPendingEvents.add(event);
    mPendingEvents.push(event);
    mCondition.notify_all();
    mCondition.notify_all();
}
}


@@ -244,11 +244,11 @@ Vector<sp<EventThread::Connection> > EventThread::waitForEventLocked(


        if (!timestamp) {
        if (!timestamp) {
            // no vsync event, see if there are some other event
            // no vsync event, see if there are some other event
            eventPending = !mPendingEvents.isEmpty();
            eventPending = !mPendingEvents.empty();
            if (eventPending) {
            if (eventPending) {
                // we have some other event to dispatch
                // we have some other event to dispatch
                *outEvent = mPendingEvents[0];
                *outEvent = mPendingEvents.front();
                mPendingEvents.removeAt(0);
                mPendingEvents.pop();
            }
            }
        }
        }


@@ -384,6 +384,7 @@ void EventThread::dump(String8& result) const {
        result.appendFormat("    %p: count=%d\n", connection.get(),
        result.appendFormat("    %p: count=%d\n", connection.get(),
                            connection != nullptr ? connection->count : 0);
                            connection != nullptr ? connection->count : 0);
    }
    }
    result.appendFormat("  other-events-pending: %zu\n", mPendingEvents.size());
}
}


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
+2 −1
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@
#include <condition_variable>
#include <condition_variable>
#include <cstdint>
#include <cstdint>
#include <mutex>
#include <mutex>
#include <queue>
#include <thread>
#include <thread>


#include <android-base/thread_annotations.h>
#include <android-base/thread_annotations.h>
@@ -168,7 +169,7 @@ private:


    // protected by mLock
    // protected by mLock
    SortedVector<wp<Connection>> mDisplayEventConnections GUARDED_BY(mMutex);
    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);
    std::array<DisplayEventReceiver::Event, 2> mVSyncEvent GUARDED_BY(mMutex);
    bool mUseSoftwareVSync GUARDED_BY(mMutex) = false;
    bool mUseSoftwareVSync GUARDED_BY(mMutex) = false;
    bool mVsyncEnabled GUARDED_BY(mMutex) = false;
    bool mVsyncEnabled GUARDED_BY(mMutex) = false;