[compiler-rt] f5808fc - [sanitizer] Use atomic_fetch_add instead of load/store
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed May 24 16:22:52 PDT 2023
Author: Vitaly Buka
Date: 2023-05-24T16:22:36-07:00
New Revision: f5808fc19711bddcb25918ed3224cdcaad4f9865
URL: https://github.com/llvm/llvm-project/commit/f5808fc19711bddcb25918ed3224cdcaad4f9865
DIFF: https://github.com/llvm/llvm-project/commit/f5808fc19711bddcb25918ed3224cdcaad4f9865.diff
LOG: [sanitizer] Use atomic_fetch_add instead of load/store
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_allocator_stats.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_stats.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_stats.h
index 5b671fb9f253..ae4dac9c8c96 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_stats.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_stats.h
@@ -25,17 +25,13 @@ typedef uptr AllocatorStatCounters[AllocatorStatCount];
// Per-thread stats, live in per-thread cache.
class AllocatorStats {
public:
- void Init() {
- internal_memset(this, 0, sizeof(*this));
- }
+ void Init() { internal_memset(this, 0, sizeof(*this)); }
void Add(AllocatorStat i, uptr v) {
- v += atomic_load(&stats_[i], memory_order_relaxed);
- atomic_store(&stats_[i], v, memory_order_relaxed);
+ atomic_fetch_add(&stats_[i], v, memory_order_relaxed);
}
void Sub(AllocatorStat i, uptr v) {
- v = atomic_load(&stats_[i], memory_order_relaxed) - v;
- atomic_store(&stats_[i], v, memory_order_relaxed);
+ atomic_fetch_sub(&stats_[i], v, memory_order_relaxed);
}
void Set(AllocatorStat i, uptr v) {
More information about the llvm-commits
mailing list