diff --git a/src/profiler/profile-generator.h b/src/profiler/profile-generator.h index 38b3c713de6..20ce4bf54b9 100644 --- a/src/profiler/profile-generator.h +++ b/src/profiler/profile-generator.h @@ -237,8 +237,10 @@ class CodeEntry { size_t DecRef() { DCHECK(is_ref_counted()); DCHECK_GT(ref_count_, 0UL); - ref_count_--; - return ref_count_; + // Use the return value of the atomic RMW directly. The previous code did + // `ref_count_--; return ref_count_;` which is two separate atomic ops and + // allows two concurrent callers from refcount=2 to both observe 0. + return ref_count_.fetch_sub(1, std::memory_order_acq_rel) - 1; } using EventField = base::BitField;