1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/synchronization/atomic_flag.h"
6 
7 #include "base/check_op.h"
8 
9 namespace base {
10 
AtomicFlag()11 AtomicFlag::AtomicFlag() {
12   // It doesn't matter where the AtomicFlag is built so long as it's always
13   // Set() from the same sequence after. Note: the sequencing requirements are
14   // necessary for IsSet()'s callers to know which sequence's memory operations
15   // they are synchronized with.
16   DETACH_FROM_SEQUENCE(set_sequence_checker_);
17 }
18 
19 AtomicFlag::~AtomicFlag() = default;
20 
Set()21 void AtomicFlag::Set() {
22   DCHECK_CALLED_ON_VALID_SEQUENCE(set_sequence_checker_);
23   flag_.store(1, std::memory_order_release);
24 }
25 
UnsafeResetForTesting()26 void AtomicFlag::UnsafeResetForTesting() {
27   DETACH_FROM_SEQUENCE(set_sequence_checker_);
28   flag_.store(0, std::memory_order_release);
29 }
30 
31 }  // namespace base
32