diff options
author | Zhijun He <zhijunhe@google.com> | 2013-10-11 16:21:11 -0700 |
---|---|---|
committer | Zhijun He <zhijunhe@google.com> | 2013-10-11 16:48:16 -0700 |
commit | 15ad2470b2f2ac34473eb568b606ad75e8e63ac6 (patch) | |
tree | 7b1785a6c1c284fc345e5e1d9722ea87432f8491 | |
parent | d5ed2263a485d6e633fe08f033d04fad75daec6f (diff) | |
download | frameworks_av-15ad2470b2f2ac34473eb568b606ad75e8e63ac6.zip frameworks_av-15ad2470b2f2ac34473eb568b606ad75e8e63ac6.tar.gz frameworks_av-15ad2470b2f2ac34473eb568b606ad75e8e63ac6.tar.bz2 |
Camera: Fix deadlock in Camera3OutputStream
process capture request thread, process capture result and setParameter
binder threads can run into circular locking situation when acquiring
StreamingProcessor lock, Camera3Stream lock, and bufferQueue lock.
Releasing the Camera3Stream lock briefly in process capture request
thread getbuffer call can break this deadlock.
Bug: 11016037
Change-Id: If08d4b134c26be26039b1d5363759e60f911bad6
-rw-r--r-- | services/camera/libcameraservice/device3/Camera3OutputStream.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp index 41328fc..682755d 100644 --- a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp +++ b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp @@ -92,7 +92,22 @@ status_t Camera3OutputStream::getBufferLocked(camera3_stream_buffer *buffer) { ANativeWindowBuffer* anb; int fenceFd; - res = mConsumer->dequeueBuffer(mConsumer.get(), &anb, &fenceFd); + /** + * Release the lock briefly to avoid deadlock for below scenario: + * Thread 1: StreamingProcessor::startStream -> Camera3Stream::isConfiguring(). + * This thread acquired StreamingProcessor lock and try to lock Camera3Stream lock. + * Thread 2: Camera3Stream::returnBuffer->StreamingProcessor::onFrameAvailable(). + * This thread acquired Camera3Stream lock and bufferQueue lock, and try to lock + * StreamingProcessor lock. + * Thread 3: Camera3Stream::getBuffer(). This thread acquired Camera3Stream lock + * and try to lock bufferQueue lock. + * Then there is circular locking dependency. + */ + sp<ANativeWindow> currentConsumer = mConsumer; + mLock.unlock(); + + res = currentConsumer->dequeueBuffer(currentConsumer.get(), &anb, &fenceFd); + mLock.lock(); if (res != OK) { ALOGE("%s: Stream %d: Can't dequeue next output buffer: %s (%d)", __FUNCTION__, mId, strerror(-res), res); |