From 4f771a5130960cf3f6550069e1c8510a31ffb12b Mon Sep 17 00:00:00 2001 From: Honggyu Kim Date: Fri, 22 Nov 2019 10:44:26 +0900 Subject: [PATCH] stacktrace: Change std::mutex to std::recursive_mutex In general, std::recursive_mutex is safer than std::mutex by preventing from unintended locking with the same mutex variable. Signed-off-by: Honggyu Kim --- stacktrace.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stacktrace.cc b/stacktrace.cc index 5c10967..59a74ff 100644 --- a/stacktrace.cc +++ b/stacktrace.cc @@ -29,13 +29,13 @@ std::map stackmap; std::map addrmap; -std::mutex container_mutex; +std::recursive_mutex container_mutex; // record_backtrace() is defined in stacktrace.h as an inline function. void __record_backtrace(size_t size, void* addr, stack_trace_t& stack_trace, int nptrs) { - std::lock_guard lock(container_mutex); + std::lock_guard lock(container_mutex); pr_dbg(" record_backtrace(%zd, %p)\n", size, addr); @@ -64,7 +64,7 @@ void release_backtrace(void* addr) if (unlikely(!addr)) return; - std::lock_guard lock(container_mutex); + std::lock_guard lock(container_mutex); pr_dbg(" release_backtrace(%p)\n", addr); @@ -340,7 +340,7 @@ void dump_stackmap(enum alloc_sort_order order, bool flamegraph) std::vector> sorted_stack; { // protect stackmap access - std::lock_guard lock(container_mutex); + std::lock_guard lock(container_mutex); for (auto& p : stackmap) sorted_stack.push_back(make_pair(p.first, p.second));