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

Side by Side Diff: components/scheduler/base/pollable_thread_safe_flag.h

Issue 1551433002: Switch to standard integer types in components/, part 3 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 4 years, 12 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 2015 The Chromium Authors. All rights reserved. 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 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 COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_ 5 #ifndef COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_
6 #define COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_ 6 #define COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_
7 7
8 #include "base/atomicops.h" 8 #include "base/atomicops.h"
9 #include "base/macros.h"
9 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
10 11
11 // A PollableThreadSafeFlag can be polled without requiring a lock, but can only 12 // A PollableThreadSafeFlag can be polled without requiring a lock, but can only
12 // be updated if a lock is held. This enables lock-free checking as to whether a 13 // be updated if a lock is held. This enables lock-free checking as to whether a
13 // condition has changed, while protecting operations which update the condition 14 // condition has changed, while protecting operations which update the condition
14 // with a lock. You must ensure that the flag is only updated within the same 15 // with a lock. You must ensure that the flag is only updated within the same
15 // lock-protected critical section as any other variables on which the condition 16 // lock-protected critical section as any other variables on which the condition
16 // depends. 17 // depends.
17 class PollableThreadSafeFlag { 18 class PollableThreadSafeFlag {
18 public: 19 public:
19 explicit PollableThreadSafeFlag(base::Lock* write_lock); 20 explicit PollableThreadSafeFlag(base::Lock* write_lock);
20 ~PollableThreadSafeFlag(); 21 ~PollableThreadSafeFlag();
21 22
22 // Set the flag. May only be called if |write_lock| is held. 23 // Set the flag. May only be called if |write_lock| is held.
23 void SetWhileLocked(bool value); 24 void SetWhileLocked(bool value);
24 25
25 // Returns true iff the flag is set to true. 26 // Returns true iff the flag is set to true.
26 bool IsSet() const; 27 bool IsSet() const;
27 28
28 private: 29 private:
29 base::subtle::Atomic32 flag_; 30 base::subtle::Atomic32 flag_;
30 base::Lock* write_lock_; // Not owned. 31 base::Lock* write_lock_; // Not owned.
31 32
32 DISALLOW_COPY_AND_ASSIGN(PollableThreadSafeFlag); 33 DISALLOW_COPY_AND_ASSIGN(PollableThreadSafeFlag);
33 }; 34 };
34 35
35 #endif // COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_ 36 #endif // COMPONENTS_SCHEDULER_BASE_POLLABLE_THREAD_SAFE_FLAG_H_
OLDNEW
« no previous file with comments | « components/scheduler/base/cancelable_closure_holder.h ('k') | components/scheduler/base/task_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698