From 99db1f9b40f722ee75dfc0f798c3b46b83b831cb Mon Sep 17 00:00:00 2001 From: Venkatesh Srinivas Date: Sun, 19 Mar 2023 06:33:07 +0000 Subject: [PATCH] OnceCallbackHolder: Swap has_run_ to std::atomic has_run_ is a flag used to check that a callback is only run once. Convert from Atomic32 to std::atomic - they are broadly supported, do not implicitly convert to/from integers, and we are converting code to use them. No behavior change expected. Bug: 1194917 Change-Id: I1fca86f5cfb88e5a591f6f1af9b9dc5271ef4472 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4320832 Reviewed-by: Benoit Lize Reviewed-by: danakj Commit-Queue: Venkatesh Srinivas Cr-Commit-Position: refs/heads/main@{#1119089} --- base/functional/callback_helpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/functional/callback_helpers.h b/base/functional/callback_helpers.h index 19d605162f11a..8bb763638e14d 100644 --- a/base/functional/callback_helpers.h +++ b/base/functional/callback_helpers.h @@ -79,7 +79,7 @@ class OnceCallbackHolder final { OnceCallbackHolder& operator=(const OnceCallbackHolder&) = delete; void Run(Args... args) { - if (subtle::NoBarrier_AtomicExchange(&has_run_, 1)) { + if (has_run_.exchange(true, std::memory_order_relaxed)) { CHECK(ignore_extra_runs_) << "Both OnceCallbacks returned by " "base::SplitOnceCallback() were run. " "At most one of the pair should be run."; @@ -90,7 +90,7 @@ class OnceCallbackHolder final { } private: - volatile subtle::Atomic32 has_run_ = 0; + std::atomic has_run_; base::OnceCallback callback_; const bool ignore_extra_runs_; };