3 ** Copyright 2008, The Android Open Source Project
4 ** Copyright 2012, Samsung Electronics Co. LTD
6 ** Licensed under the Apache License, Version 2.0 (the "License");
7 ** you may not use this file except in compliance with the License.
8 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
20 * \file SignalDrivenThread.cpp
21 * \brief source file for general thread ( for camera hal2 implementation )
22 * \author Sungjoong Kang(sj3.kang@samsung.com)
25 * <b>Revision History: </b>
26 * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n
29 * - 2012/07/10 : Sungjoong Kang(sj3.kang@samsung.com) \n
34 //#define LOG_NDEBUG 0
35 #define LOG_TAG "SignalDrivenThread"
36 #include <utils/Log.h>
38 #include "SignalDrivenThread.h"
43 SignalDrivenThread::SignalDrivenThread()
46 ALOGV("DEBUG(SignalDrivenThread() ):");
47 m_processingSignal
= 0;
51 void SignalDrivenThread::Start(const char* name
,
52 int32_t priority
, size_t stack
)
54 ALOGV("DEBUG(SignalDrivenThread::Start() ):");
55 run(name
, priority
, stack
);
57 SignalDrivenThread::SignalDrivenThread(const char* name
,
58 int32_t priority
, size_t stack
)
61 ALOGV("DEBUG(SignalDrivenThread( , , )):");
62 m_processingSignal
= 0;
64 run(name
, priority
, stack
);
68 SignalDrivenThread::~SignalDrivenThread()
70 ALOGV("DEBUG(%s):", __FUNCTION__
);
74 status_t
SignalDrivenThread::SetSignal(uint32_t signal
)
76 ALOGV("DEBUG(%s):Setting Signal (%x)", __FUNCTION__
, signal
);
78 Mutex::Autolock
lock(m_signalMutex
);
79 ALOGV("DEBUG(%s):Signal Set (%x) - prev(%x)", __FUNCTION__
, signal
, m_receivedSignal
);
80 m_receivedSignal
|= signal
;
81 m_threadCondition
.signal();
85 uint32_t SignalDrivenThread::GetProcessingSignal()
87 ALOGV("DEBUG(%s): Signal (%x)", __FUNCTION__
, m_processingSignal
);
89 return m_processingSignal
;
93 void SignalDrivenThread::ClearProcessingSignal(uint32_t signal)
95 ALOGV("DEBUG(%s):Clearing Signal (%x) from (%x)", __func__, signal, m_processingSignal);
97 m_processingSignal &= ~(signal);
102 status_t
SignalDrivenThread::readyToRun()
104 ALOGV("DEBUG(%s):", __func__
);
105 return readyToRunInternal();
109 bool SignalDrivenThread::threadLoop()
112 Mutex::Autolock
lock(m_signalMutex
);
113 ALOGV("DEBUG(%s):Waiting Signal", __FUNCTION__
);
114 while (!m_receivedSignal
)
116 m_threadCondition
.wait(m_signalMutex
);
118 m_processingSignal
= m_receivedSignal
;
119 m_receivedSignal
= 0;
121 ALOGV("DEBUG(%s):Got Signal (%x)", __FUNCTION__
, m_processingSignal
);
123 if (m_processingSignal
& SIGNAL_THREAD_TERMINATE
)
125 ALOGV("DEBUG(%s):Thread Terminating", __FUNCTION__
);
128 else if (m_processingSignal
& SIGNAL_THREAD_PAUSE
)
130 ALOGV("DEBUG(%s):Thread Paused", __FUNCTION__
);
134 threadFunctionInternal();
139 }; // namespace android