diff options
author | 2022-05-10 23:33:40 +0000 | |
---|---|---|
committer | 2022-05-16 22:31:01 +0000 | |
commit | 8d7d0f42c697ad893df9249b6e66684adb9439f5 (patch) | |
tree | 84aa7730c4c3ea2d6d88ffb4f2129273638cc636 /services/surfaceflinger/TransactionCallbackInvoker.cpp | |
parent | 04d24da36e27766f09fc871307b58cb4303b0082 (diff) |
Use semaphore instead of condition variable
BackgroundExecutor uses a condition variable to synchronize processing
to a work queue, which means that there is possible mutex contention on
the main thread in rare scenarios.
Instead, we can make the main thread non-blocking with a thread-safe
queue, and use semaphores for signaling the background thread to wake
up. Using semaphores saves a small number of instructions, but overall
reduces contention
Bug: 232113929
Test: bouncy ball
Change-Id: Iced25e8349bdb2a70cac1ed681059a0b14258407
Diffstat (limited to 'services/surfaceflinger/TransactionCallbackInvoker.cpp')
-rw-r--r-- | services/surfaceflinger/TransactionCallbackInvoker.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/services/surfaceflinger/TransactionCallbackInvoker.cpp b/services/surfaceflinger/TransactionCallbackInvoker.cpp index e1f348fdba..9f4a6cd0e6 100644 --- a/services/surfaceflinger/TransactionCallbackInvoker.cpp +++ b/services/surfaceflinger/TransactionCallbackInvoker.cpp @@ -184,6 +184,7 @@ void TransactionCallbackInvoker::addPresentFence(const sp<Fence>& presentFence) void TransactionCallbackInvoker::sendCallbacks(bool onCommitOnly) { // For each listener auto completedTransactionsItr = mCompletedTransactions.begin(); + BackgroundExecutor::Callbacks callbacks; while (completedTransactionsItr != mCompletedTransactions.end()) { auto& [listener, transactionStatsDeque] = *completedTransactionsItr; ListenerStats listenerStats; @@ -218,7 +219,7 @@ void TransactionCallbackInvoker::sendCallbacks(bool onCommitOnly) { // keep it as an IBinder due to consistency reasons: if we // interface_cast at the IPC boundary when reading a Parcel, // we get pointers that compare unequal in the SF process. - BackgroundExecutor::getInstance().execute([stats = std::move(listenerStats)]() { + callbacks.emplace_back([stats = std::move(listenerStats)]() { interface_cast<ITransactionCompletedListener>(stats.listener) ->onTransactionCompleted(stats); }); @@ -230,6 +231,8 @@ void TransactionCallbackInvoker::sendCallbacks(bool onCommitOnly) { if (mPresentFence) { mPresentFence.clear(); } + + BackgroundExecutor::getInstance().sendCallbacks(std::move(callbacks)); } // ----------------------------------------------------------------------- |