hardware: samsung_slsi: libcamera2: Modify thread creators
authorSungjoong Kang <sj3.kang@samsung.com>
Tue, 18 Sep 2012 00:46:52 +0000 (17:46 -0700)
committerRebecca Schultz Zavin <rebecca@android.com>
Tue, 18 Sep 2012 20:25:59 +0000 (13:25 -0700)
This patch resolves the crash with pure virtual functions
on changing modes.
Thread creators are modified not to call run function.

Change-Id: Ib4864aaf46852583d742a8f36001ef93b0504e07
Signed-off-by: Sungjoong Kang <sj3.kang@samsung.com>
libcamera2/ExynosCameraHWInterface2.cpp
libcamera2/ExynosCameraHWInterface2.h
libcamera2/SignalDrivenThread.cpp
libcamera2/SignalDrivenThread.h

index 81b041b01f0f131403a8fdb843e0ba77f48edec0..a0a5529c7ca376a5915de87c877dbcfa20494de7 100644 (file)
@@ -945,6 +945,7 @@ ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_
     } else {
         m_sensorThread  = new SensorThread(this);
         m_mainThread->Start("MainThread", PRIORITY_DEFAULT, 0);
+        m_sensorThread->Start("SensorThread", PRIORITY_DEFAULT, 0);
         ALOGV("DEBUG(%s): created sensorthread ", __FUNCTION__);
 
         for (int i = 0 ; i < STREAM_ID_LAST+1 ; i++)
@@ -1289,6 +1290,7 @@ void ExynosCameraHWInterface2::StartSCCThread(bool threadExists)
     }
     AllocatedStream = (StreamThread*)(m_streamThreads[1].get());
     if (!threadExists) {
+        AllocatedStream->Start("StreamThread", PRIORITY_DEFAULT, 0);
         m_streamThreadInitialize((SignalDrivenThread*)AllocatedStream);
         AllocatedStream->m_numRegisteredStream = 1;
     }
@@ -1599,6 +1601,7 @@ int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, in
             m_streamThreads[0]  = new StreamThread(this, *stream_id);
 
             AllocatedStream = (StreamThread*)(m_streamThreads[0].get());
+            AllocatedStream->Start("StreamThread", PRIORITY_DEFAULT, 0);
             m_streamThreadInitialize((SignalDrivenThread*)AllocatedStream);
 
             *format_actual                      = HAL_PIXEL_FORMAT_EXYNOS_YV12;
@@ -1687,10 +1690,9 @@ int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, in
         if (useDirectOutput) {
             *stream_id = STREAM_ID_ZSL;
 
-            /*if (createThread)*/ {
-                m_streamThreads[1]  = new StreamThread(this, *stream_id);
-            }
+            m_streamThreads[1]  = new StreamThread(this, *stream_id);
             AllocatedStream = (StreamThread*)(m_streamThreads[1].get());
+            AllocatedStream->Start("StreamThread", PRIORITY_DEFAULT, 0);
             m_streamThreadInitialize((SignalDrivenThread*)AllocatedStream);
 
             *format_actual                      = HAL_PIXEL_FORMAT_EXYNOS_YV12;
@@ -2610,14 +2612,6 @@ void ExynosCameraHWInterface2::m_mainThreadFunc(SignalDrivenThread * self)
     return;
 }
 
-void ExynosCameraHWInterface2::m_sensorThreadInitialize(SignalDrivenThread * self)
-{
-    ALOGV("DEBUG(%s): ", __FUNCTION__ );
-    /* will add */
-    return;
-}
-
-
 void ExynosCameraHWInterface2::DumpInfoWithShot(struct camera2_shot_ext * shot_ext)
 {
     ALOGD("####  common Section");
@@ -5743,9 +5737,9 @@ static int HAL2_camera_device_close(struct hw_device_t* device)
         ALOGV("cam_device(0x%08x):", (unsigned int)cam_device);
         ALOGV("g_cam2_device(0x%08x):", (unsigned int)g_cam2_device);
         delete static_cast<ExynosCameraHWInterface2 *>(cam_device->priv);
-        g_cam2_device = NULL;
         free(cam_device);
         g_camera_vaild = false;
+        g_cam2_device = NULL;
     }
 
     ALOGD("(%s): EXIT", __FUNCTION__);
index f66516d27704668ced047618152a23e22aecc7a0..ca25297689b4b37bc25e207e7009ba6aa79c7927 100644 (file)
@@ -467,16 +467,10 @@ class MainThread : public SignalDrivenThread {
     public:
         MainThread(ExynosCameraHWInterface2 *hw):
             SignalDrivenThread(),
-            mHardware(hw) {
-//            Start("MainThread", PRIORITY_DEFAULT, 0);
-        }
+            mHardware(hw) { }
         ~MainThread();
-        status_t readyToRunInternal()
-       {
-            return NO_ERROR;
-        }
         void threadFunctionInternal()
-       {
+           {
             mHardware->m_mainThreadFunc(this);
             return;
         }
@@ -488,13 +482,9 @@ class MainThread : public SignalDrivenThread {
         ExynosCameraHWInterface2 *mHardware;
     public:
         SensorThread(ExynosCameraHWInterface2 *hw):
-            SignalDrivenThread("SensorThread", PRIORITY_DEFAULT, 0),
+            SignalDrivenThread(),
             mHardware(hw) { }
         ~SensorThread();
-        status_t readyToRunInternal() {
-            mHardware->m_sensorThreadInitialize(this);
-            return NO_ERROR;
-        }
         void threadFunctionInternal() {
             mHardware->m_sensorThreadFunc(this);
             return;
@@ -508,13 +498,10 @@ class MainThread : public SignalDrivenThread {
         ExynosCameraHWInterface2 *mHardware;
     public:
         StreamThread(ExynosCameraHWInterface2 *hw, uint8_t new_index):
-            SignalDrivenThread("StreamThread", PRIORITY_DEFAULT, 0),
+            SignalDrivenThread(),
             mHardware(hw),
             m_index(new_index) { }
         ~StreamThread();
-        status_t readyToRunInternal() {
-            return NO_ERROR;
-        }
         void threadFunctionInternal() {
             mHardware->m_streamThreadFunc(this);
             return;
@@ -551,7 +538,6 @@ class MainThread : public SignalDrivenThread {
 
     void                m_mainThreadFunc(SignalDrivenThread * self);
     void                m_sensorThreadFunc(SignalDrivenThread * self);
-    void                m_sensorThreadInitialize(SignalDrivenThread * self);
     void                m_streamThreadFunc(SignalDrivenThread * self);
     void                m_streamThreadInitialize(SignalDrivenThread * self);
 
index b510d8d7912144010a768db00ac34c3c88c217f5..8c491a280cbea0a9b4c86eef4fad7b2726f0e28f 100644 (file)
@@ -104,6 +104,11 @@ status_t SignalDrivenThread::readyToRun()
     return readyToRunInternal();
 }
 
+status_t SignalDrivenThread::readyToRunInternal()
+{
+    ALOGV("DEBUG(%s):", __func__);
+    return NO_ERROR;
+}
 
 bool SignalDrivenThread::threadLoop()
 {
index a6d58e5658582f2714677a7728a5be0a548107ec..87d54aa76263586f8a982ff8d0fdf3f9383f4905 100644 (file)
@@ -1,82 +1,82 @@
-/*\r
-**\r
-** Copyright 2008, The Android Open Source Project\r
-** Copyright 2012, Samsung Electronics Co. LTD\r
-**\r
-** Licensed under the Apache License, Version 2.0 (the "License");\r
-** you may not use this file except in compliance with the License.\r
-** You may obtain a copy of the License at\r
-**\r
-**     http://www.apache.org/licenses/LICENSE-2.0\r
-**\r
-** Unless required by applicable law or agreed to in writing, software\r
-** distributed under the License is distributed on an "AS IS" BASIS,\r
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-** See the License for the specific language governing permissions and\r
-** limitations under the License.\r
-*/\r
-\r
-/*!\r
- * \file      SignalDrivenThread.h\r
- * \brief     header file for general thread ( for camera hal2 implementation )\r
- * \author    Sungjoong Kang(sj3.kang@samsung.com)\r
- * \date      2012/05/31\r
- *\r
- * <b>Revision History: </b>\r
- * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n\r
- *   Initial Release\r
- *\r
- * - 2012/07/10 : Sungjoong Kang(sj3.kang@samsung.com) \n\r
- *   2nd Release\r
- *\r
- */\r
-\r
-\r
-\r
-#ifndef SIGNAL_DRIVEN_THREAD_H\r
-#define SIGNAL_DRIVEN_THREAD_H\r
-\r
-#include <utils/threads.h>\r
-\r
-namespace android {\r
-\r
-#define SIGNAL_THREAD_TERMINATE     (1<<0)\r
-#define SIGNAL_THREAD_PAUSE         (1<<1)\r
-\r
-#define SIGNAL_THREAD_COMMON_LAST   (1<<3)\r
-\r
-class SignalDrivenThread:public Thread {\r
-public:\r
-                        SignalDrivenThread();\r
-                        SignalDrivenThread(const char *name,\r
-                            int32_t priority, size_t stack);\r
-    virtual             ~SignalDrivenThread();\r
-\r
-            status_t    SetSignal(uint32_t signal);\r
-\r
-            uint32_t    GetProcessingSignal();\r
-            //void        ClearProcessingSignal(uint32_t signal);\r
-            void        Start(const char *name,\r
-                            int32_t priority, size_t stack);\r
-            bool        IsTerminated();\r
-\r
-private:\r
-            status_t    readyToRun();\r
-    virtual status_t    readyToRunInternal() = 0;\r
-\r
-            bool        threadLoop();\r
-    virtual void        threadFunctionInternal() = 0;\r
-\r
-            void        ClearSignal();\r
-\r
-            uint32_t    m_receivedSignal;\r
-            uint32_t    m_processingSignal;\r
-\r
-            Mutex       m_signalMutex;\r
-            Condition   m_threadCondition;\r
-            bool           m_isTerminated;\r
-};\r
-\r
-}; // namespace android\r
-\r
-#endif\r
+/*
+**
+** Copyright 2008, The Android Open Source Project
+** Copyright 2012, Samsung Electronics Co. LTD
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+/*!
+ * \file      SignalDrivenThread.h
+ * \brief     header file for general thread ( for camera hal2 implementation )
+ * \author    Sungjoong Kang(sj3.kang@samsung.com)
+ * \date      2012/05/31
+ *
+ * <b>Revision History: </b>
+ * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n
+ *   Initial Release
+ *
+ * - 2012/07/10 : Sungjoong Kang(sj3.kang@samsung.com) \n
+ *   2nd Release
+ *
+ */
+
+
+
+#ifndef SIGNAL_DRIVEN_THREAD_H
+#define SIGNAL_DRIVEN_THREAD_H
+
+#include <utils/threads.h>
+
+namespace android {
+
+#define SIGNAL_THREAD_TERMINATE     (1<<0)
+#define SIGNAL_THREAD_PAUSE         (1<<1)
+
+#define SIGNAL_THREAD_COMMON_LAST   (1<<3)
+
+class SignalDrivenThread:public Thread {
+public:
+                        SignalDrivenThread();
+                        SignalDrivenThread(const char *name,
+                            int32_t priority, size_t stack);
+    virtual             ~SignalDrivenThread();
+
+            status_t    SetSignal(uint32_t signal);
+
+            uint32_t    GetProcessingSignal();
+            //void        ClearProcessingSignal(uint32_t signal);
+            void        Start(const char *name,
+                            int32_t priority, size_t stack);
+            bool        IsTerminated();
+
+private:
+            status_t    readyToRun();
+            status_t    readyToRunInternal();
+
+            bool        threadLoop();
+    virtual void        threadFunctionInternal() = 0;
+
+            void        ClearSignal();
+
+            uint32_t    m_receivedSignal;
+            uint32_t    m_processingSignal;
+
+            Mutex       m_signalMutex;
+            Condition   m_threadCondition;
+            bool           m_isTerminated;
+};
+
+}; // namespace android
+
+#endif