OLD | NEW |
---|---|
(Empty) | |
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 #ifndef BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ | |
6 #define BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ | |
7 | |
8 #include "base/atomicops.h" | |
9 #include "base/base_export.h" | |
10 #include "base/macros.h" | |
11 #include "base/threading/thread_checker.h" | |
12 | |
13 namespace base { | |
14 | |
15 // A flag that can safely be set from one thread and read from other threads. | |
16 // | |
17 // This class IS NOT intended for synchronization between threads. | |
18 class BASE_EXPORT AtomicFlag { | |
19 public: | |
20 AtomicFlag(); | |
21 ~AtomicFlag() = default; | |
22 | |
23 // Set the flag. May only be called on the thread which created the object. | |
24 void Set(); | |
25 | |
26 // Returns true iff the flag was set. | |
27 bool IsSet() const; | |
28 | |
29 // For subtle reasons that may be different on different architectures, a | |
30 // 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
| |
31 // method has been called. | |
32 void UnsafeResetForTesting(); | |
33 | |
34 private: | |
35 base::subtle::Atomic32 flag_ = false; | |
36 ThreadChecker thread_checker_; | |
37 | |
38 DISALLOW_COPY_AND_ASSIGN(AtomicFlag); | |
39 }; | |
40 | |
41 } // namespace base | |
42 | |
43 #endif // BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ | |
OLD | NEW |