// used to verify we've read at least once before evaluating how many bytes were read
bool readOnce = false;
+ // used to request a deferred sleep, to be executed later while mutex is unlocked
+ bool doSleep = false;
+
// start recording
for (;;) {
sp<RecordTrack> activeTrack;
Vector< sp<EffectChain> > effectChains;
+ // sleep with mutex unlocked
+ if (doSleep) {
+ doSleep = false;
+ usleep(kRecordThreadSleepUs);
+ }
+
{ // scope for mLock
Mutex::Autolock _l(mLock);
if (exitPending()) {
if (activeTrack->mState != TrackBase::ACTIVE &&
activeTrack->mState != TrackBase::RESUMING) {
unlockEffectChains(effectChains);
- usleep(kRecordThreadSleepUs);
+ doSleep = true;
continue;
}
for (size_t i = 0; i < effectChains.size(); i ++) {
// Force input into standby so that it tries to
// recover at next read attempt
inputStandBy();
- // FIXME sleep with effect chains locked
- usleep(kRecordThreadSleepUs);
+ doSleep = true;
}
mRsmpInIndex = mFrameCount;
framesOut = 0;
// Release the processor for a while before asking for a new buffer.
// This will give the application more chance to read from the buffer and
// clear the overflow.
- // FIXME sleep with effect chains locked
- usleep(kRecordThreadSleepUs);
+ doSleep = true;
}
// enable changes in effect chain
// Force input into standby so that it tries to
// recover at next read attempt
inputStandBy();
+ // FIXME an awkward place to sleep, consider using doSleep when this is pulled up
usleep(kRecordThreadSleepUs);
}
buffer->raw = NULL;