| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_ | |
| 6 #define COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_ | |
| 7 | |
| 8 #include "base/atomicops.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 11 | |
| 12 // A PollableThreadSafeFlag can be polled without requiring a lock, but can only | |
| 13 // be updated if a lock is held. This enables lock-free checking as to whether a | |
| 14 // condition has changed, while protecting operations which update the condition | |
| 15 // with a lock. You must ensure that the flag is only updated within the same | |
| 16 // lock-protected critical section as any other variables on which the condition | |
| 17 // depends. | |
| 18 class PollableThreadSafeFlag { | |
| 19 public: | |
| 20 explicit PollableThreadSafeFlag(base::Lock* write_lock); | |
| 21 ~PollableThreadSafeFlag(); | |
| 22 | |
| 23 // Set the flag. May only be called if |write_lock| is held. | |
| 24 void SetWhileLocked(bool value); | |
| 25 | |
| 26 // Returns true iff the flag is set to true. | |
| 27 bool IsSet() const; | |
| 28 | |
| 29 private: | |
| 30 base::subtle::Atomic32 flag_; | |
| 31 base::Lock* write_lock_; // Not owned. | |
| 32 | |
| 33 DISALLOW_COPY_AND_ASSIGN(PollableThreadSafeFlag); | |
| 34 }; | |
| 35 | |
| 36 #endif // COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_ | |
| OLD | NEW |