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

Unified Diff: base/task_scheduler/scheduler_lock.h

Issue 1685423002: Task Scheduler. (Closed) Base URL: https://luckyluke-private.googlesource.com/src@a_master
Patch Set: Created 4 years, 10 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: 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

Powered by Google App Engine
This is Rietveld 408576698