Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 661c21da authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

CameraService: Disconnect: Release mutex while waiting for joins.

The threads shutting down may have callpaths that require taking the
binder interface mutex, so waiting to join them with that mutex held
can lead to deadlocks.

A specific instance is StreamingProcessor calling dataCallbackTimestamp,
which can immediately lead to a Camera2Client::releaseRecordingFrame call,
which requires the binder interface mutex. If this call happens right when
shutdown is occurring, and Camera2Client::disconnect is holding the mutex,
deadlock ensues.

Bug: 17997578
Change-Id: I71253cd5542b5920ad205976d315110ca0043d94
parent 168799c3
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -419,6 +419,11 @@ void Camera2Client::disconnect() {

    ALOGV("Camera %d: Waiting for threads", mCameraId);

    {
        // Don't wait with lock held, in case the other threads need to
        // complete callbacks that re-enter Camera2Client
        mBinderSerializationLock.unlock();

        mStreamingProcessor->join();
        mFrameProcessor->join();
        mCaptureSequencer->join();
@@ -426,6 +431,9 @@ void Camera2Client::disconnect() {
        mZslProcessorThread->join();
        mCallbackProcessor->join();

        mBinderSerializationLock.lock();
    }

    ALOGV("Camera %d: Deleting streams", mCameraId);

    mStreamingProcessor->deletePreviewStream();