From bb05604b8de9bed83d937148a056eba256dd9e2b Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Mon, 13 Jul 2009 19:29:25 +0800 Subject: [PATCH] Fix 1956740: startPreview failed The problem is even after release() is done, the singleton variable is not cleared, so a new openCameraHardware() call could return an instance which is already released. The singleton variable is cleared in the destructor, so we wait until that happens in openCameraHardware(). --- libcamera2/QualcommCameraHardware.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libcamera2/QualcommCameraHardware.cpp b/libcamera2/QualcommCameraHardware.cpp index 9a3555b..1679133 100644 --- a/libcamera2/QualcommCameraHardware.cpp +++ b/libcamera2/QualcommCameraHardware.cpp @@ -225,6 +225,8 @@ static inline unsigned clp2(unsigned x) namespace android { static Mutex singleton_lock; +static bool singleton_releasing; +static Condition singleton_wait; static void receive_camframe_callback(struct msm_frame *frame); static void receive_jpeg_fragment_callback(uint8_t *buff_ptr, uint32_t buff_size); @@ -993,6 +995,9 @@ void QualcommCameraHardware::release() } #endif + Mutex::Autolock lock(&singleton_lock); + singleton_releasing = true; + LOGD("release X"); } @@ -1001,6 +1006,8 @@ QualcommCameraHardware::~QualcommCameraHardware() LOGD("~QualcommCameraHardware E"); Mutex::Autolock lock(&singleton_lock); singleton.clear(); + singleton_releasing = false; + singleton_wait.signal(); LOGD("~QualcommCameraHardware X"); } @@ -1435,6 +1442,13 @@ sp QualcommCameraHardware::createInstance() LOGD("createInstance: E"); Mutex::Autolock lock(&singleton_lock); + + // Wait until the previous release is done. + while (singleton_releasing) { + LOGD("Wait for previous release."); + singleton_wait.wait(singleton_lock); + } + if (singleton != 0) { sp hardware = singleton.promote(); if (hardware != 0) {