Fix audioflinger in integer sanitized builds.
Refactor threadLoop() to avoid unsigned integer overflows
which were causing errors on integer sanitized builds.
Also disable sanitization in fnv1a.
Bug: 30969751
Test: Compiles with and without integer sanitization.
Test: Device boots.
Change-Id: Ia8201e8a8f1d4df2b356ec81003fb07598db4546
Merged-In: Ia8201e8a8f1d4df2b356ec81003fb07598db4546
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index e202ca4..b8325f5 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -3307,9 +3307,13 @@
// 2. threadLoop_mix (significant for heavy mixing, especially
// on low tier processors)
- // it's OK if deltaMs is an overestimate.
- const int32_t deltaMs =
- (lastWriteFinished - previousLastWriteFinished) / 1000000;
+ // it's OK if deltaMs (and deltaNs) is an overestimate.
+ nsecs_t deltaNs;
+ // deltaNs = lastWriteFinished - previousLastWriteFinished;
+ __builtin_sub_overflow(
+ lastWriteFinished,previousLastWriteFinished, &deltaNs);
+ const int32_t deltaMs = deltaNs / 1000000;
+
const int32_t throttleMs = mHalfBufferMs - deltaMs;
if ((signed)mHalfBufferMs >= throttleMs && throttleMs > 0) {
usleep(throttleMs * 1000);