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

Unified Diff: components/scheduler/child/pollable_thread_safe_flag.h

Issue 1151353003: [scheduler]: Avoid waking up the scheduler to end long idle periods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@end_idle_sync_2
Patch Set: Fix Win for realz hopefully... Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/scheduler/child/pollable_thread_safe_flag.h
diff --git a/components/scheduler/child/pollable_thread_safe_flag.h b/components/scheduler/child/pollable_thread_safe_flag.h
new file mode 100644
index 0000000000000000000000000000000000000000..cf0564120607fe5388996cea17e1b9e1b6e17102
--- /dev/null
+++ b/components/scheduler/child/pollable_thread_safe_flag.h
@@ -0,0 +1,35 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_SCHEDULER_CHILD_POLLABLE_THREAD_SAFE_FLAG_H_
+#define COMPONENTS_SCHEDULER_CHILD_POLLABLE_THREAD_SAFE_FLAG_H_
+
+#include "base/atomicops.h"
+#include "base/synchronization/lock.h"
+
+// A PollableThreadSafeFlag can be polled without requiring a lock, but can only
+// be updated if a lock is held. This enables lock-free checking as to whether a
+// condition has changed, while protecting operations which update the condition
+// with a lock. You must ensure that the flag is only updated within the same
+// lock-protected critical section as any other variables on which the condition
+// depends.
+class PollableThreadSafeFlag {
+ public:
+ explicit PollableThreadSafeFlag(base::Lock* write_lock);
+ ~PollableThreadSafeFlag();
+
+ // Set the flag. May only be called if |write_lock| is held.
+ void SetWhileLocked(bool value);
+
+ // Returns true iff the flag is set to true.
+ bool IsSet() const;
+
+ private:
+ base::subtle::Atomic32 flag_;
+ base::Lock* write_lock_; // Not owned.
+
+ DISALLOW_COPY_AND_ASSIGN(PollableThreadSafeFlag);
+};
+
+#endif // COMPONENTS_SCHEDULER_CHILD_POLLABLE_THREAD_SAFE_FLAG_H_
« no previous file with comments | « components/scheduler/child/null_idle_task_runner.cc ('k') | components/scheduler/child/pollable_thread_safe_flag.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698