From edde45f5ccc67fddd1d3d2972efe74b0a12e4178 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Fri, 30 Aug 2024 15:57:39 +0800 Subject: [PATCH] 修复channelMap可能导致的崩溃 --- src/decoder/dvpp/DvppSourceManager.cpp | 16 +++++++++------- src/decoder/dvpp/DvppSourceManager.h | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/decoder/dvpp/DvppSourceManager.cpp b/src/decoder/dvpp/DvppSourceManager.cpp index 405d90f..ffbf593 100644 --- a/src/decoder/dvpp/DvppSourceManager.cpp +++ b/src/decoder/dvpp/DvppSourceManager.cpp @@ -7,18 +7,19 @@ using namespace std; DvppSourceManager::~DvppSourceManager() { - channelMap.clear(); + m_channelMap.clear(); // aclFinalize(); } int DvppSourceManager::getChannel(int devId){ + std::lock_guard l(m_channelMap_mtx); // channel 最大值暂定为32, 华为没有接口获取最大channel,只有文档说明 for(int iChannel = 0; iChannel < 32; iChannel++){ string channelKey = "channel_" + to_string(devId) + "_" + to_string(iChannel) ; - auto it = channelMap.find(channelKey); - if(it == channelMap.end()){ - channelMap[channelKey] = iChannel; + auto it = m_channelMap.find(channelKey); + if(it == m_channelMap.end()){ + m_channelMap[channelKey] = iChannel; return iChannel; } } @@ -26,9 +27,10 @@ int DvppSourceManager::getChannel(int devId){ } void DvppSourceManager::releaseChannel(int devId, int iChannel){ + std::lock_guard l(m_channelMap_mtx); string channelKey = "channel_" + to_string(devId) + "_" + to_string(iChannel) ; - auto it = channelMap.find(channelKey); - if(it != channelMap.end()){ - channelMap.erase(channelKey); + auto it = m_channelMap.find(channelKey); + if(it != m_channelMap.end()){ + m_channelMap.erase(channelKey); } } \ No newline at end of file diff --git a/src/decoder/dvpp/DvppSourceManager.h b/src/decoder/dvpp/DvppSourceManager.h index 9679f16..dc3c1a9 100644 --- a/src/decoder/dvpp/DvppSourceManager.h +++ b/src/decoder/dvpp/DvppSourceManager.h @@ -24,5 +24,6 @@ private: ~DvppSourceManager(); private: - map channelMap; + map m_channelMap; + mutex m_channelMap_mtx; }; \ No newline at end of file -- libgit2 0.21.4