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

Unified Diff: base/task_scheduler/scheduler_lock.h

Issue 1706123002: TaskScheduler [2/9] Scheduler Lock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Thread Local Acquired Lock Vector and CR Feedback 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..028757c7242617e2c8d19eed4d9aaa4eadc747c3
--- /dev/null
+++ b/base/task_scheduler/scheduler_lock.h
@@ -0,0 +1,89 @@
+// 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>
fdoray 2016/02/22 16:45:21 not needed here
robliao 2016/02/22 18:38:09 Done.
+
+#include "base/base_export.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
+#include "base/task_scheduler/scheduler_lock_impl.h"
+
+namespace base {
+namespace internal {
+
+// SchedulerLock should be used anywhere a lock would be used in the scheduler.
+// When DCHECK_IS_ON(), lock checking occurs. Otherwise, SchedulerLock is
+// equivalent to base::Lock.
+//
+// The shape of SchedulerLock is as follows:
+// SchedulerLock()
+// Default constructor, no predecessor lock.
+// DCHECKs
+// On Acquisition if any scheduler lock is acquired on this thread.
+//
+// SchedulerLock(const SchedulerLock* predecessor)
+// Constructor that specifies an allowed predecessor for that lock.
+// DCHECKs
+// On Construction if |predecessor| forms a predecessor lock cycle.
+// On Acquisition if the previous lock acquired on the thread is not
+// |predecessor|. Okay if there was no previous lock acquired.
+//
+// void Acquire()
+// Acquires the lock.
+//
+// void Release()
+// Releases the lock.
+//
+// void AssertAcquired().
+// DCHECKs if the lock is not acquired.
+//
+// scoped_ptr<ConditionVariable> CreateConditionVariable()
+// Creates a condition variable using this as a lock.
+
+#if DCHECK_IS_ON()
+class SchedulerLock : public SchedulerLockImpl {
+ public:
+ SchedulerLock() = default;
+ explicit SchedulerLock(const SchedulerLock* predecessor)
+ : SchedulerLockImpl(predecessor) {}
+};
+#else // DCHECK_IS_ON()
+class SchedulerLock : public Lock {
+ public:
+ SchedulerLock() = default;
+ explicit SchedulerLock(const SchedulerLock*) {}
+
+ scoped_ptr<ConditionVariable> CreateConditionVariable() {
+ return scoped_ptr<ConditionVariable>(new ConditionVariable(this));
+ }
+};
+#endif // DCHECK_IS_ON()
+
+// Provides the same functionality as base::AutoLock for SchedulerLock.
+class AutoSchedulerLock {
+ public:
+ explicit AutoSchedulerLock(SchedulerLock& lock) : lock_(lock) {
+ lock_.Acquire();
+ }
+
+ ~AutoSchedulerLock() {
+ lock_.AssertAcquired();
+ lock_.Release();
+ }
+
+ private:
+ SchedulerLock& lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoSchedulerLock);
+};
+
+} // namespace internal
+} // namespace base
+
+#endif // BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H

Powered by Google App Engine
This is Rietveld 408576698