diff options
| author | 2023-10-10 17:49:51 +0000 | |
|---|---|---|
| committer | 2023-10-10 17:49:51 +0000 | |
| commit | e963d6b2d6b5071520993818ee4840a48044203e (patch) | |
| tree | 36816572e429efad782ea9b8a0d4544868365b17 | |
| parent | 1e17f4278af0ff7cc2bae3fb4d7f238c3bed3821 (diff) | |
| parent | 56f83aa42658de6c3ad47afc6c135a4c822f6c49 (diff) | |
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>
| -rw-r--r-- | libs/binder/Binder.cpp | 3 | ||||
| -rw-r--r-- | libs/binder/BpBinder.cpp | 30 | ||||
| -rw-r--r-- | libs/binder/Parcel.cpp | 1 | ||||
| -rw-r--r-- | libs/binder/include/binder/SafeInterface.h | 31 | ||||
| -rw-r--r-- | libs/binder/tests/unit_fuzzers/BpBinderFuzzFunctions.h | 1 | ||||
| -rw-r--r-- | libs/binder/tests/unit_fuzzers/IBinderFuzzFunctions.h | 1 |
6 files changed, 33 insertions, 34 deletions
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index 0f4a6cabde..aa67869649 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 @@ status_t BBinder::transact( } } - 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 ef0ae4f654..3bc4f929e7 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 @@ sp<BpBinder> BpBinder::create(int32_t handle) { 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 @@ status_t BpBinder::transact( 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 BpBinder::transact( } 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::remoteBinder() } 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 @@ BpBinder::~BpBinder() { 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 @@ BpBinder::~BpBinder() { } 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::onFirstRef() { } void BpBinder::onLastStrongRef(const void* /*id*/) { - if (CC_UNLIKELY(isRpcBinder())) { + if (isRpcBinder()) [[unlikely]] { (void)rpcSession()->sendDecStrong(this); return; } @@ -684,7 +686,9 @@ void BpBinder::onLastStrongRef(const void* /*id*/) { 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 5b34efc257..d92de1b151 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 5fa2ff6a87..96b9733c94 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 @@ private: 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 @@ protected: 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 @@ protected: // 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 @@ protected: // 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 @@ protected: // 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 @@ protected: 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 @@ protected: 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 @@ private: 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 @@ private: 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 @@ protected: // 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 @@ protected: // 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 @@ protected: // 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 @@ private: 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 @@ private: 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 5079431058..0a584bfe56 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 bf7c61347f..a6dc182588 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> |