Skip to content

Commit e20ab38

Browse files
committed
Unlock effect chains in the middle of two if's
As part of the upcoming threadLoop() merge, this CL makes it clearer what are the similar and different parts before and after unlocking effect chains. In each threadLoop(), the old code was: if (sleepTime == 0) { // A unlockEffectChains(effectChains); // B } else { unlockEffectChains(effectChains); // C } The new code is: if (sleepTime == 0) { // A } unlockEffectChains(effectChains); if (sleepTime == 0) { // B } else { // C } Also this is slightly slower by one "if", it has the advantage of making it much more obvious about what is done before and after the unlock, and also to see the similarities and differences among the various copies of threadLoop(). Change-Id: I7bf4369d2dcb072573ec43b7e52c637f0097dc00
1 parent be3835c commit e20ab38

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,13 +2111,19 @@ bool AudioFlinger::MixerThread::threadLoop()
21112111
if (mSuspended) {
21122112
sleepTime = suspendSleepTimeUs();
21132113
}
2114-
// sleepTime == 0 means we must write to audio hardware
2114+
2115+
// only process effects if we're going to write
21152116
if (sleepTime == 0) {
21162117
for (size_t i = 0; i < effectChains.size(); i ++) {
21172118
effectChains[i]->process_l();
21182119
}
2119-
// enable changes in effect chain
2120-
unlockEffectChains(effectChains);
2120+
}
2121+
2122+
// enable changes in effect chain
2123+
unlockEffectChains(effectChains);
2124+
2125+
// sleepTime == 0 means we must write to audio hardware
2126+
if (sleepTime == 0) {
21212127
mLastWriteTime = systemTime();
21222128
mInWrite = true;
21232129
mBytesWritten += mixBufferSize;
@@ -2141,8 +2147,6 @@ bool AudioFlinger::MixerThread::threadLoop()
21412147
}
21422148
mStandby = false;
21432149
} else {
2144-
// enable changes in effect chain
2145-
unlockEffectChains(effectChains);
21462150
usleep(sleepTime);
21472151
}
21482152

@@ -2920,16 +2924,22 @@ bool AudioFlinger::DirectOutputThread::threadLoop()
29202924
if (mSuspended) {
29212925
sleepTime = suspendSleepTimeUs();
29222926
}
2923-
// sleepTime == 0 means we must write to audio hardware
2927+
2928+
// only process effects if we're going to write
29242929
if (sleepTime == 0) {
29252930
if (mixerStatus == MIXER_TRACKS_READY) {
29262931
applyVolume(leftVol, rightVol, rampVolume);
29272932
}
29282933
for (size_t i = 0; i < effectChains.size(); i ++) {
29292934
effectChains[i]->process_l();
29302935
}
2931-
unlockEffectChains(effectChains);
2936+
}
29322937

2938+
// enable changes in effect chain
2939+
unlockEffectChains(effectChains);
2940+
2941+
// sleepTime == 0 means we must write to audio hardware
2942+
if (sleepTime == 0) {
29332943
mLastWriteTime = systemTime();
29342944
mInWrite = true;
29352945
mBytesWritten += mixBufferSize;
@@ -2939,7 +2949,6 @@ bool AudioFlinger::DirectOutputThread::threadLoop()
29392949
mInWrite = false;
29402950
mStandby = false;
29412951
} else {
2942-
unlockEffectChains(effectChains);
29432952
usleep(sleepTime);
29442953
}
29452954

@@ -3191,23 +3200,26 @@ bool AudioFlinger::DuplicatingThread::threadLoop()
31913200
if (mSuspended) {
31923201
sleepTime = suspendSleepTimeUs();
31933202
}
3194-
// sleepTime == 0 means we must write to audio hardware
3203+
3204+
// only process effects if we're going to write
31953205
if (sleepTime == 0) {
31963206
for (size_t i = 0; i < effectChains.size(); i ++) {
31973207
effectChains[i]->process_l();
31983208
}
3199-
// enable changes in effect chain
3200-
unlockEffectChains(effectChains);
3209+
}
3210+
3211+
// enable changes in effect chain
3212+
unlockEffectChains(effectChains);
32013213

3214+
// sleepTime == 0 means we must write to audio hardware
3215+
if (sleepTime == 0) {
32023216
standbyTime = systemTime() + mStandbyTimeInNsecs;
32033217
for (size_t i = 0; i < outputTracks.size(); i++) {
32043218
outputTracks[i]->write(mMixBuffer, writeFrames);
32053219
}
32063220
mStandby = false;
32073221
mBytesWritten += mixBufferSize;
32083222
} else {
3209-
// enable changes in effect chain
3210-
unlockEffectChains(effectChains);
32113223
usleep(sleepTime);
32123224
}
32133225

0 commit comments

Comments
 (0)