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

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

Issue 2187333002: Loosen/improve AtomicFlag semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: side-effects 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
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 #include "base/synchronization/atomic_flag.h" 5 #include "base/synchronization/atomic_flag.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 AtomicFlag::AtomicFlag() = default; 11 AtomicFlag::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 }
12 18
13 void AtomicFlag::Set() { 19 void AtomicFlag::Set() {
14 DCHECK(thread_checker_.CalledOnValidThread()); 20 DCHECK(set_sequence_checker_.CalledOnValidSequencedThread());
15 base::subtle::Release_Store(&flag_, 1); 21 base::subtle::Release_Store(&flag_, 1);
16 } 22 }
17 23
18 bool AtomicFlag::IsSet() const { 24 bool AtomicFlag::IsSet() const {
19 return base::subtle::Acquire_Load(&flag_) != 0; 25 return base::subtle::Acquire_Load(&flag_) != 0;
20 } 26 }
21 27
22 void AtomicFlag::UnsafeResetForTesting() { 28 void AtomicFlag::UnsafeReset() {
23 base::subtle::Release_Store(&flag_, 0); 29 base::subtle::Release_Store(&flag_, 0);
30 set_sequence_checker_.DetachFromSequence();
24 } 31 }
25 32
26 } // namespace base 33 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698