diff options
author | Daniel Sanders <daniel_l_sanders@apple.com> | 2018-03-06 21:16:42 +0000 |
---|---|---|
committer | Daniel Sanders <daniel_l_sanders@apple.com> | 2018-03-06 21:16:42 +0000 |
commit | 0f4b015268a5df4d95933761d3b999e09454fa3b (patch) | |
tree | 40ae3b6d8cb1eaa18c187ca0460de43d0cdbcf37 /llvm/lib/Support/Statistic.cpp | |
parent | 7dc51375811299e1f37b82703e6c54e8361c91a5 (diff) | |
download | bcm5719-llvm-0f4b015268a5df4d95933761d3b999e09454fa3b.tar.gz bcm5719-llvm-0f4b015268a5df4d95933761d3b999e09454fa3b.zip |
PrintStatistics() and PrintStatisticsJSON() should take StatLock
These two functions iterate over the list of statistics but don't take the lock
that protects the iterators from being invalidated by
StatisticInfo::addStatistic().
So far, this hasn't been an issue since (in-tree at least) these functions are
called by the StatisticInfo destructor so addStatistic() shouldn't be called
anymore. However, we do expose them in the public API.
Note that this only protects against iterator invalidation and does not protect
against ordering issues caused by statistic updates that race with
PrintStatistics()/PrintStatisticsJSON().
Thanks to Roman Tereshin for spotting it
llvm-svn: 326834
Diffstat (limited to 'llvm/lib/Support/Statistic.cpp')
-rw-r--r-- | llvm/lib/Support/Statistic.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp index 67b07162b9a..1985409f35c 100644 --- a/llvm/lib/Support/Statistic.cpp +++ b/llvm/lib/Support/Statistic.cpp @@ -166,6 +166,7 @@ void llvm::PrintStatistics(raw_ostream &OS) { } void llvm::PrintStatisticsJSON(raw_ostream &OS) { + sys::SmartScopedLock<true> Reader(*StatLock); StatisticInfo &Stats = *StatInfo; Stats.sort(); @@ -192,6 +193,7 @@ void llvm::PrintStatisticsJSON(raw_ostream &OS) { void llvm::PrintStatistics() { #if LLVM_ENABLE_STATS + sys::SmartScopedLock<true> Reader(*StatLock); StatisticInfo &Stats = *StatInfo; // Statistics not enabled? |