summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2010-11-16 14:41:34 -0800
committerEric Laurent <elaurent@google.com>2010-11-16 18:53:46 -0800
commitfbe5f5cb1752b74c97918c2c764cc997fac00472 (patch)
treee2b6220e14e1473856c036af456b155940507c47
parent4955afc4d96eee4de050df7e6f3e8ee389f279bc (diff)
downloaddevice_samsung_crespo-fbe5f5cb1752b74c97918c2c764cc997fac00472.zip
device_samsung_crespo-fbe5f5cb1752b74c97918c2c764cc997fac00472.tar.gz
device_samsung_crespo-fbe5f5cb1752b74c97918c2c764cc997fac00472.tar.bz2
Fix issue 3201189
The issue comes from the fact that acquiring a mutex can take upto several seconds if the acquisition is attempted by a low priority thread and a high priority thread is frequently acquiring and releasing the same mutex. This happens when setMode() tries to lock the output stream mutex while playback is active. The fix is more a workaround consisting in boosting the priority of the thread executing setMode() until the mutex is acquired. Change-Id: I0921c215759dcd86d6ffb03669b5f94691878ffb
-rw-r--r--libaudio2/AudioHardware.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/libaudio2/AudioHardware.cpp b/libaudio2/AudioHardware.cpp
index 3755e23..10409a1 100644
--- a/libaudio2/AudioHardware.cpp
+++ b/libaudio2/AudioHardware.cpp
@@ -28,6 +28,7 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/resource.h>
#include <dlfcn.h>
#include <fcntl.h>
@@ -311,8 +312,13 @@ status_t AudioHardware::setMode(int mode)
sp<AudioStreamInALSA> spIn;
status_t status;
+ // bump thread priority to speed up mutex acquisition
+ int priority = getpriority(PRIO_PROCESS, 0);
+ setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_URGENT_AUDIO);
+
// Mutex acquisition order is always out -> in -> hw
AutoMutex lock(mLock);
+
spOut = mOutput;
while (spOut != 0) {
if (!spOut->checkStandby()) {
@@ -349,6 +355,8 @@ status_t AudioHardware::setMode(int mode)
}
// spIn is not 0 here only if the input is active
+ setpriority(PRIO_PROCESS, 0, priority);
+
int prevMode = mMode;
status = AudioHardwareBase::setMode(mode);
LOGV("setMode() : new %d, old %d", mMode, prevMode);