Use the standard CC_LIKELY and CC_UNLIKELY macros

Several source files privately defined macros LIKELY and UNLIKELY in terms
of __builtin_expect. But <cutils/compiler.h> already has CC_LIKELY and
CC_UNLIKELY which are intended for this purpose.  So rename the private
uses to use the standard names.

In addition, AudioFlinger was relying on the macro expanding to extra ( ).

Change-Id: I2494e087a0c0cac0ac998335f5e9c8ad02955873
This commit is contained in:
Glenn Kasten 2011-12-15 09:51:17 -08:00
parent a91bc48fbd
commit 99ed22412d
5 changed files with 18 additions and 27 deletions

View File

@ -40,11 +40,6 @@
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
// ---------------------------------------------------------------------------
namespace android { namespace android {
class IDisplayEventConnection; class IDisplayEventConnection;

View File

@ -42,9 +42,6 @@
#define AID_GRAPHICS 1003 #define AID_GRAPHICS 1003
#endif #endif
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
namespace android { namespace android {

View File

@ -240,7 +240,7 @@ void LayerBase::validateVisibility(const Transform& planeTransform)
for (size_t i=0 ; i<4 ; i++) for (size_t i=0 ; i<4 ; i++)
mVertices[i][1] = hw_h - mVertices[i][1]; mVertices[i][1] = hw_h - mVertices[i][1];
if (UNLIKELY(transformed)) { if (CC_UNLIKELY(transformed)) {
// NOTE: here we could also punt if we have too many rectangles // NOTE: here we could also punt if we have too many rectangles
// in the transparent region // in the transparent region
if (tr.preserveRects()) { if (tr.preserveRects()) {
@ -416,7 +416,7 @@ void LayerBase::drawWithOpenGL(const Region& clip) const
const State& s(drawingState()); const State& s(drawingState());
GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
if (UNLIKELY(s.alpha < 0xFF)) { if (CC_UNLIKELY(s.alpha < 0xFF)) {
const GLfloat alpha = s.alpha * (1.0f/255.0f); const GLfloat alpha = s.alpha * (1.0f/255.0f);
if (mPremultipliedAlpha) { if (mPremultipliedAlpha) {
glColor4f(alpha, alpha, alpha, alpha); glColor4f(alpha, alpha, alpha, alpha);

View File

@ -404,14 +404,14 @@ bool SurfaceFlinger::threadLoop()
waitForEvent(); waitForEvent();
// check for transactions // check for transactions
if (UNLIKELY(mConsoleSignals)) { if (CC_UNLIKELY(mConsoleSignals)) {
handleConsoleEvents(); handleConsoleEvents();
} }
// if we're in a global transaction, don't do anything. // if we're in a global transaction, don't do anything.
const uint32_t mask = eTransactionNeeded | eTraversalNeeded; const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
uint32_t transactionFlags = peekTransactionFlags(mask); uint32_t transactionFlags = peekTransactionFlags(mask);
if (UNLIKELY(transactionFlags)) { if (CC_UNLIKELY(transactionFlags)) {
handleTransaction(transactionFlags); handleTransaction(transactionFlags);
} }
@ -423,13 +423,13 @@ bool SurfaceFlinger::threadLoop()
return true; return true;
} }
if (UNLIKELY(mHwWorkListDirty)) { if (CC_UNLIKELY(mHwWorkListDirty)) {
// build the h/w work list // build the h/w work list
handleWorkList(); handleWorkList();
} }
const DisplayHardware& hw(graphicPlane(0).displayHardware()); const DisplayHardware& hw(graphicPlane(0).displayHardware());
if (LIKELY(hw.canDraw())) { if (CC_LIKELY(hw.canDraw())) {
// repaint the framebuffer (if needed) // repaint the framebuffer (if needed)
const int index = hw.getCurrentBufferIndex(); const int index = hw.getCurrentBufferIndex();
@ -629,7 +629,7 @@ void SurfaceFlinger::computeVisibleRegions(
// handle hidden surfaces by setting the visible region to empty // handle hidden surfaces by setting the visible region to empty
if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) { if (CC_LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
const bool translucent = !layer->isOpaque(); const bool translucent = !layer->isOpaque();
const Rect bounds(layer->visibleBounds()); const Rect bounds(layer->visibleBounds());
visibleRegion.set(bounds); visibleRegion.set(bounds);
@ -814,7 +814,7 @@ void SurfaceFlinger::handleRepaint()
// compute the invalid region // compute the invalid region
mSwapRegion.orSelf(mDirtyRegion); mSwapRegion.orSelf(mDirtyRegion);
if (UNLIKELY(mDebugRegion)) { if (CC_UNLIKELY(mDebugRegion)) {
debugFlashRegions(); debugFlashRegions();
} }
@ -968,7 +968,7 @@ void SurfaceFlinger::composeSurfaces(const Region& dirty)
HWComposer& hwc(hw.getHwComposer()); HWComposer& hwc(hw.getHwComposer());
const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER); const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER);
if (UNLIKELY(fbLayerCount && !mWormholeRegion.isEmpty())) { if (CC_UNLIKELY(fbLayerCount && !mWormholeRegion.isEmpty())) {
// should never happen unless the window manager has a bug // should never happen unless the window manager has a bug
// draw something... // draw something...
drawWormhole(); drawWormhole();
@ -1053,7 +1053,7 @@ void SurfaceFlinger::drawWormhole() const
const int32_t width = hw.getWidth(); const int32_t width = hw.getWidth();
const int32_t height = hw.getHeight(); const int32_t height = hw.getHeight();
if (LIKELY(!mDebugBackground)) { if (CC_LIKELY(!mDebugBackground)) {
glClearColor(0,0,0,0); glClearColor(0,0,0,0);
Region::const_iterator it = region.begin(); Region::const_iterator it = region.begin();
Region::const_iterator const end = region.end(); Region::const_iterator const end = region.end();
@ -1257,7 +1257,7 @@ void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& state,
int SurfaceFlinger::setOrientation(DisplayID dpy, int SurfaceFlinger::setOrientation(DisplayID dpy,
int orientation, uint32_t flags) int orientation, uint32_t flags)
{ {
if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) if (CC_UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
return BAD_VALUE; return BAD_VALUE;
Mutex::Autolock _l(mStateLock); Mutex::Autolock _l(mStateLock);
@ -1356,7 +1356,7 @@ sp<Layer> SurfaceFlinger::createNormalSurface(
sp<Layer> layer = new Layer(this, display, client); sp<Layer> layer = new Layer(this, display, client);
status_t err = layer->setBuffers(w, h, format, flags); status_t err = layer->setBuffers(w, h, format, flags);
if (LIKELY(err != NO_ERROR)) { if (CC_LIKELY(err != NO_ERROR)) {
LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err)); LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err));
layer.clear(); layer.clear();
} }
@ -1676,7 +1676,7 @@ status_t SurfaceFlinger::onTransact(
status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
CHECK_INTERFACE(ISurfaceComposer, data, reply); CHECK_INTERFACE(ISurfaceComposer, data, reply);
if (UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) { if (CC_UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) {
IPCThreadState* ipc = IPCThreadState::self(); IPCThreadState* ipc = IPCThreadState::self();
const int pid = ipc->getCallingPid(); const int pid = ipc->getCallingPid();
const int uid = ipc->getCallingUid(); const int uid = ipc->getCallingUid();
@ -2261,7 +2261,7 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
status_t result = PERMISSION_DENIED; status_t result = PERMISSION_DENIED;
// only one display supported for now // only one display supported for now
if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) if (CC_UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
return BAD_VALUE; return BAD_VALUE;
if (!GLExtensions::getInstance().haveFramebufferObject()) if (!GLExtensions::getInstance().haveFramebufferObject())
@ -2383,7 +2383,7 @@ status_t SurfaceFlinger::captureScreen(DisplayID dpy,
uint32_t minLayerZ, uint32_t maxLayerZ) uint32_t minLayerZ, uint32_t maxLayerZ)
{ {
// only one display supported for now // only one display supported for now
if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) if (CC_UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
return BAD_VALUE; return BAD_VALUE;
if (!GLExtensions::getInstance().haveFramebufferObject()) if (!GLExtensions::getInstance().haveFramebufferObject())
@ -2511,7 +2511,7 @@ status_t Client::onTransact(
const int pid = ipc->getCallingPid(); const int pid = ipc->getCallingPid();
const int uid = ipc->getCallingUid(); const int uid = ipc->getCallingUid();
const int self_pid = getpid(); const int self_pid = getpid();
if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) { if (CC_UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) {
// we're called from a different process, do the real check // we're called from a different process, do the real check
if (!PermissionCache::checkCallingPermission(sAccessSurfaceFlinger)) if (!PermissionCache::checkCallingPermission(sAccessSurfaceFlinger))
{ {

View File

@ -20,6 +20,8 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <cutils/compiler.h>
#include <utils/Atomic.h> #include <utils/Atomic.h>
#include <utils/Errors.h> #include <utils/Errors.h>
#include <utils/KeyedVector.h> #include <utils/KeyedVector.h>
@ -53,9 +55,6 @@ class LayerDim;
class LayerScreenshot; class LayerScreenshot;
struct surface_flinger_cblk_t; struct surface_flinger_cblk_t;
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
class Client : public BnSurfaceComposerClient class Client : public BnSurfaceComposerClient