add lock for allocAddrMap

Signed-off-by: zyxzyx <zhangyixin19@huawei.com>
This commit is contained in:
zyxzyx 2024-02-08 16:54:40 +08:00
parent 99ed570da6
commit 4f15046395
2 changed files with 4 additions and 0 deletions

View File

@ -160,6 +160,7 @@ private:
int32_t pid_ {-1};
std::mutex mtx_;
bool isSaService_{false};
std::mutex mtex_;
};
#endif // STACK_PREPROCESS_H

View File

@ -696,6 +696,7 @@ void StackPreprocess::SetHookData(RawStackPtr rawStack,
inline bool StackPreprocess::SetFreeStatisticsData(uint64_t addr)
{
// through the addr lookup record
std::lock_guard<std::mutex> guard(mtex_);
auto addrIter = allocAddrMap_.find(addr);
if (addrIter != allocAddrMap_.end()) {
auto& record = addrIter->second.second;
@ -717,6 +718,7 @@ inline void StackPreprocess::SetAllocStatisticsData(const RawStackPtr& rawStack,
auto& record = recordIter->second;
++record.applyCount;
record.applySize += rawStack->stackConext->mallocSize;
std::lock_guard<std::mutex> guard(mtex_);
allocAddrMap_[(uint64_t)rawStack->stackConext->addr] =
std::pair(rawStack->stackConext->mallocSize, &recordIter->second);
statisticsPeriodData_[stackId] = &recordIter->second;
@ -752,6 +754,7 @@ inline void StackPreprocess::SetAllocStatisticsData(const RawStackPtr& rawStack,
}
auto [recordIter, stat] = recordStatisticsMap_.emplace(stackId, record);
std::lock_guard<std::mutex> guard(mtex_);
allocAddrMap_[(uint64_t)rawStack->stackConext->addr] =
std::pair(rawStack->stackConext->mallocSize, &recordIter->second);
statisticsPeriodData_[stackId] = &recordIter->second;