Chromium Code Reviews| Index: base/synchronization/atomic_flag.h |
| diff --git a/base/synchronization/atomic_flag.h b/base/synchronization/atomic_flag.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..07bf38b3e6d0c221e9586fb84bf75ee309d6cdc1 |
| --- /dev/null |
| +++ b/base/synchronization/atomic_flag.h |
| @@ -0,0 +1,43 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ |
| +#define BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ |
| + |
| +#include "base/atomicops.h" |
| +#include "base/base_export.h" |
| +#include "base/macros.h" |
| +#include "base/threading/thread_checker.h" |
| + |
| +namespace base { |
| + |
| +// A flag that can safely be set from one thread and read from other threads. |
| +// |
| +// This class IS NOT intended for synchronization between threads. |
| +class BASE_EXPORT AtomicFlag { |
| + public: |
| + AtomicFlag(); |
| + ~AtomicFlag() = default; |
| + |
| + // Set the flag. May only be called on the thread which created the object. |
| + void Set(); |
| + |
| + // Returns true iff the flag was set. |
| + bool IsSet() const; |
| + |
| + // For subtle reasons that may be different on different architectures, a |
| + // different thread testing IsSet() may erroneously read 'true' after this |
|
danakj
2016/07/20 19:21:01
Really? But it's using Release_Store. Is this stil
fdoray
2016/07/21 13:08:33
Talked with the author of https://codereview.chrom
|
| + // method has been called. |
| + void UnsafeResetForTesting(); |
| + |
| + private: |
| + base::subtle::Atomic32 flag_ = false; |
| + ThreadChecker thread_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AtomicFlag); |
| +}; |
| + |
| +} // namespace base |
| + |
| +#endif // BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ |