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/logging.h" 8 9 namespace base { 10 AtomicFlag()11AtomicFlag::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 set_sequence_checker_.DetachFromSequence(); 17 } 18 Set()19void AtomicFlag::Set() { 20 DCHECK(set_sequence_checker_.CalledOnValidSequence()); 21 base::subtle::Release_Store(&flag_, 1); 22 } 23 IsSet() const24bool AtomicFlag::IsSet() const { 25 return base::subtle::Acquire_Load(&flag_) != 0; 26 } 27 UnsafeResetForTesting()28void AtomicFlag::UnsafeResetForTesting() { 29 base::subtle::Release_Store(&flag_, 0); 30 } 31 32 } // namespace base 33