From 609bc02b21c725825bd469391e9ecd4e2d462fe1 Mon Sep 17 00:00:00 2001 From: Tyler Luu Date: Wed, 14 Mar 2012 23:37:20 -0500 Subject: camera: prevent possible deadlock scenario Hold scope of returnFrame lock for just the calculation of refCount. Otherwise, we could have a scenario where endImageCapture and stopRecording could cause a deadlock competing for mReturnFrameLock and mLock. Issue arises mainly because endImageCapture is signalled from fillThisBuffer which stopRecording will need to get into. Make sure mEventQ has a message before calling get() since read on the pipe will block with notifyEvent holding mLock. Change-Id: I3a125711632fa311fd794e300cd5008321a84c40 Signed-off-by: Tyler Luu --- camera/AppCallbackNotifier.cpp | 8 ++++++-- camera/BaseCameraAdapter.cpp | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'camera') diff --git a/camera/AppCallbackNotifier.cpp b/camera/AppCallbackNotifier.cpp index 77b0556..aa41141 100644 --- a/camera/AppCallbackNotifier.cpp +++ b/camera/AppCallbackNotifier.cpp @@ -311,8 +311,12 @@ void AppCallbackNotifier::notifyEvent() TIUTILS::Message msg; LOG_FUNCTION_NAME; { - Mutex::Autolock lock(mLock); - mEventQ.get(&msg); + Mutex::Autolock lock(mLock); + if(!mEventQ.isEmpty()) { + mEventQ.get(&msg); + } else { + return; + } } bool ret = true; CameraHalEvent *evt = NULL; diff --git a/camera/BaseCameraAdapter.cpp b/camera/BaseCameraAdapter.cpp index 69291af..ec75232 100644 --- a/camera/BaseCameraAdapter.cpp +++ b/camera/BaseCameraAdapter.cpp @@ -258,8 +258,6 @@ void BaseCameraAdapter::returnFrame(void* frameBuf, CameraFrame::FrameType frame size_t subscriberCount = 0; int refCount = -1; - Mutex::Autolock lock(mReturnFrameLock); - if ( NULL == frameBuf ) { CAMHAL_LOGEA("Invalid frameBuf"); @@ -268,6 +266,7 @@ void BaseCameraAdapter::returnFrame(void* frameBuf, CameraFrame::FrameType frame if ( NO_ERROR == res) { + Mutex::Autolock lock(mReturnFrameLock); refCount = getFrameRefCount(frameBuf, frameType); -- cgit v1.1