Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28b7a7e3 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Automerger Merge Worker
Browse files

Merge "Use C++20 [[unlikely]] instead of UNLIKELY macro" into main am:...

Merge "Use C++20 [[unlikely]] instead of UNLIKELY macro" into main am: 56f83aa4 am: e963d6b2 am: 3829544d am: 2362ad97

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2779433



Change-Id: If22c268d0f90cc51224497337c48d5a950f06995
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents bd0e796f 2362ad97
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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) {
+17 −13
Original line number Diff line number Diff line
@@ -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");
+0 −1
Original line number Diff line number Diff line
@@ -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>
+15 −16
Original line number Diff line number Diff line
@@ -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;
            }
+0 −1
Original line number Diff line number Diff line
@@ -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>
Loading