summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBo Hu <bohu@google.com>2015-03-27 17:11:59 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-03-27 17:11:59 +0000
commitf5e45945e2f1d1e061add56ea39d00a07f7c16f8 (patch)
treeeed37db2655bdb5058f8cd4d806b907de702e398
parent9af76c29413fb56887f74ef5a6969b0f90741a8d (diff)
parent8e39c79622b79f4b5faf53123acefa5c5bda5eed (diff)
downloadandroid_device_generic_goldfish-f5e45945e2f1d1e061add56ea39d00a07f7c16f8.tar.gz
android_device_generic_goldfish-f5e45945e2f1d1e061add56ea39d00a07f7c16f8.tar.bz2
android_device_generic_goldfish-f5e45945e2f1d1e061add56ea39d00a07f7c16f8.zip
am 8e39c796: am dbfa611b: Merge "Fix inconsistant results for some cts tests."
* commit '8e39c79622b79f4b5faf53123acefa5c5bda5eed': Fix inconsistant results for some cts tests.
-rwxr-xr-xcamera/EmulatedCameraDevice.cpp20
-rwxr-xr-xcamera/EmulatedCameraDevice.h2
2 files changed, 20 insertions, 2 deletions
diff --git a/camera/EmulatedCameraDevice.cpp b/camera/EmulatedCameraDevice.cpp
index b76353d..c8e5640 100755
--- a/camera/EmulatedCameraDevice.cpp
+++ b/camera/EmulatedCameraDevice.cpp
@@ -291,16 +291,21 @@ status_t EmulatedCameraDevice::WorkerThread::readyToRun()
"%s: Thread control FDs are opened", __FUNCTION__);
/* Create a pair of FDs that would be used to control the thread. */
int thread_fds[2];
+ status_t ret;
+ Mutex::Autolock lock(mCameraDevice->mObjectLock);
if (pipe(thread_fds) == 0) {
mThreadControl = thread_fds[1];
mControlFD = thread_fds[0];
ALOGV("Emulated device's worker thread has been started.");
- return NO_ERROR;
+ ret = NO_ERROR;
} else {
ALOGE("%s: Unable to create thread control FDs: %d -> %s",
__FUNCTION__, errno, strerror(errno));
- return errno;
+ ret = errno;
}
+
+ mSetup.signal();
+ return ret;
}
status_t EmulatedCameraDevice::WorkerThread::stopThread()
@@ -308,6 +313,17 @@ status_t EmulatedCameraDevice::WorkerThread::stopThread()
ALOGV("Stopping emulated camera device's worker thread...");
status_t res = EINVAL;
+
+ // Limit the scope of the Autolock
+ {
+ // If thread is running and readyToRun() has not finished running,
+ // then wait until it is done.
+ Mutex::Autolock lock(mCameraDevice->mObjectLock);
+ if (isRunning() && (mThreadControl < 0 || mControlFD < 0)) {
+ mSetup.wait(mCameraDevice->mObjectLock);
+ }
+ }
+
if (mThreadControl >= 0) {
/* Send "stop" message to the thread loop. */
const ControlMessage msg = THREAD_STOP;
diff --git a/camera/EmulatedCameraDevice.h b/camera/EmulatedCameraDevice.h
index b7cdcb7..ee9f7dd 100755
--- a/camera/EmulatedCameraDevice.h
+++ b/camera/EmulatedCameraDevice.h
@@ -467,6 +467,8 @@ protected:
/* Stop the thread. */
THREAD_STOP
};
+
+ Condition mSetup;
};
/* Worker thread accessor. */