Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: base/synchronization/atomic_flag.h

Issue 2187333002: Loosen/improve AtomicFlag semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile post merge Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/synchronization/atomic_flag.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ 5 #ifndef BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_
6 #define BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ 6 #define BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_
7 7
8 #include "base/atomicops.h" 8 #include "base/atomicops.h"
9 #include "base/base_export.h" 9 #include "base/base_export.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/threading/thread_checker.h" 11 #include "base/sequence_checker.h"
12 12
13 namespace base { 13 namespace base {
14 14
15 // A flag that can safely be set from one thread and read from other threads. 15 // A flag that can safely be set from one thread and read from other threads.
16 // 16 //
17 // This class IS NOT intended for synchronization between threads. 17 // This class IS NOT intended for synchronization between threads.
18 class BASE_EXPORT AtomicFlag { 18 class BASE_EXPORT AtomicFlag {
19 public: 19 public:
20 AtomicFlag(); 20 AtomicFlag();
21 ~AtomicFlag() = default; 21 ~AtomicFlag() = default;
22 22
23 // Set the flag. May only be called on the thread which created the object. 23 // Set the flag. Must always be called from the same sequence.
24 void Set(); 24 void Set();
25 25
26 // Returns true iff the flag was set. 26 // Returns true iff the flag was set. If this returns true, the current thread
27 // is guaranteed to be synchronized with all memory operations on the sequence
28 // which invoked Set() up until at least the first call to Set() on it.
27 bool IsSet() const; 29 bool IsSet() const;
28 30
29 // Resets the flag. Be careful when using this: callers might not expect 31 // Resets the flag. Be careful when using this: callers might not expect
30 // IsSet() to return false after returning true once. 32 // IsSet() to return false after returning true once.
31 void UnsafeResetForTesting(); 33 void UnsafeResetForTesting();
32 34
33 private: 35 private:
34 base::subtle::Atomic32 flag_ = 0; 36 base::subtle::Atomic32 flag_ = 0;
35 ThreadChecker thread_checker_; 37 SequenceChecker set_sequence_checker_;
36 38
37 DISALLOW_COPY_AND_ASSIGN(AtomicFlag); 39 DISALLOW_COPY_AND_ASSIGN(AtomicFlag);
38 }; 40 };
39 41
40 } // namespace base 42 } // namespace base
41 43
42 #endif // BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_ 44 #endif // BASE_SYNCHRONIZATION_ATOMIC_FLAG_H_
OLDNEW
« no previous file with comments | « no previous file | base/synchronization/atomic_flag.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698