Skip to content

Commit

Permalink
OnceCallbackHolder: Swap has_run_ to std::atomic
Browse files Browse the repository at this point in the history
has_run_ is a flag used to check that a callback is only run once.
Convert from Atomic32 to std::atomic<bool> - 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 <lizeb@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Venkatesh Srinivas <venkateshs@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1119089}
  • Loading branch information
vsrinivas authored and Chromium LUCI CQ committed Mar 19, 2023
1 parent 3483e5e commit 99db1f9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/functional/callback_helpers.h
Expand Up @@ -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.";
Expand All @@ -90,7 +90,7 @@ class OnceCallbackHolder final {
}

private:
volatile subtle::Atomic32 has_run_ = 0;
std::atomic<bool> has_run_;
base::OnceCallback<void(Args...)> callback_;
const bool ignore_extra_runs_;
};
Expand Down

0 comments on commit 99db1f9

Please sign in to comment.