BQ: Conditionally compile validateConsistencyLocked
- Only enable it on userdebug and eng builds so that it won't slow
down user builds.
Change-Id: I70933a23d54657fdf5cbc23873da4fbee84b9a26
diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h
index 23cd066..e2e73a0 100644
--- a/include/gui/BufferQueueCore.h
+++ b/include/gui/BufferQueueCore.h
@@ -126,9 +126,11 @@
// waitWhileAllocatingLocked blocks until mIsAllocating is false.
void waitWhileAllocatingLocked() const;
+#if DEBUG_ONLY_CODE
// validateConsistencyLocked ensures that the free lists are in sync with
// the information stored in mSlots
void validateConsistencyLocked() const;
+#endif
// mAllocator is the connection to SurfaceFlinger that is used to allocate
// new GraphicBuffer objects.
diff --git a/libs/gui/Android.mk b/libs/gui/Android.mk
index 8a965dd..635020e 100644
--- a/libs/gui/Android.mk
+++ b/libs/gui/Android.mk
@@ -36,6 +36,8 @@
# Don't warn about struct padding
LOCAL_CPPFLAGS += -Wno-padded
+LOCAL_CPPFLAGS += -DDEBUG_ONLY_CODE=$(if $(filter userdebug eng,$(TARGET_BUILD_VARIANT)),1,0)
+
LOCAL_SRC_FILES := \
IGraphicBufferConsumer.cpp \
IConsumerListener.cpp \
diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp
index d182f6b..9c1bbe4 100644
--- a/libs/gui/BufferQueueConsumer.cpp
+++ b/libs/gui/BufferQueueConsumer.cpp
@@ -20,6 +20,12 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
//#define LOG_NDEBUG 0
+#if DEBUG_ONLY_CODE
+#define VALIDATE_CONSISTENCY() do { mCore->validateConsistencyLocked(); } while (0)
+#else
+#define VALIDATE_CONSISTENCY()
+#endif
+
#include <gui/BufferItem.h>
#include <gui/BufferQueueConsumer.h>
#include <gui/BufferQueueCore.h>
@@ -252,7 +258,7 @@
ATRACE_INT(mCore->mConsumerName.string(), mCore->mQueue.size());
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
}
if (listener != NULL) {
@@ -296,7 +302,7 @@
mCore->mFreeSlots.insert(slot);
mCore->clearBufferSlotLocked(slot);
mCore->mDequeueCondition.broadcast();
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return NO_ERROR;
}
@@ -386,7 +392,7 @@
// for attached buffers.
mSlots[*outSlot].mAcquireCalled = false;
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return NO_ERROR;
}
@@ -446,7 +452,7 @@
BQ_LOGV("releaseBuffer: releasing slot %d", slot);
mCore->mDequeueCondition.broadcast();
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
} // Autolock scope
// Call back without lock held
@@ -633,7 +639,7 @@
BQ_LOGV("setMaxAcquiredBufferCount: %d", maxAcquiredBuffers);
mCore->mMaxAcquiredBufferCount = maxAcquiredBuffers;
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return NO_ERROR;
}
diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp
index f02ff5f..5c80694 100644
--- a/libs/gui/BufferQueueCore.cpp
+++ b/libs/gui/BufferQueueCore.cpp
@@ -20,6 +20,12 @@
#define EGL_EGLEXT_PROTOTYPES
+#if DEBUG_ONLY_CODE
+#define VALIDATE_CONSISTENCY() do { validateConsistencyLocked(); } while (0)
+#else
+#define VALIDATE_CONSISTENCY()
+#endif
+
#include <inttypes.h>
#include <gui/BufferItem.h>
@@ -216,7 +222,7 @@
b.mIsStale = true;
}
- validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
}
bool BufferQueueCore::adjustAvailableSlotsLocked(int delta) {
@@ -258,6 +264,7 @@
}
}
+#if DEBUG_ONLY_CODE
void BufferQueueCore::validateConsistencyLocked() const {
static const useconds_t PAUSE_TIME = 0;
int allocatedSlots = 0;
@@ -382,5 +389,6 @@
mUnusedSlots.size());
}
}
+#endif
} // namespace android
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index 22a2d79..3c06899 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -20,6 +20,12 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
//#define LOG_NDEBUG 0
+#if DEBUG_ONLY_CODE
+#define VALIDATE_CONSISTENCY() do { mCore->validateConsistencyLocked(); } while (0)
+#else
+#define VALIDATE_CONSISTENCY()
+#endif
+
#define EGL_EGLEXT_PROTOTYPES
#include <gui/BufferItem.h>
@@ -140,7 +146,7 @@
return BAD_VALUE;
}
mCore->mMaxDequeuedBufferCount = maxDequeuedBuffers;
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
mCore->mDequeueCondition.broadcast();
listener = mCore->mConsumerListener;
} // Autolock scope
@@ -189,7 +195,7 @@
return BAD_VALUE;
}
mCore->mAsyncMode = async;
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
mCore->mDequeueCondition.broadcast();
listener = mCore->mConsumerListener;
} // Autolock scope
@@ -495,7 +501,7 @@
return NO_INIT;
}
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
} // Autolock scope
}
@@ -566,7 +572,7 @@
mCore->mFreeSlots.insert(slot);
mCore->clearBufferSlotLocked(slot);
mCore->mDequeueCondition.broadcast();
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return NO_ERROR;
}
@@ -616,7 +622,7 @@
*outBuffer = mSlots[found].mGraphicBuffer;
*outFence = mSlots[found].mFence;
mCore->clearBufferSlotLocked(found);
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return NO_ERROR;
}
@@ -684,7 +690,7 @@
mSlots[*outSlot].mRequestBufferCalled = true;
mSlots[*outSlot].mAcquireCalled = false;
mCore->mActiveBuffers.insert(found);
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return returnFlags;
}
@@ -861,7 +867,7 @@
// Take a ticket for the callback functions
callbackTicket = mNextCallbackTicket++;
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
} // Autolock scope
// Don't send the GraphicBuffer through the callback, and don't send
@@ -948,7 +954,7 @@
mSlots[slot].mFence = fence;
mCore->mDequeueCondition.broadcast();
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return NO_ERROR;
}
@@ -1087,7 +1093,7 @@
}
mCore->mAllowAllocation = true;
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
return status;
}
@@ -1252,7 +1258,7 @@
mCore->mIsAllocating = false;
mCore->mIsAllocatingCondition.broadcast();
- mCore->validateConsistencyLocked();
+ VALIDATE_CONSISTENCY();
} // Autolock scope
}
}
@@ -1316,7 +1322,8 @@
mDequeueTimeout = timeout;
mCore->mDequeueBufferCannotBlock = false;
- mCore->validateConsistencyLocked();
+
+ VALIDATE_CONSISTENCY();
return NO_ERROR;
}