Merge "Use C++20 [[unlikely]] instead of UNLIKELY macro" into main am: 56f83aa426
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2779433
Change-Id: I05f99b9e2bafa86075f337e84171625e7850c1a4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index 0f4a6ca..aa67869 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -29,7 +29,6 @@
#include <binder/Parcel.h>
#include <binder/RecordedTransaction.h>
#include <binder/RpcServer.h>
-#include <cutils/compiler.h>
#include <private/android_filesystem_config.h>
#include <pthread.h>
#include <utils/misc.h>
@@ -402,7 +401,7 @@
}
}
- if (CC_UNLIKELY(kEnableKernelIpc && mRecordingOn && code != START_RECORDING_TRANSACTION)) {
+ if (kEnableKernelIpc && mRecordingOn && code != START_RECORDING_TRANSACTION) [[unlikely]] {
Extras* e = mExtras.load(std::memory_order_acquire);
AutoMutex lock(e->mLock);
if (mRecordingOn) {
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index ef0ae4f..3bc4f92 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -23,7 +23,6 @@
#include <binder/IResultReceiver.h>
#include <binder/RpcSession.h>
#include <binder/Stability.h>
-#include <cutils/compiler.h>
#include <utils/Log.h>
#include <stdio.h>
@@ -166,7 +165,7 @@
trackedUid = IPCThreadState::self()->getCallingUid();
AutoMutex _l(sTrackingLock);
uint32_t trackedValue = sTrackingMap[trackedUid];
- if (CC_UNLIKELY(trackedValue & LIMIT_REACHED_MASK)) {
+ if (trackedValue & LIMIT_REACHED_MASK) [[unlikely]] {
if (sBinderProxyThrottleCreate) {
return nullptr;
}
@@ -364,7 +363,7 @@
Stability::Level required = privateVendor ? Stability::VENDOR
: Stability::getLocalLevel();
- if (CC_UNLIKELY(!Stability::check(stability, required))) {
+ if (!Stability::check(stability, required)) [[unlikely]] {
ALOGE("Cannot do a user transaction on a %s binder (%s) in a %s context.",
Stability::levelString(stability).c_str(),
String8(getInterfaceDescriptor()).c_str(),
@@ -374,7 +373,7 @@
}
status_t status;
- if (CC_UNLIKELY(isRpcBinder())) {
+ if (isRpcBinder()) [[unlikely]] {
status = rpcSession()->transact(sp<IBinder>::fromExisting(this), code, data, reply,
flags);
} else {
@@ -589,7 +588,9 @@
}
BpBinder::~BpBinder() {
- if (CC_UNLIKELY(isRpcBinder())) return;
+ if (isRpcBinder()) [[unlikely]] {
+ return;
+ }
if constexpr (!kEnableKernelIpc) {
LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
@@ -603,14 +604,13 @@
if (mTrackedUid >= 0) {
AutoMutex _l(sTrackingLock);
uint32_t trackedValue = sTrackingMap[mTrackedUid];
- if (CC_UNLIKELY((trackedValue & COUNTING_VALUE_MASK) == 0)) {
+ if ((trackedValue & COUNTING_VALUE_MASK) == 0) [[unlikely]] {
ALOGE("Unexpected Binder Proxy tracking decrement in %p handle %d\n", this,
binderHandle());
} else {
- if (CC_UNLIKELY(
- (trackedValue & LIMIT_REACHED_MASK) &&
- ((trackedValue & COUNTING_VALUE_MASK) <= sBinderProxyCountLowWatermark)
- )) {
+ auto countingValue = trackedValue & COUNTING_VALUE_MASK;
+ if ((trackedValue & LIMIT_REACHED_MASK) &&
+ (countingValue <= sBinderProxyCountLowWatermark)) [[unlikely]] {
ALOGI("Limit reached bit reset for uid %d (fewer than %d proxies from uid %d held)",
getuid(), sBinderProxyCountLowWatermark, mTrackedUid);
sTrackingMap[mTrackedUid] &= ~LIMIT_REACHED_MASK;
@@ -630,7 +630,9 @@
}
void BpBinder::onFirstRef() {
- if (CC_UNLIKELY(isRpcBinder())) return;
+ if (isRpcBinder()) [[unlikely]] {
+ return;
+ }
if constexpr (!kEnableKernelIpc) {
LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
@@ -643,7 +645,7 @@
}
void BpBinder::onLastStrongRef(const void* /*id*/) {
- if (CC_UNLIKELY(isRpcBinder())) {
+ if (isRpcBinder()) [[unlikely]] {
(void)rpcSession()->sendDecStrong(this);
return;
}
@@ -684,7 +686,9 @@
bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)
{
// RPC binder doesn't currently support inc from weak binders
- if (CC_UNLIKELY(isRpcBinder())) return false;
+ if (isRpcBinder()) [[unlikely]] {
+ return false;
+ }
if constexpr (!kEnableKernelIpc) {
LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 5b34efc..d92de1b 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -41,7 +41,6 @@
#include <android-base/scopeguard.h>
#include <cutils/ashmem.h>
-#include <cutils/compiler.h>
#include <utils/Flattenable.h>
#include <utils/Log.h>
#include <utils/String16.h>
diff --git a/libs/binder/include/binder/SafeInterface.h b/libs/binder/include/binder/SafeInterface.h
index 5fa2ff6..96b9733 100644
--- a/libs/binder/include/binder/SafeInterface.h
+++ b/libs/binder/include/binder/SafeInterface.h
@@ -18,7 +18,6 @@
#include <binder/IInterface.h>
#include <binder/Parcel.h>
-#include <cutils/compiler.h>
// Set to 1 to enable CallStacks when logging errors
#define SI_DUMP_CALLSTACKS 0
@@ -218,7 +217,7 @@
template <typename Function>
status_t callParcel(const char* name, Function f) const {
status_t error = f();
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
ALOG(LOG_ERROR, mLogTag, "Failed to %s, (%d: %s)", name, error, strerror(-error));
#if SI_DUMP_CALLSTACKS
CallStack callStack(mLogTag);
@@ -265,7 +264,7 @@
data.writeInterfaceToken(this->getInterfaceDescriptor());
status_t error = writeInputs(&data, std::forward<Args>(args)...);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by writeInputs
return error;
}
@@ -273,7 +272,7 @@
// Send the data Parcel to the remote and retrieve the reply parcel
Parcel reply;
error = this->remote()->transact(static_cast<uint32_t>(tag), data, &reply);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
ALOG(LOG_ERROR, mLogTag, "Failed to transact (%d)", error);
#if SI_DUMP_CALLSTACKS
CallStack callStack(mLogTag);
@@ -283,7 +282,7 @@
// Read the outputs from the reply Parcel into the output arguments
error = readOutputs(reply, std::forward<Args>(args)...);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by readOutputs
return error;
}
@@ -291,7 +290,7 @@
// Retrieve the result code from the reply Parcel
status_t result = NO_ERROR;
error = reply.readInt32(&result);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
ALOG(LOG_ERROR, mLogTag, "Failed to obtain result");
#if SI_DUMP_CALLSTACKS
CallStack callStack(mLogTag);
@@ -315,7 +314,7 @@
Parcel data;
data.writeInterfaceToken(this->getInterfaceDescriptor());
status_t error = writeInputs(&data, std::forward<Args>(args)...);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by writeInputs
return;
}
@@ -324,7 +323,7 @@
Parcel reply;
error = this->remote()->transact(static_cast<uint32_t>(tag), data, &reply,
IBinder::FLAG_ONEWAY);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
ALOG(LOG_ERROR, mLogTag, "Failed to transact (%d)", error);
#if SI_DUMP_CALLSTACKS
CallStack callStack(mLogTag);
@@ -406,7 +405,7 @@
template <typename T, typename... Remaining>
status_t writeInputs(Parcel* data, T&& t, Remaining&&... remaining) const {
status_t error = writeIfInput(data, std::forward<T>(t));
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by writeIfInput
return error;
}
@@ -429,7 +428,7 @@
template <typename T, typename... Remaining>
status_t readOutputs(const Parcel& reply, T&& t, Remaining&&... remaining) const {
status_t error = readIfOutput(reply, std::forward<T>(t));
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by readIfOutput
return error;
}
@@ -458,7 +457,7 @@
// Read the inputs from the data Parcel into the argument tuple
status_t error = InputReader<ParamTuple>{mLogTag}.readInputs(data, &rawArgs);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by read
return error;
}
@@ -468,14 +467,14 @@
// Extract the outputs from the argument tuple and write them into the reply Parcel
error = OutputWriter<ParamTuple>{mLogTag}.writeOutputs(reply, &rawArgs);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by write
return error;
}
// Return the result code in the reply Parcel
error = reply->writeInt32(result);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
ALOG(LOG_ERROR, mLogTag, "Failed to write result");
#if SI_DUMP_CALLSTACKS
CallStack callStack(mLogTag);
@@ -500,7 +499,7 @@
// Read the inputs from the data Parcel into the argument tuple
status_t error = InputReader<ParamTuple>{mLogTag}.readInputs(data, &rawArgs);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged by read
return error;
}
@@ -596,7 +595,7 @@
typename std::enable_if<(I < sizeof...(Params)), status_t>::type dispatchArg(
const Parcel& data, RawTuple* args) {
status_t error = readIfInput<I>(data, args);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged in read
return error;
}
@@ -694,7 +693,7 @@
typename std::enable_if<(I < sizeof...(Params)), status_t>::type dispatchArg(
Parcel* reply, RawTuple* args) {
status_t error = writeIfOutput<I>(reply, args);
- if (CC_UNLIKELY(error != NO_ERROR)) {
+ if (error != NO_ERROR) [[unlikely]] {
// A message will have been logged in read
return error;
}
diff --git a/libs/binder/tests/unit_fuzzers/BpBinderFuzzFunctions.h b/libs/binder/tests/unit_fuzzers/BpBinderFuzzFunctions.h
index 5079431..0a584bf 100644
--- a/libs/binder/tests/unit_fuzzers/BpBinderFuzzFunctions.h
+++ b/libs/binder/tests/unit_fuzzers/BpBinderFuzzFunctions.h
@@ -26,7 +26,6 @@
#include <binder/Parcel.h>
#include <binder/Stability.h>
-#include <cutils/compiler.h>
#include <utils/KeyedVector.h>
#include <utils/Log.h>
#include <utils/Mutex.h>
diff --git a/libs/binder/tests/unit_fuzzers/IBinderFuzzFunctions.h b/libs/binder/tests/unit_fuzzers/IBinderFuzzFunctions.h
index bf7c613..a6dc182 100644
--- a/libs/binder/tests/unit_fuzzers/IBinderFuzzFunctions.h
+++ b/libs/binder/tests/unit_fuzzers/IBinderFuzzFunctions.h
@@ -23,7 +23,6 @@
#include <binder/IResultReceiver.h>
#include <binder/Parcel.h>
#include <binder/Stability.h>
-#include <cutils/compiler.h>
#include <utils/KeyedVector.h>
#include <utils/Log.h>
#include <utils/Mutex.h>