atomic_flag.cc 936 B

12345678910111213141516171819202122232425262728293031
  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. #include "base/synchronization/atomic_flag.h"
  5. #include "base/check_op.h"
  6. namespace base {
  7. AtomicFlag::AtomicFlag() {
  8. // It doesn't matter where the AtomicFlag is built so long as it's always
  9. // Set() from the same sequence after. Note: the sequencing requirements are
  10. // necessary for IsSet()'s callers to know which sequence's memory operations
  11. // they are synchronized with.
  12. DETACH_FROM_SEQUENCE(set_sequence_checker_);
  13. }
  14. AtomicFlag::~AtomicFlag() = default;
  15. void AtomicFlag::Set() {
  16. DCHECK_CALLED_ON_VALID_SEQUENCE(set_sequence_checker_);
  17. flag_.store(1, std::memory_order_release);
  18. }
  19. void AtomicFlag::UnsafeResetForTesting() {
  20. DETACH_FROM_SEQUENCE(set_sequence_checker_);
  21. flag_.store(0, std::memory_order_release);
  22. }
  23. } // namespace base