From 1264ab1629accf444d13831e209eafe4657d7664 Mon Sep 17 00:00:00 2001 From: Alex Ray Date: Mon, 8 Apr 2013 17:44:06 -0700 Subject: [PATCH] libcamera2: Protect in-flight counts. Protect numEntries accesses with numEntriesLock. Protect jpegEncoder accesses with jpegEncoderLock. Bug: 8058308 Change-Id: Idc31172d7d154ae2051e9eab94dadcf8f6cdddd3 --- libcamera2/ExynosCameraHWInterface2.cpp | 31 ++++++++++++++++++++----- libcamera2/ExynosCameraHWInterface2.h | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/libcamera2/ExynosCameraHWInterface2.cpp b/libcamera2/ExynosCameraHWInterface2.cpp index 8f4f5cd..b372c8c 100644 --- a/libcamera2/ExynosCameraHWInterface2.cpp +++ b/libcamera2/ExynosCameraHWInterface2.cpp @@ -309,6 +309,7 @@ RequestManager::~RequestManager() void RequestManager::ResetEntry() { Mutex::Autolock lock(m_requestMutex); + Mutex::Autolock lock2(m_numOfEntriesLock); for (int i=0 ; i=NUM_MAX_REQUEST_MGR_ENTRY) return true; else @@ -343,6 +346,7 @@ void RequestManager::RegisterRequest(camera_metadata_t * new_request, int * afMo ALOGV("DEBUG(%s):", __FUNCTION__); Mutex::Autolock lock(m_requestMutex); + Mutex::Autolock lock2(m_numOfEntriesLock); request_manager_entry * newEntry = NULL; int newInsertionIndex = GetNextIndex(m_entryInsertionIndex); @@ -386,6 +390,7 @@ void RequestManager::DeregisterRequest(camera_metadata_t ** deregistered_request request_manager_entry * currentEntry; Mutex::Autolock lock(m_requestMutex); + Mutex::Autolock lock2(m_numOfEntriesLock); frame_index = GetCompletedIndex(); currentEntry = &(entries[frame_index]); @@ -454,6 +459,7 @@ int RequestManager::MarkProcessingRequest(ExynosBuffer* buf) static int count = 0; Mutex::Autolock lock(m_requestMutex); + Mutex::Autolock lock2(m_numOfEntriesLock); if (m_numOfEntries == 0) { CAM_LOGD("DEBUG(%s): Request Manager Empty ", __FUNCTION__); return -1; @@ -899,6 +905,7 @@ void RequestManager::Dump(void) { int i = 0; request_manager_entry * currentEntry; + Mutex::Autolock lock(m_numOfEntriesLock); ALOGD("## Dump totalentry(%d), insert(%d), processing(%d), frame(%d)", m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex); @@ -1623,10 +1630,17 @@ int ExynosCameraHWInterface2::setFrameQueueDstOps(const camera2_frame_queue_dst_ int ExynosCameraHWInterface2::getInProgressCount() { - int inProgressCount = m_requestManager->GetNumEntries(); + int inProgressJpeg; + int inProgressCount; + + { + Mutex::Autolock lock(m_jpegEncoderLock); + inProgressJpeg = m_jpegEncodingCount; + inProgressCount = m_requestManager->GetNumEntries(); + } ALOGV("DEBUG(%s): # of dequeued req (%d) jpeg(%d) = (%d)", __FUNCTION__, - inProgressCount, m_jpegEncodingCount, (inProgressCount + m_jpegEncodingCount)); - return (inProgressCount + m_jpegEncodingCount); + inProgressCount, inProgressJpeg, (inProgressCount + inProgressJpeg)); + return (inProgressCount + inProgressJpeg); } int ExynosCameraHWInterface2::flushCapturesInProgress() @@ -4129,7 +4143,6 @@ void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self) } int ExynosCameraHWInterface2::m_jpegCreator(StreamThread *selfThread, ExynosBuffer *srcImageBuf, nsecs_t frameTimeStamp) { - Mutex::Autolock lock(m_jpegEncoderLock); stream_parameters_t *selfStreamParms = &(selfThread->m_parameters); substream_parameters_t *subParms = &m_subStreams[STREAM_ID_JPEG]; status_t res; @@ -4161,7 +4174,10 @@ int ExynosCameraHWInterface2::m_jpegCreator(StreamThread *selfThread, ExynosBuff return 1; } - m_jpegEncodingCount++; + { + Mutex::Autolock lock(m_jpegEncoderLock); + m_jpegEncodingCount++; + } m_getRatioSize(selfStreamParms->width, selfStreamParms->height, m_streamThreads[0]->m_parameters.width, m_streamThreads[0]->m_parameters.height, @@ -4325,7 +4341,10 @@ int ExynosCameraHWInterface2::m_jpegCreator(StreamThread *selfThread, ExynosBuff subParms->svcBufIndex, subParms->svcBufStatus[subParms->svcBufIndex]); } } - m_jpegEncodingCount--; + { + Mutex::Autolock lock(m_jpegEncoderLock); + m_jpegEncodingCount--; + } return 0; } diff --git a/libcamera2/ExynosCameraHWInterface2.h b/libcamera2/ExynosCameraHWInterface2.h index 027322f..b54d77a 100644 --- a/libcamera2/ExynosCameraHWInterface2.h +++ b/libcamera2/ExynosCameraHWInterface2.h @@ -315,6 +315,7 @@ private: MetadataConverter *m_metadataConverter; SignalDrivenThread *m_mainThread; + Mutex m_numOfEntriesLock; int m_numOfEntries; int m_entryInsertionIndex; int m_entryProcessingIndex; -- 2.20.1