summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-09-20 09:20:45 -0700
committerGlenn Kasten <gkasten@google.com>2013-09-20 12:22:29 -0700
commit5a6cd224d07c05b496b6aca050ce5ecf96f125af (patch)
treec5d2fe55f0080c9660d283d040616d9a9fb6decc /include
parenta3b97ad288e6808c54c6275eaac1bd53108d8f11 (diff)
downloadframeworks_av-5a6cd224d07c05b496b6aca050ce5ecf96f125af.zip
frameworks_av-5a6cd224d07c05b496b6aca050ce5ecf96f125af.tar.gz
frameworks_av-5a6cd224d07c05b496b6aca050ce5ecf96f125af.tar.bz2
Fix slow AudioTrack and AudioRecord destruction
There were two causes for the slowness: When thread was paused, it used nanosleep and sleep. These usually run to completion (except for POSIX signal, which we avoid because it is low-level). Instead, replace the nanosleep and sleep by condition timed wait, as that can be made to return early by a condition signal. Another advantage of condition timed wait is that a condition wait was already being used at top of thread loop, so it is a simpler change. The AudioRecord destructor was missing a proxy interrupt that was correct in AudioTrack. This proxy interrupt is needed in case another thread is blocked in proxy obtainBuffer. Does not address the 1 second polling for NS_WHENEVER. Bug: 10822765 Change-Id: Id665994551e87e4d7da9c7b015f424fd7a0b5560
Diffstat (limited to 'include')
-rw-r--r--include/media/AudioRecord.h10
-rw-r--r--include/media/AudioTrack.h10
2 files changed, 12 insertions, 8 deletions
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index 62f0c64..052064d 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -398,18 +398,20 @@ private:
void pause(); // suspend thread from execution at next loop boundary
void resume(); // allow thread to execute, if not requested to exit
- void pauseConditional();
- // like pause(), but only if prior resume() wasn't latched
private:
+ void pauseInternal(nsecs_t ns = 0LL);
+ // like pause(), but only used internally within thread
+
friend class AudioRecord;
virtual bool threadLoop();
AudioRecord& mReceiver;
virtual ~AudioRecordThread();
Mutex mMyLock; // Thread::mLock is private
Condition mMyCond; // Thread::mThreadExitedCondition is private
- bool mPaused; // whether thread is currently paused
- bool mResumeLatch; // whether next pauseConditional() will be a nop
+ bool mPaused; // whether thread is requested to pause at next loop entry
+ bool mPausedInt; // whether thread internally requests pause
+ nsecs_t mPausedNs; // if mPausedInt then associated timeout, otherwise ignored
};
// body of AudioRecordThread::threadLoop()
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 453c106..22ad57e 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -598,18 +598,20 @@ protected:
void pause(); // suspend thread from execution at next loop boundary
void resume(); // allow thread to execute, if not requested to exit
- void pauseConditional();
- // like pause(), but only if prior resume() wasn't latched
private:
+ void pauseInternal(nsecs_t ns = 0LL);
+ // like pause(), but only used internally within thread
+
friend class AudioTrack;
virtual bool threadLoop();
AudioTrack& mReceiver;
virtual ~AudioTrackThread();
Mutex mMyLock; // Thread::mLock is private
Condition mMyCond; // Thread::mThreadExitedCondition is private
- bool mPaused; // whether thread is currently paused
- bool mResumeLatch; // whether next pauseConditional() will be a nop
+ bool mPaused; // whether thread is requested to pause at next loop entry
+ bool mPausedInt; // whether thread internally requests pause
+ nsecs_t mPausedNs; // if mPausedInt then associated timeout, otherwise ignored
};
// body of AudioTrackThread::threadLoop()