FastPath: More clang-tidy optimizations

use-default-member-init

Test: ALLOW_LOCAL_TIDY_TRUE=1 mm -j .
Test: atest AudioTrackTest AudioRecordTest
Bug: 284390461
Merged-In: I4b5570bcbe3d4c3df890d87f547bab1de3c62187
Change-Id: I4b5570bcbe3d4c3df890d87f547bab1de3c62187
(cherry picked from commit 87e740a67f3ebac577635cd321ba7a88c65d1f0f)
diff --git a/services/audioflinger/fastpath/Android.bp b/services/audioflinger/fastpath/Android.bp
index 10f1af9..6c024e7 100644
--- a/services/audioflinger/fastpath/Android.bp
+++ b/services/audioflinger/fastpath/Android.bp
@@ -61,16 +61,7 @@
     "-bugprone-narrowing-conversions", // b/182410845
 
     // TODO(b/275642749) Reenable these warnings
-    "-bugprone-assignment-in-if-condition",
-    "-bugprone-forward-declaration-namespace",
-    "-bugprone-parent-virtual-call",
-    "-cert-dcl59-cpp",
-    "-cert-err34-c",
-    "-google-runtime-int",
     "-misc-non-private-member-variables-in-classes",
-    "-modernize-concat-nested-namespaces",
-    "-modernize-loop-convert",
-    "-modernize-use-default-member-init",
     "-performance-no-int-to-ptr",
 ]
 
diff --git a/services/audioflinger/fastpath/FastCapture.cpp b/services/audioflinger/fastpath/FastCapture.cpp
index 5c76649..288036d 100644
--- a/services/audioflinger/fastpath/FastCapture.cpp
+++ b/services/audioflinger/fastpath/FastCapture.cpp
@@ -30,17 +30,13 @@
 
 namespace android {
 
-/*static*/ const FastCaptureState FastCapture::sInitial;
+/*static*/ const FastCaptureState FastCapture::sInitial{};
 
-FastCapture::FastCapture() : FastThread("cycleC_ms", "loadC_us"),
-    mInputSource(nullptr), mInputSourceGen(0), mPipeSink(nullptr), mPipeSinkGen(0),
-    mReadBuffer(nullptr), mReadBufferState(-1), mFormat(Format_Invalid), mSampleRate(0),
-    // mDummyDumpState
-    mTotalNativeFramesRead(0)
+FastCapture::FastCapture() : FastThread("cycleC_ms", "loadC_us")
 {
+    // base class initialization
     mPrevious = &sInitial;
     mCurrent = &sInitial;
-
     mDummyDumpState = &mDummyFastCaptureDumpState;
 }
 
diff --git a/services/audioflinger/fastpath/FastCapture.h b/services/audioflinger/fastpath/FastCapture.h
index 657a324..b565216 100644
--- a/services/audioflinger/fastpath/FastCapture.h
+++ b/services/audioflinger/fastpath/FastCapture.h
@@ -48,17 +48,17 @@
 
     FastCaptureState    mPreIdle;   // copy of state before we went into idle
     // FIXME by renaming, could pull up many of these to FastThread
-    NBAIO_Source*       mInputSource;
-    int                 mInputSourceGen;
-    NBAIO_Sink*         mPipeSink;
-    int                 mPipeSinkGen;
-    void*               mReadBuffer;
-    ssize_t             mReadBufferState;   // number of initialized frames in readBuffer,
-                                            // or -1 to clear
-    NBAIO_Format        mFormat;
-    unsigned            mSampleRate;
+    NBAIO_Source*       mInputSource = nullptr;
+    int                 mInputSourceGen = 0;
+    NBAIO_Sink*         mPipeSink = nullptr;
+    int                 mPipeSinkGen = 0;
+    void*               mReadBuffer = nullptr;
+    ssize_t             mReadBufferState = -1;  // number of initialized frames in readBuffer,
+                                                // or -1 to clear
+    NBAIO_Format        mFormat = Format_Invalid;
+    unsigned            mSampleRate = 0;
     FastCaptureDumpState mDummyFastCaptureDumpState;
-    uint32_t            mTotalNativeFramesRead; // copied to dumpState->mFramesRead
+    uint32_t            mTotalNativeFramesRead = 0; // copied to dumpState->mFramesRead
 
 };  // class FastCapture
 
diff --git a/services/audioflinger/fastpath/FastCaptureDumpState.cpp b/services/audioflinger/fastpath/FastCaptureDumpState.cpp
index e0ac9cc..fe7ea16 100644
--- a/services/audioflinger/fastpath/FastCaptureDumpState.cpp
+++ b/services/audioflinger/fastpath/FastCaptureDumpState.cpp
@@ -24,11 +24,6 @@
 
 namespace android {
 
-FastCaptureDumpState::FastCaptureDumpState() : FastThreadDumpState(),
-    mReadSequence(0), mFramesRead(0), mReadErrors(0), mSampleRate(0), mFrameCount(0)
-{
-}
-
 void FastCaptureDumpState::dump(int fd) const
 {
     if (mCommand == FastCaptureState::INITIAL) {
diff --git a/services/audioflinger/fastpath/FastCaptureDumpState.h b/services/audioflinger/fastpath/FastCaptureDumpState.h
index e205518..3dc8a9b 100644
--- a/services/audioflinger/fastpath/FastCaptureDumpState.h
+++ b/services/audioflinger/fastpath/FastCaptureDumpState.h
@@ -24,16 +24,14 @@
 namespace android {
 
 struct FastCaptureDumpState : FastThreadDumpState {
-    FastCaptureDumpState();
-
     void dump(int fd) const;    // should only be called on a stable copy, not the original
 
     // FIXME by renaming, could pull up many of these to FastThreadDumpState
-    uint32_t mReadSequence;     // incremented before and after each read()
-    uint32_t mFramesRead;       // total number of frames read successfully
-    uint32_t mReadErrors;       // total number of read() errors
-    uint32_t mSampleRate;
-    size_t   mFrameCount;
+    uint32_t mReadSequence = 0;  // incremented before and after each read()
+    uint32_t mFramesRead = 0;    // total number of frames read successfully
+    uint32_t mReadErrors = 0;    // total number of read() errors
+    uint32_t mSampleRate = 0;
+    size_t   mFrameCount = 0;
     bool     mSilenced = false; // capture is silenced
 };
 
diff --git a/services/audioflinger/fastpath/FastCaptureState.cpp b/services/audioflinger/fastpath/FastCaptureState.cpp
index d2df62a..77c0c4c 100644
--- a/services/audioflinger/fastpath/FastCaptureState.cpp
+++ b/services/audioflinger/fastpath/FastCaptureState.cpp
@@ -18,11 +18,6 @@
 
 namespace android {
 
-FastCaptureState::FastCaptureState() : FastThreadState(),
-    mInputSource(nullptr), mInputSourceGen(0), mPipeSink(nullptr), mPipeSinkGen(0), mFrameCount(0)
-{
-}
-
 // static
 const char *FastCaptureState::commandToString(Command command)
 {
@@ -35,7 +30,7 @@
     case FastCaptureState::WRITE:       return "WRITE";
     case FastCaptureState::READ_WRITE:  return "READ_WRITE";
     }
-    LOG_ALWAYS_FATAL("%s", __func__);
+    LOG_ALWAYS_FATAL("%s: command %d invalid", __func__, (int) command);
 }
 
 }  // namespace android
diff --git a/services/audioflinger/fastpath/FastCaptureState.h b/services/audioflinger/fastpath/FastCaptureState.h
index 82ea0ed..0f4126e 100644
--- a/services/audioflinger/fastpath/FastCaptureState.h
+++ b/services/audioflinger/fastpath/FastCaptureState.h
@@ -26,15 +26,14 @@
 
 // Represent a single state of the fast capture
 struct FastCaptureState : FastThreadState {
-                FastCaptureState();
-
     // all pointer fields use raw pointers; objects are owned and ref-counted by RecordThread
-    NBAIO_Source*   mInputSource;       // HAL input device, must already be negotiated
+    NBAIO_Source*   mInputSource = nullptr; // HAL input device, must already be negotiated
     // FIXME by renaming, could pull up these fields to FastThreadState
-    int             mInputSourceGen;    // increment when mInputSource is assigned
-    NBAIO_Sink*     mPipeSink;          // after reading from input source, write to this pipe sink
-    int             mPipeSinkGen;       // increment when mPipeSink is assigned
-    size_t          mFrameCount;        // number of frames per fast capture buffer
+    int             mInputSourceGen = 0;    // increment when mInputSource is assigned
+    NBAIO_Sink*     mPipeSink = nullptr;    // after reading from input source,
+                                            // write to this pipe sink
+    int             mPipeSinkGen = 0;       // increment when mPipeSink is assigned
+    size_t          mFrameCount = 0;        // number of frames per fast capture buffer
     audio_track_cblk_t* mCblk;          // control block for the single fast client, or NULL
 
     audio_format_t  mFastPatchRecordFormat = AUDIO_FORMAT_INVALID;
diff --git a/services/audioflinger/fastpath/FastMixer.cpp b/services/audioflinger/fastpath/FastMixer.cpp
index e13adab..e0a15c1 100644
--- a/services/audioflinger/fastpath/FastMixer.cpp
+++ b/services/audioflinger/fastpath/FastMixer.cpp
@@ -61,38 +61,19 @@
     : FastThread("cycle_ms", "load_us"),
     // mFastTrackNames
     // mGenerations
-    mOutputSink(nullptr),
-    mOutputSinkGen(0),
-    mMixer(nullptr),
-    mSinkBuffer(nullptr),
-    mSinkBufferSize(0),
-    mSinkChannelCount(FCC_2),
-    mMixerBuffer(nullptr),
-    mMixerBufferSize(0),
-    mMixerBufferState(UNDEFINED),
-    mFormat(Format_Invalid),
-    mSampleRate(0),
-    mFastTracksGen(0),
-    mTotalNativeFramesWritten(0),
     // timestamp
-    mNativeFramesWrittenButNotPresented(0),   // the = 0 is to silence the compiler
-    mMasterMono(false),
     mThreadIoHandle(parentIoHandle)
 {
     // FIXME pass sInitial as parameter to base class constructor, and make it static local
     mPrevious = &sInitial;
     mCurrent = &sInitial;
-
     mDummyDumpState = &mDummyFastMixerDumpState;
+
     // TODO: Add channel mask to NBAIO_Format.
     // We assume that the channel mask must be a valid positional channel mask.
     mSinkChannelMask = getChannelMaskFromCount(mSinkChannelCount);
     mBalance.setChannelMask(mSinkChannelMask);
 
-    unsigned i;
-    for (i = 0; i < FastMixerState::sMaxFastTracks; ++i) {
-        mGenerations[i] = 0;
-    }
 #ifdef FAST_THREAD_STATISTICS
     mOldLoad.tv_sec = 0;
     mOldLoad.tv_nsec = 0;
diff --git a/services/audioflinger/fastpath/FastMixer.h b/services/audioflinger/fastpath/FastMixer.h
index ab7bfe1..48b94a3 100644
--- a/services/audioflinger/fastpath/FastMixer.h
+++ b/services/audioflinger/fastpath/FastMixer.h
@@ -69,39 +69,39 @@
     static const FastMixerState sInitial;
 
     FastMixerState  mPreIdle;   // copy of state before we went into idle
-    int             mGenerations[FastMixerState::kMaxFastTracks];
+    int             mGenerations[FastMixerState::kMaxFastTracks]{};
                                 // last observed mFastTracks[i].mGeneration
-    NBAIO_Sink*     mOutputSink;
-    int             mOutputSinkGen;
-    AudioMixer*     mMixer;
+    NBAIO_Sink*     mOutputSink = nullptr;
+    int             mOutputSinkGen = 0;
+    AudioMixer*     mMixer = nullptr;
 
     // mSinkBuffer audio format is stored in format.mFormat.
-    void*           mSinkBuffer;        // used for mixer output format translation
+    void*           mSinkBuffer = nullptr; // used for mixer output format translation
                                         // if sink format is different than mixer output.
-    size_t          mSinkBufferSize;
-    uint32_t        mSinkChannelCount;
+    size_t          mSinkBufferSize = 0;
+    uint32_t        mSinkChannelCount = FCC_2;
     audio_channel_mask_t mSinkChannelMask;
-    void*           mMixerBuffer;       // mixer output buffer.
-    size_t          mMixerBufferSize;
+    void*           mMixerBuffer = nullptr;       // mixer output buffer.
+    size_t          mMixerBufferSize = 0;
     static constexpr audio_format_t mMixerBufferFormat = AUDIO_FORMAT_PCM_FLOAT;
 
     uint32_t        mAudioChannelCount; // audio channel count, excludes haptic channels.
 
-    enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
-    NBAIO_Format    mFormat;
-    unsigned        mSampleRate;
-    int             mFastTracksGen;
+    enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState = UNDEFINED;
+    NBAIO_Format    mFormat{Format_Invalid};
+    unsigned        mSampleRate = 0;
+    int             mFastTracksGen = 0;
     FastMixerDumpState mDummyFastMixerDumpState;
-    int64_t         mTotalNativeFramesWritten;  // copied to dumpState->mFramesWritten
+    int64_t         mTotalNativeFramesWritten = 0;  // copied to dumpState->mFramesWritten
 
     // next 2 fields are valid only when timestampStatus == NO_ERROR
     ExtendedTimestamp mTimestamp;
-    int64_t         mNativeFramesWrittenButNotPresented;
+    int64_t         mNativeFramesWrittenButNotPresented = 0;
 
     audio_utils::Balance mBalance;
 
     // accessed without lock between multiple threads.
-    std::atomic_bool mMasterMono;
+    std::atomic_bool mMasterMono{};
     std::atomic<float> mMasterBalance{};
     std::atomic_int_fast64_t mBoottimeOffset;
 
diff --git a/services/audioflinger/fastpath/FastMixerDumpState.cpp b/services/audioflinger/fastpath/FastMixerDumpState.cpp
index f48f539..4f79dd6 100644
--- a/services/audioflinger/fastpath/FastMixerDumpState.cpp
+++ b/services/audioflinger/fastpath/FastMixerDumpState.cpp
@@ -29,14 +29,6 @@
 
 namespace android {
 
-FastMixerDumpState::FastMixerDumpState() : FastThreadDumpState(),
-    mWriteSequence(0), mFramesWritten(0),
-    mNumTracks(0), mWriteErrors(0),
-    mSampleRate(0), mFrameCount(0),
-    mTrackMask(0)
-{
-}
-
 // helper function called by qsort()
 static int compare_uint32_t(const void *pa, const void *pb)
 {
diff --git a/services/audioflinger/fastpath/FastMixerDumpState.h b/services/audioflinger/fastpath/FastMixerDumpState.h
index 91d85b1..1b0e029 100644
--- a/services/audioflinger/fastpath/FastMixerDumpState.h
+++ b/services/audioflinger/fastpath/FastMixerDumpState.h
@@ -54,9 +54,8 @@
 
 // Represents the dump state of a fast track
 struct FastTrackDump {
-    FastTrackDump() : mFramesReady(0) { }
     FastTrackUnderruns  mUnderruns;
-    size_t              mFramesReady;        // most recent value only; no long-term statistics kept
+    size_t              mFramesReady = 0;    // most recent value only; no long-term statistics kept
     int64_t             mFramesWritten;      // last value from track
 };
 
@@ -64,18 +63,16 @@
 static_assert(!std::is_polymorphic_v<FastTrackDump>);
 
 struct FastMixerDumpState : FastThreadDumpState {
-    FastMixerDumpState();
-
     void dump(int fd) const;    // should only be called on a stable copy, not the original
 
-    double   mLatencyMs = 0.;   // measured latency, default of 0 if no valid timestamp read.
-    uint32_t mWriteSequence;    // incremented before and after each write()
-    uint32_t mFramesWritten;    // total number of frames written successfully
-    uint32_t mNumTracks;        // total number of active fast tracks
-    uint32_t mWriteErrors;      // total number of write() errors
-    uint32_t mSampleRate;
-    size_t   mFrameCount;
-    uint32_t mTrackMask;        // mask of active tracks
+    double   mLatencyMs = 0.;     // measured latency, default of 0 if no valid timestamp read.
+    uint32_t mWriteSequence = 0;  // incremented before and after each write()
+    uint32_t mFramesWritten = 0;  // total number of frames written successfully
+    uint32_t mNumTracks = 0;      // total number of active fast tracks
+    uint32_t mWriteErrors = 0;    // total number of write() errors
+    uint32_t mSampleRate = 0;
+    size_t   mFrameCount = 0;
+    uint32_t mTrackMask = 0;      // mask of active tracks
     FastTrackDump   mTracks[FastMixerState::kMaxFastTracks];
 
     // For timestamp statistics.
diff --git a/services/audioflinger/fastpath/FastMixerState.cpp b/services/audioflinger/fastpath/FastMixerState.cpp
index dbccb10..4fe2d86 100644
--- a/services/audioflinger/fastpath/FastMixerState.cpp
+++ b/services/audioflinger/fastpath/FastMixerState.cpp
@@ -22,16 +22,7 @@
 
 namespace android {
 
-FastTrack::FastTrack() :
-    mBufferProvider(nullptr), mVolumeProvider(nullptr),
-    mChannelMask(AUDIO_CHANNEL_OUT_STEREO), mFormat(AUDIO_FORMAT_INVALID), mGeneration(0)
-{
-}
-
-FastMixerState::FastMixerState() : FastThreadState(),
-    // mFastTracks
-    mFastTracksGen(0), mTrackMask(0), mOutputSink(nullptr), mOutputSinkGen(0),
-    mFrameCount(0)
+FastMixerState::FastMixerState() : FastThreadState()
 {
     const int ok = pthread_once(&sMaxFastTracksOnce, sMaxFastTracksInit);
     if (ok != 0) {
@@ -66,7 +57,7 @@
     char value[PROPERTY_VALUE_MAX];
     if (property_get("ro.audio.max_fast_tracks", value, nullptr /* default_value */) > 0) {
         char *endptr;
-        const unsigned long ul = strtoul(value, &endptr, 0);
+        const auto ul = strtoul(value, &endptr, 0);
         if (*endptr == '\0' && kMinFastTracks <= ul && ul <= kMaxFastTracks) {
             sMaxFastTracks = (unsigned) ul;
         }
diff --git a/services/audioflinger/fastpath/FastMixerState.h b/services/audioflinger/fastpath/FastMixerState.h
index f40f612..fdf3eaa 100644
--- a/services/audioflinger/fastpath/FastMixerState.h
+++ b/services/audioflinger/fastpath/FastMixerState.h
@@ -43,13 +43,16 @@
 
 // Represents the state of a fast track
 struct FastTrack {
-    FastTrack();
+    // must be nullptr if inactive, or non-nullptr if active
+    ExtendedAudioBufferProvider* mBufferProvider = nullptr;
 
-    ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
-    VolumeProvider*         mVolumeProvider; // optional; if NULL then full-scale
-    audio_channel_mask_t    mChannelMask;    // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
-    audio_format_t          mFormat;         // track format
-    int                     mGeneration;     // increment when any field is assigned
+    // optional: if nullptr then full-scale
+    VolumeProvider*         mVolumeProvider = nullptr;
+
+    // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
+    audio_channel_mask_t    mChannelMask = AUDIO_CHANNEL_OUT_STEREO;
+    audio_format_t          mFormat = AUDIO_FORMAT_INVALID;         // track format
+    int                     mGeneration = 0;     // increment when any field is assigned
     bool                    mHapticPlaybackEnabled = false; // haptic playback is enabled or not
     os::HapticScale         mHapticIntensity = os::HapticScale::MUTE; // intensity of haptic data
     float                   mHapticMaxAmplitude = NAN; // max amplitude allowed for haptic data
@@ -72,11 +75,12 @@
 
     // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer
     FastTrack   mFastTracks[kMaxFastTracks];
-    int         mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented
-    unsigned    mTrackMask;     // bit i is set if and only if mFastTracks[i] is active
-    NBAIO_Sink* mOutputSink;    // HAL output device, must already be negotiated
-    int         mOutputSinkGen; // increment when mOutputSink is assigned
-    size_t      mFrameCount;    // number of frames per fast mix buffer
+    int         mFastTracksGen = 0; // increment when any
+                                    // mFastTracks[i].mGeneration is incremented
+    unsigned    mTrackMask = 0;     // bit i is set if and only if mFastTracks[i] is active
+    NBAIO_Sink* mOutputSink = nullptr; // HAL output device, must already be negotiated
+    int         mOutputSinkGen = 0; // increment when mOutputSink is assigned
+    size_t      mFrameCount = 0;    // number of frames per fast mix buffer
     audio_channel_mask_t mSinkChannelMask; // If not AUDIO_CHANNEL_NONE, specifies sink channel
                                            // mask when it cannot be directly calculated from
                                            // channel count
diff --git a/services/audioflinger/fastpath/FastThread.cpp b/services/audioflinger/fastpath/FastThread.cpp
index 2ebdbc1..d054d71 100644
--- a/services/audioflinger/fastpath/FastThread.cpp
+++ b/services/audioflinger/fastpath/FastThread.cpp
@@ -38,48 +38,8 @@
 
 namespace android {
 
-FastThread::FastThread(const char *cycleMs, const char *loadUs) : Thread(false /*canCallJava*/),
-    // re-initialized to &sInitial by subclass constructor
-    mPrevious(nullptr), mCurrent(nullptr),
-    /* mOldTs({0, 0}), */
-    mOldTsValid(false),
-    mSleepNs(-1),
-    mPeriodNs(0),
-    mUnderrunNs(0),
-    mOverrunNs(0),
-    mForceNs(0),
-    mWarmupNsMin(0),
-    mWarmupNsMax(LONG_MAX),
-    // re-initialized to &mDummySubclassDumpState by subclass constructor
-    mDummyDumpState(nullptr),
-    mDumpState(nullptr),
-    mIgnoreNextOverrun(true),
-#ifdef FAST_THREAD_STATISTICS
-    // mOldLoad
-    mOldLoadValid(false),
-    mBounds(0),
-    mFull(false),
-    // mTcu
-#endif
-    mColdGen(0),
-    mIsWarm(false),
-    /* mMeasuredWarmupTs({0, 0}), */
-    mWarmupCycles(0),
-    mWarmupConsecutiveInRangeCycles(0),
-    mTimestampStatus(INVALID_OPERATION),
-
-    mCommand(FastThreadState::INITIAL),
-#if 0
-    frameCount(0),
-#endif
-    mAttemptedWrite(false)
-    // mCycleMs(cycleMs)
-    // mLoadUs(loadUs)
+FastThread::FastThread(const char *cycleMs, const char *loadUs) : Thread(false /*canCallJava*/)
 {
-    mOldTs.tv_sec = 0;
-    mOldTs.tv_nsec = 0;
-    mMeasuredWarmupTs.tv_sec = 0;
-    mMeasuredWarmupTs.tv_nsec = 0;
     strlcpy(mCycleMs, cycleMs, sizeof(mCycleMs));
     strlcpy(mLoadUs, loadUs, sizeof(mLoadUs));
 }
@@ -95,7 +55,10 @@
         if (mSleepNs >= 0) {
             if (mSleepNs > 0) {
                 ALOG_ASSERT(mSleepNs < 1000000000);
-                const struct timespec req = {0, mSleepNs};
+                const struct timespec req = {
+                    0, // tv_sec
+                    static_cast<long>(mSleepNs) // NOLINT(google-runtime-int)
+                };
                 nanosleep(&req, nullptr);
             } else {
                 sched_yield();
@@ -221,7 +184,7 @@
         if (rc == 0) {
             if (mOldTsValid) {
                 time_t sec = newTs.tv_sec - mOldTs.tv_sec;
-                long nsec = newTs.tv_nsec - mOldTs.tv_nsec;
+                auto nsec = newTs.tv_nsec - mOldTs.tv_nsec;
                 ALOGE_IF(sec < 0 || (sec == 0 && nsec < 0),
                         "clock_gettime(CLOCK_MONOTONIC) failed: was %ld.%09ld but now %ld.%09ld",
                         mOldTs.tv_sec, mOldTs.tv_nsec, newTs.tv_sec, newTs.tv_nsec);
diff --git a/services/audioflinger/fastpath/FastThread.h b/services/audioflinger/fastpath/FastThread.h
index 84dc4d2..1f46b29 100644
--- a/services/audioflinger/fastpath/FastThread.h
+++ b/services/audioflinger/fastpath/FastThread.h
@@ -47,44 +47,47 @@
     virtual void onWork() = 0;
 
     // FIXME these former local variables need comments
-    const FastThreadState*  mPrevious;
-    const FastThreadState*  mCurrent;
-    struct timespec mOldTs;
-    bool            mOldTsValid;
-    long            mSleepNs;       // -1: busy wait, 0: sched_yield, > 0: nanosleep
-    long            mPeriodNs;      // expected period; the time required to render one mix buffer
-    long            mUnderrunNs;    // underrun likely when write cycle is greater than this value
-    long            mOverrunNs;     // overrun likely when write cycle is less than this value
-    long            mForceNs;       // if overrun detected,
-                                    // force the write cycle to take this much time
-    long            mWarmupNsMin;   // warmup complete when write cycle is greater than or equal to
-                                    // this value
-    long            mWarmupNsMax;   // and less than or equal to this value
-    FastThreadDumpState* mDummyDumpState;
-    FastThreadDumpState* mDumpState;
-    bool            mIgnoreNextOverrun;     // used to ignore initial overrun and first after an
-                                            // underrun
+    const FastThreadState*  mPrevious = nullptr;
+    const FastThreadState*  mCurrent = nullptr;
+    struct timespec mOldTs{};
+    bool            mOldTsValid = false;
+    int64_t         mSleepNs = -1;     // -1: busy wait, 0: sched_yield, > 0: nanosleep
+    int64_t         mPeriodNs = 0;     // expected period; the time required to
+                                       // render one mix buffer
+    int64_t         mUnderrunNs = 0;   // underrun likely when write cycle
+                                       // is greater than this value
+    int64_t         mOverrunNs = 0;    // overrun likely when write cycle is less than this value
+    int64_t         mForceNs = 0;      // if overrun detected,
+                                       // force the write cycle to take this much time
+    int64_t         mWarmupNsMin = 0;  // warmup complete when write cycle is greater
+                                       //  than or equal to this value
+    int64_t         mWarmupNsMax = INT64_MAX;  // and less than or equal to this value
+    FastThreadDumpState* mDummyDumpState = nullptr;
+    FastThreadDumpState* mDumpState = nullptr;
+    bool            mIgnoreNextOverrun = true; // used to ignore initial overrun
+                                               //  and first after an underrun
 #ifdef FAST_THREAD_STATISTICS
     struct timespec mOldLoad;       // previous value of clock_gettime(CLOCK_THREAD_CPUTIME_ID)
-    bool            mOldLoadValid;  // whether oldLoad is valid
-    uint32_t        mBounds;
-    bool            mFull;          // whether we have collected at least mSamplingN samples
+    bool            mOldLoadValid = false;  // whether oldLoad is valid
+    uint32_t        mBounds = 0;
+    bool            mFull = false;        // whether we have collected at least mSamplingN samples
 #ifdef CPU_FREQUENCY_STATISTICS
     ThreadCpuUsage  mTcu;           // for reading the current CPU clock frequency in kHz
 #endif
 #endif
-    unsigned        mColdGen;       // last observed mColdGen
-    bool            mIsWarm;        // true means ready to mix,
+    unsigned        mColdGen = 0;       // last observed mColdGen
+    bool            mIsWarm = false;        // true means ready to mix,
                                     // false means wait for warmup before mixing
-    struct timespec   mMeasuredWarmupTs;  // how long did it take for warmup to complete
-    uint32_t          mWarmupCycles;  // counter of number of loop cycles during warmup phase
-    uint32_t          mWarmupConsecutiveInRangeCycles;    // number of consecutive cycles in range
+    struct timespec   mMeasuredWarmupTs{};  // how long did it take for warmup to complete
+    uint32_t          mWarmupCycles = 0;  // counter of number of loop cycles during warmup phase
+    uint32_t          mWarmupConsecutiveInRangeCycles = 0; // number of consecutive cycles in range
     const sp<NBLog::Writer> mDummyNBLogWriter{new NBLog::Writer()};
-    status_t          mTimestampStatus;
+    status_t          mTimestampStatus = INVALID_OPERATION;
 
-    FastThreadState::Command mCommand;
-    bool            mAttemptedWrite;
+    FastThreadState::Command mCommand = FastThreadState::INITIAL;
+    bool            mAttemptedWrite = false;
 
+    // init in constructor
     char            mCycleMs[16];   // cycle_ms + suffix
     char            mLoadUs[16];    // load_us + suffix
 
diff --git a/services/audioflinger/fastpath/FastThreadDumpState.cpp b/services/audioflinger/fastpath/FastThreadDumpState.cpp
index 09d4744..747cb9e 100644
--- a/services/audioflinger/fastpath/FastThreadDumpState.cpp
+++ b/services/audioflinger/fastpath/FastThreadDumpState.cpp
@@ -19,16 +19,8 @@
 
 namespace android {
 
-FastThreadDumpState::FastThreadDumpState() :
-    mCommand(FastThreadState::INITIAL), mUnderruns(0), mOverruns(0),
-    /* mMeasuredWarmupTs({0, 0}), */
-    mWarmupCycles(0)
-#ifdef FAST_THREAD_STATISTICS
-    , mSamplingN(0), mBounds(0)
-#endif
+FastThreadDumpState::FastThreadDumpState()
 {
-    mMeasuredWarmupTs.tv_sec = 0;
-    mMeasuredWarmupTs.tv_nsec = 0;
 #ifdef FAST_THREAD_STATISTICS
     increaseSamplingN(1);
 #endif
diff --git a/services/audioflinger/fastpath/FastThreadDumpState.h b/services/audioflinger/fastpath/FastThreadDumpState.h
index 63e81d3..b7bc404 100644
--- a/services/audioflinger/fastpath/FastThreadDumpState.h
+++ b/services/audioflinger/fastpath/FastThreadDumpState.h
@@ -32,11 +32,11 @@
 struct FastThreadDumpState {
     FastThreadDumpState();
 
-    FastThreadState::Command mCommand;   // current command
-    uint32_t mUnderruns;        // total number of underruns
-    uint32_t mOverruns;         // total number of overruns
-    struct timespec mMeasuredWarmupTs;  // measured warmup time
-    uint32_t mWarmupCycles;     // number of loop cycles required to warmup
+    FastThreadState::Command mCommand = FastThreadState::INITIAL;  // current command
+    uint32_t mUnderruns = 0;        // total number of underruns
+    uint32_t mOverruns = 0;         // total number of overruns
+    struct timespec mMeasuredWarmupTs{};  // measured warmup time
+    uint32_t mWarmupCycles = 0;     // number of loop cycles required to warmup
 
 #ifdef FAST_THREAD_STATISTICS
     // Recently collected samples of per-cycle monotonic time, thread CPU time, and CPU frequency.
@@ -48,12 +48,12 @@
     // This value was chosen such that each array uses 1 small page (4 Kbytes).
     static const uint32_t kSamplingNforLowRamDevice = 0x400;
     // Corresponding runtime maximum size of sample arrays, must be a power of 2 <= kSamplingN.
-    uint32_t mSamplingN;
+    uint32_t mSamplingN = 0;
     // The bounds define the interval of valid samples, and are represented as follows:
     //      newest open (excluded) endpoint   = lower 16 bits of bounds, modulo N
     //      oldest closed (included) endpoint = upper 16 bits of bounds, modulo N
     // Number of valid samples is newest - oldest.
-    uint32_t mBounds;                   // bounds for mMonotonicNs, mThreadCpuNs, and mCpukHz
+    uint32_t mBounds = 0;               // bounds for mMonotonicNs, mThreadCpuNs, and mCpukHz
     // The elements in the *Ns arrays are in units of nanoseconds <= 3999999999.
     uint32_t mMonotonicNs[kSamplingN];  // delta monotonic (wall clock) time
     uint32_t mLoadNs[kSamplingN];       // delta CPU load in time
diff --git a/services/audioflinger/fastpath/FastThreadState.cpp b/services/audioflinger/fastpath/FastThreadState.cpp
index e6cb353..dfe8e65 100644
--- a/services/audioflinger/fastpath/FastThreadState.cpp
+++ b/services/audioflinger/fastpath/FastThreadState.cpp
@@ -19,12 +19,6 @@
 
 namespace android {
 
-FastThreadState::FastThreadState() :
-    mCommand(INITIAL), mColdFutexAddr(nullptr), mColdGen(0), mDumpState(nullptr)
-    , mNBLogWriter(nullptr)
-{
-}
-
 // static
 const char *FastThreadState::commandToString(FastThreadState::Command command)
 {
diff --git a/services/audioflinger/fastpath/FastThreadState.h b/services/audioflinger/fastpath/FastThreadState.h
index 2b8b079..8e5bedd 100644
--- a/services/audioflinger/fastpath/FastThreadState.h
+++ b/services/audioflinger/fastpath/FastThreadState.h
@@ -27,8 +27,6 @@
 
 // Represents a single state of a FastThread
 struct FastThreadState {
-                FastThreadState();
-
     using Command = uint32_t;
     static const Command
         INITIAL = 0,            // used only for the initial state
@@ -37,13 +35,14 @@
         IDLE = 3,               // either HOT_IDLE or COLD_IDLE
         EXIT = 4;               // exit from thread
         // additional values defined per subclass
-    Command     mCommand;       // current command
-    int32_t*    mColdFutexAddr; // for COLD_IDLE only, pointer to the associated futex
-    unsigned    mColdGen;       // increment when COLD_IDLE is requested so it's only performed once
+    Command     mCommand = INITIAL;       // current command
+    int32_t*    mColdFutexAddr = nullptr; // for COLD_IDLE only, pointer to the associated futex
+    unsigned    mColdGen = 0;             // increment when COLD_IDLE is requested
+                                          // so it's only performed once
 
     // This might be a one-time configuration rather than per-state
-    FastThreadDumpState* mDumpState; // if non-NULL, then update dump state periodically
-    NBLog::Writer* mNBLogWriter; // non-blocking logger
+    FastThreadDumpState* mDumpState = nullptr; // if non-NULL, then update dump state periodically
+    NBLog::Writer* mNBLogWriter = nullptr; // non-blocking logger
 
     // returns NULL if command belongs to a subclass
     static const char *commandToString(Command command);
diff --git a/services/audioflinger/fastpath/StateQueue.cpp b/services/audioflinger/fastpath/StateQueue.cpp
index 62c00be..e896d29 100644
--- a/services/audioflinger/fastpath/StateQueue.cpp
+++ b/services/audioflinger/fastpath/StateQueue.cpp
@@ -38,19 +38,6 @@
 }
 #endif
 
-// Constructor and destructor
-
-template<typename T> StateQueue<T>::StateQueue() :
-    mAck(nullptr), mCurrent(nullptr),
-    mMutating(&mStates[0]), mExpecting(nullptr),
-    mInMutation(false), mIsDirty(false), mIsInitialized(false)
-#ifdef STATE_QUEUE_DUMP
-    , mObserverDump(&mObserverDummyDump), mMutatorDump(&mMutatorDummyDump)
-#endif
-{
-    atomic_init(&mNext, static_cast<uintptr_t>(0));
-}
-
 // Observer APIs
 
 template<typename T> const T* StateQueue<T>::poll()
diff --git a/services/audioflinger/fastpath/StateQueue.h b/services/audioflinger/fastpath/StateQueue.h
index dff8f3f..29d1809 100644
--- a/services/audioflinger/fastpath/StateQueue.h
+++ b/services/audioflinger/fastpath/StateQueue.h
@@ -126,7 +126,6 @@
 template<typename T> class StateQueue {
 
 public:
-            StateQueue();
     virtual ~StateQueue() = default;  // why is this virtual?
 
     // Observer APIs
@@ -187,24 +186,27 @@
     T                 mStates[kN];      // written by mutator, read by observer
 
     // "volatile" is meaningless with SMP, but here it indicates that we're using atomic ops
-    atomic_uintptr_t  mNext; // written by mutator to advance next, read by observer
-    volatile const T* mAck;  // written by observer to acknowledge advance of next, read by mutator
+    atomic_uintptr_t  mNext{}; // written by mutator to advance next, read by observer
+    volatile const T* mAck = nullptr;  // written by observer to acknowledge advance of next,
+                                       // read by mutator
 
     // only used by observer
-    const T*          mCurrent;         // most recent value returned by poll()
+    const T*    mCurrent = nullptr;     // most recent value returned by poll()
 
     // only used by mutator
-    T*                mMutating;        // where updates by mutator are done in place
-    const T*          mExpecting;       // what the mutator expects mAck to be set to
-    bool              mInMutation;      // whether we're currently in the middle of a mutation
-    bool              mIsDirty;         // whether mutating state has been modified since last push
-    bool              mIsInitialized;   // whether mutating state has been initialized yet
+    T*          mMutating{&mStates[0]}; // where updates by mutator are done in place
+    const T*    mExpecting = nullptr;   // what the mutator expects mAck to be set to
+    bool        mInMutation = false;    // whether we're currently in the middle of a mutation
+    bool        mIsDirty = false;       // whether mutating state has been modified since last push
+    bool        mIsInitialized = false; // whether mutating state has been initialized yet
 
 #ifdef STATE_QUEUE_DUMP
     StateQueueObserverDump  mObserverDummyDump; // default area for observer dump if not set
-    StateQueueObserverDump* mObserverDump;      // pointer to active observer dump, always non-NULL
+    // pointer to active observer dump, always non-nullptr
+    StateQueueObserverDump* mObserverDump{&mObserverDummyDump};
     StateQueueMutatorDump   mMutatorDummyDump;  // default area for mutator dump if not set
-    StateQueueMutatorDump*  mMutatorDump;       // pointer to active mutator dump, always non-NULL
+    // pointer to active mutator dump, always non-nullptr
+    StateQueueMutatorDump*  mMutatorDump{&mMutatorDummyDump};
 #endif
 
 };  // class StateQueue