summaryrefslogtreecommitdiff
path: root/libs/binder/RpcState.cpp
diff options
context:
space:
mode:
author Sebastian Pickl <spickl@google.com> 2023-10-30 11:28:23 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-10-30 11:28:23 +0000
commit271bd23714c8f90bf46398843141dfd29a59d125 (patch)
tree47483af2f39a1ff2d26442658ff43f0de44c70ac /libs/binder/RpcState.cpp
parent9636af27d208552aa679437cbf3e292a6033a23d (diff)
parent25c1a3b8543dd1756308424dd65030f90bb7a99f (diff)
Merge changes from topic "revert-2780893-XRITMVSTFB" into main
* changes: Revert "Use std::unique_ptr instead of ScopeGuard" Revert "Use std::function instead of base::function_ref"
Diffstat (limited to 'libs/binder/RpcState.cpp')
-rw-r--r--libs/binder/RpcState.cpp43
1 files changed, 21 insertions, 22 deletions
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp
index 09032dd4dd..26a2f4fa39 100644
--- a/libs/binder/RpcState.cpp
+++ b/libs/binder/RpcState.cpp
@@ -19,8 +19,8 @@
#include "RpcState.h"
#include <android-base/macros.h>
+#include <android-base/scopeguard.h>
#include <binder/BpBinder.h>
-#include <binder/Functional.h>
#include <binder/IPCThreadState.h>
#include <binder/RpcServer.h>
@@ -39,8 +39,6 @@
namespace android {
-using namespace android::binder::impl;
-
#if RPC_FLAKE_PRONE
void rpcMaybeWaitToFlake() {
[[clang::no_destroy]] static std::random_device r;
@@ -359,7 +357,7 @@ RpcState::CommandData::CommandData(size_t size) : mSize(size) {
status_t RpcState::rpcSend(
const sp<RpcSession::RpcConnection>& connection, const sp<RpcSession>& session,
const char* what, iovec* iovs, int niovs,
- const std::optional<SmallFunction<status_t()>>& altPoll,
+ const std::optional<android::base::function_ref<status_t()>>& altPoll,
const std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds) {
for (int i = 0; i < niovs; i++) {
LOG_RPC_DETAIL("Sending %s (part %d of %d) on RpcTransport %p: %s",
@@ -604,24 +602,25 @@ status_t RpcState::transactAddress(const sp<RpcSession::RpcConnection>& connecti
{const_cast<uint8_t*>(data.data()), data.dataSize()},
objectTableSpan.toIovec(),
};
- auto altPoll = [&] {
- if (waitUs > kWaitLogUs) {
- ALOGE("Cannot send command, trying to process pending refcounts. Waiting "
- "%zuus. Too many oneway calls?",
- waitUs);
- }
+ if (status_t status = rpcSend(
+ connection, session, "transaction", iovs, arraysize(iovs),
+ [&] {
+ if (waitUs > kWaitLogUs) {
+ ALOGE("Cannot send command, trying to process pending refcounts. Waiting "
+ "%zuus. Too many oneway calls?",
+ waitUs);
+ }
- if (waitUs > 0) {
- usleep(waitUs);
- waitUs = std::min(kWaitMaxUs, waitUs * 2);
- } else {
- waitUs = 1;
- }
+ if (waitUs > 0) {
+ usleep(waitUs);
+ waitUs = std::min(kWaitMaxUs, waitUs * 2);
+ } else {
+ waitUs = 1;
+ }
- return drainCommands(connection, session, CommandType::CONTROL_ONLY);
- };
- if (status_t status = rpcSend(connection, session, "transaction", iovs, arraysize(iovs),
- std::ref(altPoll), rpcFields->mFds.get());
+ return drainCommands(connection, session, CommandType::CONTROL_ONLY);
+ },
+ rpcFields->mFds.get());
status != OK) {
// rpcSend calls shutdownAndWait, so all refcounts should be reset. If we ever tolerate
// errors here, then we may need to undo the binder-sent counts for the transaction as
@@ -812,11 +811,11 @@ status_t RpcState::processCommand(
origGuard = kernelBinderState->pushGetCallingSpGuard(&spGuard);
}
- auto guardUnguard = make_scope_guard([&]() {
+ base::ScopeGuard guardUnguard = [&]() {
if (kernelBinderState != nullptr) {
kernelBinderState->restoreGetCallingSpGuard(origGuard);
}
- });
+ };
#endif // BINDER_WITH_KERNEL_IPC
switch (command.command) {