OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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_ATOMIC_FLAG_H_ |
| 6 #define BASE_ATOMIC_FLAG_H_ |
| 7 |
| 8 #include "base/atomicops.h" |
| 9 |
| 10 namespace base { |
| 11 |
| 12 // AtomicFlag allows threads to notify each other for a single occurrence |
| 13 // of a single event. It maintains an abstract boolean "flag" that transitions |
| 14 // to true at most once. It provides calls to query the boolean. |
| 15 // |
| 16 // Memory ordering: For any threads X and Y, if X calls Set(), then any |
| 17 // action taken by X before it calls Set() is visible to thread Y after |
| 18 // Y receives a true return value from IsSet(). |
| 19 class AtomicFlag { |
| 20 public: |
| 21 // Sets "flag_" to "initial_value". |
| 22 explicit AtomicFlag(bool initial_value = false) |
| 23 : flag_(initial_value ? 1 : 0) { } |
| 24 ~AtomicFlag() {} |
| 25 |
| 26 void Set(); // Set "flag_" to true. May be called only once. |
| 27 bool IsSet() const; // Return "flag_". |
| 28 |
| 29 private: |
| 30 base::subtle::Atomic32 flag_; |
| 31 |
| 32 DISALLOW_COPY_AND_ASSIGN(AtomicFlag); |
| 33 }; |
| 34 |
| 35 } // namespace base |
| 36 |
| 37 #endif // BASE_ATOMIC_FLAG_H_ |
OLD | NEW |