diff options
author | Eric Laurent <elaurent@google.com> | 2013-09-06 13:33:01 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-09-06 13:33:01 -0700 |
commit | bfc4214079875f0dc8c349e8c475d1813c234e67 (patch) | |
tree | 7f8695357953e7d7c143c262f14645406f724e2d /services/audioflinger/Threads.h | |
parent | 0f096cfb8b478e2035bbdc0efb0322103b1f392e (diff) | |
parent | 99b84e8b013a6e0b926693067b00e82cfbe2ca4f (diff) | |
download | frameworks_av-bfc4214079875f0dc8c349e8c475d1813c234e67.zip frameworks_av-bfc4214079875f0dc8c349e8c475d1813c234e67.tar.gz frameworks_av-bfc4214079875f0dc8c349e8c475d1813c234e67.tar.bz2 |
am 99b84e8b: am 3b4529e0: audioflinger: remove async write race conditions
* commit '99b84e8b013a6e0b926693067b00e82cfbe2ca4f':
audioflinger: remove async write race conditions
Diffstat (limited to 'services/audioflinger/Threads.h')
-rw-r--r-- | services/audioflinger/Threads.h | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h index 15278ce..7999436 100644 --- a/services/audioflinger/Threads.h +++ b/services/audioflinger/Threads.h @@ -380,9 +380,9 @@ protected: void removeTracks_l(const Vector< sp<Track> >& tracksToRemove); void writeCallback(); - void setWriteBlocked(bool value); + void resetWriteBlocked(uint32_t sequence); void drainCallback(); - void setDraining(bool value); + void resetDraining(uint32_t sequence); static int asyncCallback(stream_callback_event_t event, void *param, void *cookie); @@ -579,8 +579,19 @@ private: size_t mBytesRemaining; size_t mCurrentWriteLength; bool mUseAsyncWrite; - bool mWriteBlocked; - bool mDraining; + // mWriteAckSequence contains current write sequence on bits 31-1. The write sequence is + // incremented each time a write(), a flush() or a standby() occurs. + // Bit 0 is set when a write blocks and indicates a callback is expected. + // Bit 0 is reset by the async callback thread calling resetWriteBlocked(). Out of sequence + // callbacks are ignored. + uint32_t mWriteAckSequence; + // mDrainSequence contains current drain sequence on bits 31-1. The drain sequence is + // incremented each time a drain is requested or a flush() or standby() occurs. + // Bit 0 is set when the drain() command is called at the HAL and indicates a callback is + // expected. + // Bit 0 is reset by the async callback thread calling resetDraining(). Out of sequence + // callbacks are ignored. + uint32_t mDrainSequence; bool mSignalPending; sp<AsyncCallbackThread> mCallbackThread; @@ -757,13 +768,21 @@ public: virtual void onFirstRef(); void exit(); - void setWriteBlocked(bool value); - void setDraining(bool value); + void setWriteBlocked(uint32_t sequence); + void resetWriteBlocked(); + void setDraining(uint32_t sequence); + void resetDraining(); private: wp<OffloadThread> mOffloadThread; - bool mWriteBlocked; - bool mDraining; + // mWriteAckSequence corresponds to the last write sequence passed by the offload thread via + // setWriteBlocked(). The sequence is shifted one bit to the left and the lsb is used + // to indicate that the callback has been received via resetWriteBlocked() + uint32_t mWriteAckSequence; + // mDrainSequence corresponds to the last drain sequence passed by the offload thread via + // setDraining(). The sequence is shifted one bit to the left and the lsb is used + // to indicate that the callback has been received via resetDraining() + uint32_t mDrainSequence; Condition mWaitWorkCV; Mutex mLock; }; |