Use C++20 [[unlikely]] instead of UNLIKELY macro
Bug: 302723053
Test: mma
Change-Id: I126772474763a55f43de0cd4a3d2605f7f84da3b
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 589df9a..b0c1af2 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>
@@ -161,7 +160,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;
}
@@ -347,7 +346,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(),
@@ -357,7 +356,7 @@
}
status_t status;
- if (CC_UNLIKELY(isRpcBinder())) {
+ if (isRpcBinder()) [[unlikely]] {
status = rpcSession()->transact(sp<IBinder>::fromExisting(this), code, data, reply,
flags);
} else {
@@ -572,7 +571,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");
@@ -586,14 +587,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;
@@ -612,7 +612,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");
@@ -625,7 +627,7 @@
}
void BpBinder::onLastStrongRef(const void* /*id*/) {
- if (CC_UNLIKELY(isRpcBinder())) {
+ if (isRpcBinder()) [[unlikely]] {
(void)rpcSession()->sendDecStrong(this);
return;
}
@@ -666,7 +668,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");