summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/TransactionCallbackInvoker.cpp
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2021-11-18 15:23:23 -0800
committer Vishnu Nair <vishnun@google.com> 2021-11-19 11:17:57 -0800
commit34eb9ca577d78524b992d2af367e23ce89a9f034 (patch)
treeeb9c8615e8252e4578a752b15117dc987888b252 /services/surfaceflinger/TransactionCallbackInvoker.cpp
parent27c20ff12d67b4667edb01160289afc8a4e23373 (diff)
SF: Introduce background task executor
Extract logic to execute work outside of the main thread from TransactionCallbackInvoker so we can reuse the thread for other tasks that are not critical to drawing. Bug: 206380307 Test: presubmit Change-Id: I8128d2f333e3aab5639cd1200e820de39f0b3191
Diffstat (limited to 'services/surfaceflinger/TransactionCallbackInvoker.cpp')
-rw-r--r--services/surfaceflinger/TransactionCallbackInvoker.cpp39
1 files changed, 5 insertions, 34 deletions
diff --git a/services/surfaceflinger/TransactionCallbackInvoker.cpp b/services/surfaceflinger/TransactionCallbackInvoker.cpp
index f3d46ea061..b705d9cf7b 100644
--- a/services/surfaceflinger/TransactionCallbackInvoker.cpp
+++ b/services/surfaceflinger/TransactionCallbackInvoker.cpp
@@ -24,6 +24,7 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#include "TransactionCallbackInvoker.h"
+#include "BackgroundExecutor.h"
#include <cinttypes>
@@ -49,31 +50,6 @@ static bool containsOnCommitCallbacks(const std::vector<CallbackId>& callbacks)
return !callbacks.empty() && callbacks.front().type == CallbackId::Type::ON_COMMIT;
}
-TransactionCallbackInvoker::TransactionCallbackInvoker() {
- mThread = std::thread([&]() {
- std::unique_lock lock(mCallbackThreadMutex);
-
- while (mKeepRunning) {
- while (mCallbackThreadWork.size() > 0) {
- mCallbackThreadWork.front()();
- mCallbackThreadWork.pop();
- }
- mCallbackConditionVariable.wait(lock);
- }
- });
-}
-
-TransactionCallbackInvoker::~TransactionCallbackInvoker() {
- {
- std::unique_lock lock(mCallbackThreadMutex);
- mKeepRunning = false;
- mCallbackConditionVariable.notify_all();
- }
- if (mThread.joinable()) {
- mThread.join();
- }
-}
-
void TransactionCallbackInvoker::addEmptyTransaction(const ListenerCallbacks& listenerCallbacks) {
auto& [listener, callbackIds] = listenerCallbacks;
auto& transactionStatsDeque = mCompletedTransactions[listener];
@@ -242,15 +218,10 @@ 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.
- {
- std::unique_lock lock(mCallbackThreadMutex);
- mCallbackThreadWork.push(
- [stats = std::move(listenerStats)]() {
- interface_cast<ITransactionCompletedListener>(stats.listener)
- ->onTransactionCompleted(stats);
- });
- mCallbackConditionVariable.notify_all();
- }
+ BackgroundExecutor::getInstance().execute([stats = std::move(listenerStats)]() {
+ interface_cast<ITransactionCompletedListener>(stats.listener)
+ ->onTransactionCompleted(stats);
+ });
}
}
completedTransactionsItr++;