[lldb] Make StatsDuration thread-safe
authorPavel Labath <pavel@labath.sk>
Mon, 17 Jan 2022 14:04:30 +0000 (15:04 +0100)
committerPavel Labath <pavel@labath.sk>
Wed, 19 Jan 2022 15:42:53 +0000 (16:42 +0100)
commit4f89157b9d73711a7ce20b597f93eb17a3133adf
tree6f4612e48222b42294a0908e68679ed9dea4f8d7
parente35c8f541cfab0747429063f6b5acf47cff17b6d
[lldb] Make StatsDuration thread-safe

std::chrono::duration types are not thread-safe, and they cannot be
concurrently updated from multiple threads. Currently, we were doing
such a thing (only) in the DWARF indexing code
(DWARFUnit::ExtractDIEsRWLocked), but I think it can easily happen that
someone else tries to update another statistic like this without
bothering to check for thread safety.

This patch changes the StatsDuration type from a simple typedef into a
class in its own right. The class stores the duration internally as
std::atomic<uint64_t> (so it can be updated atomically), but presents it
to its users as the usual chrono type (duration<float>).

Differential Revision: https://reviews.llvm.org/D117474
lldb/include/lldb/Breakpoint/Breakpoint.h
lldb/include/lldb/Core/Module.h
lldb/include/lldb/Symbol/SymbolFile.h
lldb/include/lldb/Target/Statistics.h
lldb/source/Breakpoint/Breakpoint.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
lldb/source/Target/Statistics.cpp