Index: base/task_scheduler/scheduler_lock.h |
diff --git a/base/task_scheduler/scheduler_lock.h b/base/task_scheduler/scheduler_lock.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..df936b88cac267b3728d17eaaf749afed5a9b3ce |
--- /dev/null |
+++ b/base/task_scheduler/scheduler_lock.h |
@@ -0,0 +1,56 @@ |
+// Copyright 2016 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 BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H |
+#define BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H |
+ |
+#include <vector> |
+ |
+#include "base/base_export.h" |
+#include "base/macros.h" |
+#include "base/synchronization/lock.h" |
+ |
+namespace base { |
+namespace task_scheduler { |
+ |
+// A regular lock with simple deadlock correctness checking. |
+// This lock is used throughout the scheduler, and when DCHECK_IS_ON(), tracks |
+// all of the available locks to make sure that any locks are acquired in |
+// an expected order. |
+class BASE_EXPORT SchedulerLock { |
+ public: |
+ SchedulerLock(); |
+ explicit SchedulerLock(const SchedulerLock* predecessor); |
+ ~SchedulerLock(); |
+ |
+ void Acquire(); |
+ void Release(); |
+ |
+ Lock* RawLockForConditionVariable(); |
+ |
+ private: |
+ Lock lock; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SchedulerLock); |
+}; |
+ |
+class AutoSchedulerLock { |
+ public: |
+ explicit AutoSchedulerLock(SchedulerLock& lock) : lock_(lock) { |
+ lock_.Acquire(); |
+ } |
+ |
+ ~AutoSchedulerLock() { |
+ lock_.Release(); |
+ } |
+ |
+ private: |
+ SchedulerLock& lock_; |
+ DISALLOW_COPY_AND_ASSIGN(AutoSchedulerLock); |
+}; |
+ |
+} // namespace task_scheduler |
+} // namespace base |
+ |
+#endif // BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H |