[base] Rename internal::SchedulerLock to internal::CheckedLock
And move to base/task/common as it is now used by
base/task/sequence_manager as well.
[email protected]
[email protected]
(side-effects on services/tracing)
Bug: 951388
Change-Id: Icae46a97d5e70a1dd164d2b4b136919dc34bd8b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1588719
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: François Doray <[email protected]>
Commit-Queue: Gabriel Charette <[email protected]>
Auto-Submit: Gabriel Charette <[email protected]>
Cr-Commit-Position: refs/heads/master@{#655340}
diff --git a/base/task/common/checked_lock.h b/base/task/common/checked_lock.h
new file mode 100644
index 0000000..29ce5735
--- /dev/null
+++ b/base/task/common/checked_lock.h
@@ -0,0 +1,131 @@
+// 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_COMMON_CHECKED_LOCK_H_
+#define BASE_TASK_COMMON_CHECKED_LOCK_H_
+
+#include <memory>
+
+#include "base/base_export.h"
+#include "base/macros.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
+#include "base/task/common/checked_lock_impl.h"
+#include "base/thread_annotations.h"
+
+namespace base {
+namespace internal {
+
+// CheckedLock should be used anywhere a Lock would be used in the base/task
+// impl. When DCHECK_IS_ON(), lock checking occurs. Otherwise, CheckedLock is
+// equivalent to base::Lock.
+//
+// The shape of CheckedLock is as follows:
+// CheckedLock()
+// Default constructor, no predecessor lock.
+// DCHECKs
+// On Acquisition if any CheckedLock is acquired on this thread.
+// Okay if a universal predecessor is acquired.
+//
+// CheckedLock(const CheckedLock* 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
+// either |predecessor| or a universal predecessor. Okay if there
+// was no previous lock acquired.
+//
+// CheckedLock(UniversalPredecessor universal_predecessor)
+// Constructor for a lock that will allow the acquisition of any lock after
+// it, without needing to explicitly be named a predecessor. Can only be
+// acquired if no locks are currently held by this thread.
+// DCHECKs
+// On Acquisition if any CheckedLock is acquired on this thread.
+//
+// void Acquire()
+// Acquires the lock.
+//
+// void Release()
+// Releases the lock.
+//
+// void AssertAcquired().
+// DCHECKs if the lock is not acquired.
+//
+// std::unique_ptr<ConditionVariable> CreateConditionVariable()
+// Creates a condition variable using this as a lock.
+
+#if DCHECK_IS_ON()
+class LOCKABLE CheckedLock : public CheckedLockImpl {
+ public:
+ CheckedLock() = default;
+ explicit CheckedLock(const CheckedLock* predecessor)
+ : CheckedLockImpl(predecessor) {}
+ explicit CheckedLock(UniversalPredecessor universal_predecessor)
+ : CheckedLockImpl(universal_predecessor) {}
+};
+#else // DCHECK_IS_ON()
+class LOCKABLE CheckedLock : public Lock {
+ public:
+ CheckedLock() = default;
+ explicit CheckedLock(const CheckedLock*) {}
+ explicit CheckedLock(UniversalPredecessor) {}
+ static void AssertNoLockHeldOnCurrentThread() {}
+
+ std::unique_ptr<ConditionVariable> CreateConditionVariable() {
+ return std::unique_ptr<ConditionVariable>(new ConditionVariable(this));
+ }
+};
+#endif // DCHECK_IS_ON()
+
+// Provides the same functionality as base::AutoLock for CheckedLock.
+using CheckedAutoLock = internal::BasicAutoLock<CheckedLock>;
+
+// Provides the same functionality as base::AutoUnlock for CheckedLock.
+using CheckedAutoUnlock = internal::BasicAutoUnlock<CheckedLock>;
+
+// Provides the same functionality as base::AutoLockMaybe for CheckedLock.
+using CheckedAutoLockMaybe = internal::BasicAutoLockMaybe<CheckedLock>;
+
+// Informs the clang thread safety analysis that an aliased lock is acquired.
+// Because the clang thread safety analysis doesn't understand aliased locks
+// [1], this code wouldn't compile without AnnotateAcquiredLockAlias:
+//
+// class Example {
+// public:
+// CheckedLock lock_;
+// int value = 0 GUARDED_BY(lock_);
+// };
+//
+// Example example;
+// CheckedLock* acquired = &example.lock_;
+// CheckedAutoLock auto_lock(*acquired);
+// AnnotateAcquiredLockAlias annotate(*acquired, example.lock_);
+// example.value = 42; // Doesn't compile without |annotate|.
+//
+// [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#no-alias-analysis
+class SCOPED_LOCKABLE AnnotateAcquiredLockAlias {
+ public:
+ // |acquired_lock| is an acquired lock. |lock_alias| is an alias of
+ // |acquired_lock|.
+ AnnotateAcquiredLockAlias(const CheckedLock& acquired_lock,
+ const CheckedLock& lock_alias)
+ EXCLUSIVE_LOCK_FUNCTION(lock_alias)
+ : acquired_lock_(acquired_lock) {
+ DCHECK_EQ(&acquired_lock, &lock_alias);
+ acquired_lock_.AssertAcquired();
+ }
+ ~AnnotateAcquiredLockAlias() UNLOCK_FUNCTION() {
+ acquired_lock_.AssertAcquired();
+ }
+
+ private:
+ const CheckedLock& acquired_lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(AnnotateAcquiredLockAlias);
+};
+
+} // namespace internal
+} // namespace base
+
+#endif // BASE_TASK_COMMON_CHECKED_LOCK_H_
diff --git a/base/task/thread_pool/scheduler_lock_impl.cc b/base/task/common/checked_lock_impl.cc
similarity index 67%
rename from base/task/thread_pool/scheduler_lock_impl.cc
rename to base/task/common/checked_lock_impl.cc
index b6f62e3..c801f05 100644
--- a/base/task/thread_pool/scheduler_lock_impl.cc
+++ b/base/task/common/checked_lock_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/task/thread_pool/scheduler_lock_impl.h"
+#include "base/task/common/checked_lock_impl.h"
#include <algorithm>
#include <unordered_map>
@@ -11,7 +11,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/synchronization/condition_variable.h"
-#include "base/task/thread_pool/scheduler_lock.h"
+#include "base/task/common/checked_lock.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_local.h"
@@ -24,25 +24,25 @@
public:
SafeAcquisitionTracker() = default;
- void RegisterLock(const SchedulerLockImpl* const lock,
- const SchedulerLockImpl* const predecessor) {
+ void RegisterLock(const CheckedLockImpl* const lock,
+ const CheckedLockImpl* const predecessor) {
DCHECK_NE(lock, predecessor) << "Reentrant locks are unsupported.";
AutoLock auto_lock(allowed_predecessor_map_lock_);
allowed_predecessor_map_[lock] = predecessor;
AssertSafePredecessor(lock);
}
- void UnregisterLock(const SchedulerLockImpl* const lock) {
+ void UnregisterLock(const CheckedLockImpl* const lock) {
AutoLock auto_lock(allowed_predecessor_map_lock_);
allowed_predecessor_map_.erase(lock);
}
- void RecordAcquisition(const SchedulerLockImpl* const lock) {
+ void RecordAcquisition(const CheckedLockImpl* const lock) {
AssertSafeAcquire(lock);
GetAcquiredLocksOnCurrentThread()->push_back(lock);
}
- void RecordRelease(const SchedulerLockImpl* const lock) {
+ void RecordRelease(const CheckedLockImpl* const lock) {
LockVector* acquired_locks = GetAcquiredLocksOnCurrentThread();
const auto iter_at_lock =
std::find(acquired_locks->begin(), acquired_locks->end(), lock);
@@ -55,13 +55,13 @@
}
private:
- using LockVector = std::vector<const SchedulerLockImpl*>;
+ using LockVector = std::vector<const CheckedLockImpl*>;
using PredecessorMap =
- std::unordered_map<const SchedulerLockImpl*, const SchedulerLockImpl*>;
+ std::unordered_map<const CheckedLockImpl*, const CheckedLockImpl*>;
// This asserts that the lock is safe to acquire. This means that this should
// be run before actually recording the acquisition.
- void AssertSafeAcquire(const SchedulerLockImpl* const lock) {
+ void AssertSafeAcquire(const CheckedLockImpl* const lock) {
const LockVector* acquired_locks = GetAcquiredLocksOnCurrentThread();
// If the thread currently holds no locks, this is inherently safe.
@@ -73,34 +73,34 @@
// Otherwise, make sure that the previous lock acquired is either an
// allowed predecessor for this lock or a universal predecessor.
- const SchedulerLockImpl* previous_lock = acquired_locks->back();
+ const CheckedLockImpl* previous_lock = acquired_locks->back();
if (previous_lock->is_universal_predecessor())
return;
AutoLock auto_lock(allowed_predecessor_map_lock_);
// Using at() is exception-safe here as |lock| was registered already.
- const SchedulerLockImpl* allowed_predecessor =
+ const CheckedLockImpl* allowed_predecessor =
allowed_predecessor_map_.at(lock);
DCHECK_EQ(previous_lock, allowed_predecessor);
}
// Asserts that |lock|'s registered predecessor is safe. Because
- // SchedulerLocks are registered at construction time and any predecessor
- // specified on a SchedulerLock must already exist, the first registered
- // SchedulerLock in a potential chain must have a null predecessor and is thus
- // cycle-free. Any subsequent SchedulerLock with a predecessor must come from
- // the set of registered SchedulerLocks. Since the registered SchedulerLocks
- // only contain cycle-free SchedulerLocks, this subsequent SchedulerLock is
- // itself cycle-free and may be safely added to the registered SchedulerLock
+ // CheckedLocks are registered at construction time and any predecessor
+ // specified on a CheckedLock must already exist, the first registered
+ // CheckedLock in a potential chain must have a null predecessor and is thus
+ // cycle-free. Any subsequent CheckedLock with a predecessor must come from
+ // the set of registered CheckedLocks. Since the registered CheckedLocks
+ // only contain cycle-free CheckedLocks, this subsequent CheckedLock is
+ // itself cycle-free and may be safely added to the registered CheckedLock
// set.
- void AssertSafePredecessor(const SchedulerLockImpl* lock) const {
+ void AssertSafePredecessor(const CheckedLockImpl* lock) const {
allowed_predecessor_map_lock_.AssertAcquired();
// Using at() is exception-safe here as |lock| was registered already.
- const SchedulerLockImpl* predecessor = allowed_predecessor_map_.at(lock);
+ const CheckedLockImpl* predecessor = allowed_predecessor_map_.at(lock);
if (predecessor) {
DCHECK(allowed_predecessor_map_.find(predecessor) !=
allowed_predecessor_map_.end())
- << "SchedulerLock was registered before its predecessor. "
+ << "CheckedLock was registered before its predecessor. "
<< "Potential cycle detected";
}
}
@@ -130,40 +130,39 @@
} // namespace
-SchedulerLockImpl::SchedulerLockImpl() : SchedulerLockImpl(nullptr) {}
+CheckedLockImpl::CheckedLockImpl() : CheckedLockImpl(nullptr) {}
-SchedulerLockImpl::SchedulerLockImpl(const SchedulerLockImpl* predecessor)
+CheckedLockImpl::CheckedLockImpl(const CheckedLockImpl* predecessor)
: is_universal_predecessor_(false) {
g_safe_acquisition_tracker.Get().RegisterLock(this, predecessor);
}
-SchedulerLockImpl::SchedulerLockImpl(UniversalPredecessor)
+CheckedLockImpl::CheckedLockImpl(UniversalPredecessor)
: is_universal_predecessor_(true) {}
-SchedulerLockImpl::~SchedulerLockImpl() {
+CheckedLockImpl::~CheckedLockImpl() {
g_safe_acquisition_tracker.Get().UnregisterLock(this);
}
-void SchedulerLockImpl::AssertNoLockHeldOnCurrentThread() {
+void CheckedLockImpl::AssertNoLockHeldOnCurrentThread() {
g_safe_acquisition_tracker.Get().AssertNoLockHeldOnCurrentThread();
}
-void SchedulerLockImpl::Acquire() {
+void CheckedLockImpl::Acquire() {
lock_.Acquire();
g_safe_acquisition_tracker.Get().RecordAcquisition(this);
}
-void SchedulerLockImpl::Release() {
+void CheckedLockImpl::Release() {
lock_.Release();
g_safe_acquisition_tracker.Get().RecordRelease(this);
}
-void SchedulerLockImpl::AssertAcquired() const {
+void CheckedLockImpl::AssertAcquired() const {
lock_.AssertAcquired();
}
-std::unique_ptr<ConditionVariable>
-SchedulerLockImpl::CreateConditionVariable() {
+std::unique_ptr<ConditionVariable> CheckedLockImpl::CreateConditionVariable() {
return std::make_unique<ConditionVariable>(&lock_);
}
diff --git a/base/task/thread_pool/scheduler_lock_impl.h b/base/task/common/checked_lock_impl.h
similarity index 69%
rename from base/task/thread_pool/scheduler_lock_impl.h
rename to base/task/common/checked_lock_impl.h
index 0b827bf..2a3dac6 100644
--- a/base/task/thread_pool/scheduler_lock_impl.h
+++ b/base/task/common/checked_lock_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_TASK_THREAD_POOL_SCHEDULER_LOCK_IMPL_H_
-#define BASE_TASK_THREAD_POOL_SCHEDULER_LOCK_IMPL_H_
+#ifndef BASE_TASK_COMMON_CHECKED_LOCK_IMPL_H_
+#define BASE_TASK_COMMON_CHECKED_LOCK_IMPL_H_
#include <memory>
@@ -23,12 +23,12 @@
// This lock tracks all of the available locks to make sure that any locks are
// acquired in an expected order.
// See scheduler_lock.h for details.
-class BASE_EXPORT SchedulerLockImpl {
+class BASE_EXPORT CheckedLockImpl {
public:
- SchedulerLockImpl();
- explicit SchedulerLockImpl(const SchedulerLockImpl* predecessor);
- explicit SchedulerLockImpl(UniversalPredecessor);
- ~SchedulerLockImpl();
+ CheckedLockImpl();
+ explicit CheckedLockImpl(const CheckedLockImpl* predecessor);
+ explicit CheckedLockImpl(UniversalPredecessor);
+ ~CheckedLockImpl();
static void AssertNoLockHeldOnCurrentThread();
@@ -45,10 +45,10 @@
Lock lock_;
const bool is_universal_predecessor_;
- DISALLOW_COPY_AND_ASSIGN(SchedulerLockImpl);
+ DISALLOW_COPY_AND_ASSIGN(CheckedLockImpl);
};
} // namespace internal
} // namespace base
-#endif // BASE_TASK_THREAD_POOL_SCHEDULER_LOCK_IMPL_H_
+#endif // BASE_TASK_COMMON_CHECKED_LOCK_IMPL_H_
diff --git a/base/task/thread_pool/scheduler_lock_unittest.cc b/base/task/common/checked_lock_unittest.cc
similarity index 70%
rename from base/task/thread_pool/scheduler_lock_unittest.cc
rename to base/task/common/checked_lock_unittest.cc
index f572774..85223cc 100644
--- a/base/task/thread_pool/scheduler_lock_unittest.cc
+++ b/base/task/common/checked_lock_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/task/thread_pool/scheduler_lock.h"
+#include "base/task/common/checked_lock.h"
#include <stdlib.h>
@@ -23,7 +23,7 @@
// Acquire()/Release() don't crash.
class BasicLockTestThread : public SimpleThread {
public:
- explicit BasicLockTestThread(SchedulerLock* lock)
+ explicit BasicLockTestThread(CheckedLock* lock)
: SimpleThread("BasicLockTestThread"), lock_(lock), acquired_(0) {}
int acquired() const { return acquired_; }
@@ -43,7 +43,7 @@
}
}
- SchedulerLock* const lock_;
+ CheckedLock* const lock_;
int acquired_;
DISALLOW_COPY_AND_ASSIGN(BasicLockTestThread);
@@ -51,7 +51,7 @@
class BasicLockAcquireAndWaitThread : public SimpleThread {
public:
- explicit BasicLockAcquireAndWaitThread(SchedulerLock* lock)
+ explicit BasicLockAcquireAndWaitThread(CheckedLock* lock)
: SimpleThread("BasicLockAcquireAndWaitThread"),
lock_(lock),
lock_acquire_event_(WaitableEvent::ResetPolicy::AUTOMATIC,
@@ -72,7 +72,7 @@
lock_->Release();
}
- SchedulerLock* const lock_;
+ CheckedLock* const lock_;
WaitableEvent lock_acquire_event_;
WaitableEvent main_thread_continue_event_;
@@ -81,8 +81,8 @@
} // namespace
-TEST(ThreadPoolLock, Basic) {
- SchedulerLock lock;
+TEST(CheckedLockTest, Basic) {
+ CheckedLock lock;
BasicLockTestThread thread(&lock);
thread.Start();
@@ -112,37 +112,37 @@
EXPECT_EQ(thread.acquired(), 20);
}
-TEST(ThreadPoolLock, AcquirePredecessor) {
- SchedulerLock predecessor;
- SchedulerLock lock(&predecessor);
+TEST(CheckedLockTest, AcquirePredecessor) {
+ CheckedLock predecessor;
+ CheckedLock lock(&predecessor);
predecessor.Acquire();
lock.Acquire();
lock.Release();
predecessor.Release();
}
-TEST(ThreadPoolLock, AcquirePredecessorWrongOrder) {
- SchedulerLock predecessor;
- SchedulerLock lock(&predecessor);
+TEST(CheckedLockTest, AcquirePredecessorWrongOrder) {
+ CheckedLock predecessor;
+ CheckedLock lock(&predecessor);
EXPECT_DCHECK_DEATH({
lock.Acquire();
predecessor.Acquire();
});
}
-TEST(ThreadPoolLock, AcquireNonPredecessor) {
- SchedulerLock lock1;
- SchedulerLock lock2;
+TEST(CheckedLockTest, AcquireNonPredecessor) {
+ CheckedLock lock1;
+ CheckedLock lock2;
EXPECT_DCHECK_DEATH({
lock1.Acquire();
lock2.Acquire();
});
}
-TEST(ThreadPoolLock, AcquireMultipleLocksInOrder) {
- SchedulerLock lock1;
- SchedulerLock lock2(&lock1);
- SchedulerLock lock3(&lock2);
+TEST(CheckedLockTest, AcquireMultipleLocksInOrder) {
+ CheckedLock lock1;
+ CheckedLock lock2(&lock1);
+ CheckedLock lock3(&lock2);
lock1.Acquire();
lock2.Acquire();
lock3.Acquire();
@@ -151,29 +151,29 @@
lock1.Release();
}
-TEST(ThreadPoolLock, AcquireMultipleLocksInTheMiddleOfAChain) {
- SchedulerLock lock1;
- SchedulerLock lock2(&lock1);
- SchedulerLock lock3(&lock2);
+TEST(CheckedLockTest, AcquireMultipleLocksInTheMiddleOfAChain) {
+ CheckedLock lock1;
+ CheckedLock lock2(&lock1);
+ CheckedLock lock3(&lock2);
lock2.Acquire();
lock3.Acquire();
lock3.Release();
lock2.Release();
}
-TEST(ThreadPoolLock, AcquireMultipleLocksNoTransitivity) {
- SchedulerLock lock1;
- SchedulerLock lock2(&lock1);
- SchedulerLock lock3(&lock2);
+TEST(CheckedLockTest, AcquireMultipleLocksNoTransitivity) {
+ CheckedLock lock1;
+ CheckedLock lock2(&lock1);
+ CheckedLock lock3(&lock2);
EXPECT_DCHECK_DEATH({
lock1.Acquire();
lock3.Acquire();
});
}
-TEST(ThreadPoolLock, AcquireLocksDifferentThreadsSafely) {
- SchedulerLock lock1;
- SchedulerLock lock2;
+TEST(CheckedLockTest, AcquireLocksDifferentThreadsSafely) {
+ CheckedLock lock1;
+ CheckedLock lock2;
BasicLockAcquireAndWaitThread thread(&lock1);
thread.Start();
@@ -184,7 +184,7 @@
lock2.Release();
}
-TEST(ThreadPoolLock,
+TEST(CheckedLockTest,
AcquireLocksWithPredecessorDifferentThreadsSafelyPredecessorFirst) {
// A lock and its predecessor may be safely acquired on different threads.
// This Thread Other Thread
@@ -192,8 +192,8 @@
// lock.Acquire()
// predecessor.Release()
// lock.Release()
- SchedulerLock predecessor;
- SchedulerLock lock(&predecessor);
+ CheckedLock predecessor;
+ CheckedLock lock(&predecessor);
predecessor.Acquire();
BasicLockAcquireAndWaitThread thread(&lock);
thread.Start();
@@ -203,7 +203,7 @@
thread.Join();
}
-TEST(ThreadPoolLock,
+TEST(CheckedLockTest,
AcquireLocksWithPredecessorDifferentThreadsSafelyPredecessorLast) {
// A lock and its predecessor may be safely acquired on different threads.
// This Thread Other Thread
@@ -211,8 +211,8 @@
// predecessor.Acquire()
// lock.Release()
// predecessor.Release()
- SchedulerLock predecessor;
- SchedulerLock lock(&predecessor);
+ CheckedLock predecessor;
+ CheckedLock lock(&predecessor);
lock.Acquire();
BasicLockAcquireAndWaitThread thread(&predecessor);
thread.Start();
@@ -222,7 +222,7 @@
thread.Join();
}
-TEST(ThreadPoolLock,
+TEST(CheckedLockTest,
AcquireLocksWithPredecessorDifferentThreadsSafelyNoInterference) {
// Acquisition of an unrelated lock on another thread should not affect a
// legal lock acquisition with a predecessor on this thread.
@@ -233,10 +233,10 @@
// unrelated.Release()
// lock.Release()
// predecessor.Release();
- SchedulerLock predecessor;
- SchedulerLock lock(&predecessor);
+ CheckedLock predecessor;
+ CheckedLock lock(&predecessor);
predecessor.Acquire();
- SchedulerLock unrelated;
+ CheckedLock unrelated;
BasicLockAcquireAndWaitThread thread(&unrelated);
thread.Start();
thread.WaitForLockAcquisition();
@@ -247,28 +247,28 @@
predecessor.Release();
}
-TEST(ThreadPoolLock, SelfReferentialLock) {
+TEST(CheckedLockTest, SelfReferentialLock) {
struct SelfReferentialLock {
SelfReferentialLock() : lock(&lock) {}
- SchedulerLock lock;
+ CheckedLock lock;
};
EXPECT_DCHECK_DEATH({ SelfReferentialLock lock; });
}
-TEST(ThreadPoolLock, PredecessorCycle) {
+TEST(CheckedLockTest, PredecessorCycle) {
struct LockCycle {
LockCycle() : lock1(&lock2), lock2(&lock1) {}
- SchedulerLock lock1;
- SchedulerLock lock2;
+ CheckedLock lock1;
+ CheckedLock lock2;
};
EXPECT_DCHECK_DEATH({ LockCycle cycle; });
}
-TEST(ThreadPoolLock, PredecessorLongerCycle) {
+TEST(CheckedLockTest, PredecessorLongerCycle) {
struct LockCycle {
LockCycle()
: lock1(&lock5),
@@ -277,21 +277,21 @@
lock4(&lock3),
lock5(&lock4) {}
- SchedulerLock lock1;
- SchedulerLock lock2;
- SchedulerLock lock3;
- SchedulerLock lock4;
- SchedulerLock lock5;
+ CheckedLock lock1;
+ CheckedLock lock2;
+ CheckedLock lock3;
+ CheckedLock lock4;
+ CheckedLock lock5;
};
EXPECT_DCHECK_DEATH({ LockCycle cycle; });
}
-TEST(ThreadPoolLock, AcquireLockAfterUniversalPredecessor) {
+TEST(CheckedLockTest, AcquireLockAfterUniversalPredecessor) {
// Acquisition of a universal-predecessor lock should not prevent acquisition
- // of a SchedulerLock after it.
- SchedulerLock universal_predecessor((UniversalPredecessor()));
- SchedulerLock lock;
+ // of a CheckedLock after it.
+ CheckedLock universal_predecessor((UniversalPredecessor()));
+ CheckedLock lock;
universal_predecessor.Acquire();
lock.Acquire();
@@ -299,13 +299,13 @@
universal_predecessor.Release();
}
-TEST(ThreadPoolLock, AcquireMultipleLocksAfterUniversalPredecessor) {
+TEST(CheckedLockTest, AcquireMultipleLocksAfterUniversalPredecessor) {
// Acquisition of a universal-predecessor lock does not affect acquisition
// rules for locks beyond the one acquired directly after it.
- SchedulerLock universal_predecessor((UniversalPredecessor()));
- SchedulerLock lock;
- SchedulerLock lock2(&lock);
- SchedulerLock lock3;
+ CheckedLock universal_predecessor((UniversalPredecessor()));
+ CheckedLock lock;
+ CheckedLock lock2(&lock);
+ CheckedLock lock3;
universal_predecessor.Acquire();
lock.Acquire();
@@ -321,10 +321,10 @@
});
}
-TEST(ThreadPoolLock, AcquireUniversalPredecessorAfterLock) {
+TEST(CheckedLockTest, AcquireUniversalPredecessorAfterLock) {
// A universal-predecessor lock may not be acquired after any other lock.
- SchedulerLock universal_predecessor((UniversalPredecessor()));
- SchedulerLock lock;
+ CheckedLock universal_predecessor((UniversalPredecessor()));
+ CheckedLock lock;
EXPECT_DCHECK_DEATH({
lock.Acquire();
@@ -332,11 +332,11 @@
});
}
-TEST(ThreadPoolLock, AcquireUniversalPredecessorAfterUniversalPredecessor) {
+TEST(CheckedLockTest, AcquireUniversalPredecessorAfterUniversalPredecessor) {
// A universal-predecessor lock may not be acquired after any other lock, not
// even another universal predecessor.
- SchedulerLock universal_predecessor((UniversalPredecessor()));
- SchedulerLock universal_predecessor2((UniversalPredecessor()));
+ CheckedLock universal_predecessor((UniversalPredecessor()));
+ CheckedLock universal_predecessor2((UniversalPredecessor()));
EXPECT_DCHECK_DEATH({
universal_predecessor.Acquire();
@@ -344,15 +344,15 @@
});
}
-TEST(ThreadPoolLock, AssertNoLockHeldOnCurrentThread) {
+TEST(CheckedLockTest, AssertNoLockHeldOnCurrentThread) {
// AssertNoLockHeldOnCurrentThread() shouldn't fail when no lock is acquired.
- SchedulerLock::AssertNoLockHeldOnCurrentThread();
+ CheckedLock::AssertNoLockHeldOnCurrentThread();
// AssertNoLockHeldOnCurrentThread() should fail when a lock is acquired.
- SchedulerLock lock;
+ CheckedLock lock;
{
- AutoSchedulerLock auto_lock(lock);
- EXPECT_DCHECK_DEATH({ SchedulerLock::AssertNoLockHeldOnCurrentThread(); });
+ CheckedAutoLock auto_lock(lock);
+ EXPECT_DCHECK_DEATH({ CheckedLock::AssertNoLockHeldOnCurrentThread(); });
}
}
@@ -360,16 +360,16 @@
class MemberGuardedByLock {
public:
- SchedulerLock lock_;
+ CheckedLock lock_;
int value GUARDED_BY(lock_) = 0;
};
} // namespace
-TEST(ThreadPoolLock, AnnotateAcquiredLockAlias) {
+TEST(CheckedLockTest, AnnotateAcquiredLockAlias) {
MemberGuardedByLock member_guarded_by_lock;
- SchedulerLock* acquired = &member_guarded_by_lock.lock_;
- AutoSchedulerLock auto_lock(*acquired);
+ CheckedLock* acquired = &member_guarded_by_lock.lock_;
+ CheckedAutoLock auto_lock(*acquired);
AnnotateAcquiredLockAlias annotate(*acquired, member_guarded_by_lock.lock_);
member_guarded_by_lock.value = 42; // Doesn't compile without |annotate|.
}
diff --git a/base/task/lazy_task_runner.cc b/base/task/lazy_task_runner.cc
index 20bac91..fc80c8e7 100644
--- a/base/task/lazy_task_runner.cc
+++ b/base/task/lazy_task_runner.cc
@@ -107,14 +107,14 @@
}
ScopedLazyTaskRunnerListForTesting::~ScopedLazyTaskRunnerListForTesting() {
- internal::AutoSchedulerLock auto_lock(lock_);
+ internal::CheckedAutoLock auto_lock(lock_);
for (auto& callback : callbacks_)
std::move(callback).Run();
g_scoped_lazy_task_runner_list_for_testing = nullptr;
}
void ScopedLazyTaskRunnerListForTesting::AddCallback(OnceClosure callback) {
- internal::AutoSchedulerLock auto_lock(lock_);
+ internal::CheckedAutoLock auto_lock(lock_);
callbacks_.push_back(std::move(callback));
}
diff --git a/base/task/lazy_task_runner.h b/base/task/lazy_task_runner.h
index 544d3473..68d19a68 100644
--- a/base/task/lazy_task_runner.h
+++ b/base/task/lazy_task_runner.h
@@ -13,9 +13,9 @@
#include "base/lazy_instance_helpers.h"
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/single_thread_task_runner_thread_mode.h"
#include "base/task/task_traits.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/thread_annotations.h"
#include "build/build_config.h"
@@ -204,7 +204,7 @@
// Add |callback| to the list of callbacks to run on destruction.
void AddCallback(OnceClosure callback);
- SchedulerLock lock_;
+ CheckedLock lock_;
// List of callbacks to run on destruction.
std::vector<OnceClosure> callbacks_ GUARDED_BY(lock_);
diff --git a/base/task/sequence_manager/task_queue.cc b/base/task/sequence_manager/task_queue.cc
index 3d82c2c..b3e01b0 100644
--- a/base/task/sequence_manager/task_queue.cc
+++ b/base/task/sequence_manager/task_queue.cc
@@ -176,8 +176,8 @@
scoped_refptr<SingleThreadTaskRunner> TaskQueue::CreateTaskRunner(
TaskType task_type) {
// We only need to lock if we're not on the main thread.
- base::internal::AutoSchedulerLockMaybe lock(IsOnMainThread() ? &impl_lock_
- : nullptr);
+ base::internal::CheckedAutoLockMaybe lock(IsOnMainThread() ? &impl_lock_
+ : nullptr);
if (!impl_)
return CreateNullTaskRunner();
return impl_->CreateTaskRunner(task_type);
@@ -331,7 +331,7 @@
}
std::unique_ptr<internal::TaskQueueImpl> TaskQueue::TakeTaskQueueImpl() {
- base::internal::AutoSchedulerLock lock(impl_lock_);
+ base::internal::CheckedAutoLock lock(impl_lock_);
DCHECK(impl_);
return std::move(impl_);
}
diff --git a/base/task/sequence_manager/task_queue.h b/base/task/sequence_manager/task_queue.h
index e90891c3..71449ee 100644
--- a/base/task/sequence_manager/task_queue.h
+++ b/base/task/sequence_manager/task_queue.h
@@ -12,10 +12,10 @@
#include "base/message_loop/message_loop.h"
#include "base/optional.h"
#include "base/single_thread_task_runner.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/sequence_manager/lazy_now.h"
#include "base/task/sequence_manager/tasks.h"
#include "base/task/task_observer.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
@@ -354,7 +354,7 @@
// |impl_lock_| must be acquired when writing to |impl_| or when accessing
// it from non-main thread. Reading from the main thread does not require
// a lock.
- mutable base::internal::SchedulerLock impl_lock_{
+ mutable base::internal::CheckedLock impl_lock_{
base::internal::UniversalPredecessor{}};
std::unique_ptr<internal::TaskQueueImpl> impl_;
diff --git a/base/task/sequence_manager/task_queue_impl.cc b/base/task/sequence_manager/task_queue_impl.cc
index 048e531..6cf3842 100644
--- a/base/task/sequence_manager/task_queue_impl.cc
+++ b/base/task/sequence_manager/task_queue_impl.cc
@@ -114,7 +114,7 @@
TaskQueueImpl::~TaskQueueImpl() {
#if DCHECK_IS_ON()
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
// NOTE this check shouldn't fire because |SequenceManagerImpl::queues_|
// contains a strong reference to this TaskQueueImpl and the
// SequenceManagerImpl destructor calls UnregisterTaskQueue on all task
@@ -160,7 +160,7 @@
TaskDeque immediate_incoming_queue;
{
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
any_thread_.unregistered = true;
any_thread_.time_domain = nullptr;
immediate_incoming_queue.swap(any_thread_.immediate_incoming_queue);
@@ -231,7 +231,7 @@
CurrentThread current_thread) {
#if DCHECK_IS_ON()
if (current_thread == TaskQueueImpl::CurrentThread::kNotMainThread) {
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
// Add a per-priority delay to cross thread tasks. This can help diagnose
// scheduler induced flakiness by making things flake most of the time.
task->delay +=
@@ -255,7 +255,7 @@
{
// TODO(alexclarke): Maybe add a main thread only immediate_incoming_queue
// See https://crbug.com/901800
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
TimeTicks now;
bool add_queue_time_to_tasks = sequence_manager_->GetAddQueueTimeToTasks();
if (delayed_fence_allowed_ || add_queue_time_to_tasks) {
@@ -351,7 +351,7 @@
TimeTicks time_domain_now;
{
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
time_domain_now = any_thread_.time_domain->Now();
}
TimeTicks time_domain_delayed_run_time = time_domain_now + task.delay;
@@ -433,7 +433,7 @@
}
void TaskQueueImpl::TakeImmediateIncomingQueueTasks(TaskDeque* queue) {
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
DCHECK(queue->empty());
queue->swap(any_thread_.immediate_incoming_queue);
@@ -473,7 +473,7 @@
return false;
}
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
return any_thread_.immediate_incoming_queue.empty();
}
@@ -483,7 +483,7 @@
task_count += main_thread_only().delayed_incoming_queue.size();
task_count += main_thread_only().immediate_work_queue->Size();
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
task_count += any_thread_.immediate_incoming_queue.size();
return task_count;
}
@@ -504,7 +504,7 @@
}
// Finally tasks on |immediate_incoming_queue| count as immediate work.
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
return !any_thread_.immediate_incoming_queue.empty();
}
@@ -565,7 +565,7 @@
if (!associated_thread_->IsBoundToCurrentThread())
return;
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
TRACE_COUNTER_WITH_FLAG1(
TRACE_DISABLED_BY_DEFAULT("sequence_manager"), GetName(),
TRACE_EVENT_FLAG_DISALLOW_POSTTASK,
@@ -591,7 +591,7 @@
void TaskQueueImpl::AsValueInto(TimeTicks now,
trace_event::TracedValue* state,
bool force_verbose) const {
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
state->BeginDictionary();
state->SetString("name", GetName());
if (any_thread_.unregistered) {
@@ -691,7 +691,7 @@
void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) {
{
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
DCHECK(time_domain);
DCHECK(!any_thread_.unregistered);
if (any_thread_.unregistered)
@@ -743,7 +743,7 @@
main_thread_only().delayed_work_queue->InsertFence(current_fence);
{
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
if (!task_unblocked && previous_fence && previous_fence < current_fence) {
if (!any_thread_.immediate_incoming_queue.empty() &&
any_thread_.immediate_incoming_queue.front().enqueue_order() >
@@ -780,7 +780,7 @@
task_unblocked |= main_thread_only().delayed_work_queue->RemoveFence();
{
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
if (!task_unblocked && previous_fence) {
if (!any_thread_.immediate_incoming_queue.empty() &&
any_thread_.immediate_incoming_queue.front().enqueue_order() >
@@ -805,7 +805,7 @@
return false;
}
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
if (any_thread_.immediate_incoming_queue.empty())
return true;
@@ -882,7 +882,7 @@
bool has_pending_immediate_work;
{
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
UpdateCrossThreadQueueStateLocked();
has_pending_immediate_work = HasPendingImmediateWorkLocked();
}
@@ -934,7 +934,7 @@
main_thread_only().immediate_work_queue->MaybeShrinkQueue();
{
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
any_thread_.immediate_incoming_queue.MaybeShrinkQueue();
}
@@ -943,7 +943,7 @@
}
void TaskQueueImpl::PushImmediateIncomingTaskForTest(Task&& task) {
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
any_thread_.immediate_incoming_queue.push_back(std::move(task));
}
@@ -964,7 +964,7 @@
// the lock to avoid a cross-thread post task setting it again before
// we actually make |immediate_work_queue| non-empty.
if (main_thread_only().immediate_work_queue->Empty()) {
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
empty_queues_to_reload_handle_.SetActive(false);
any_thread_.immediate_work_queue_empty = false;
@@ -1027,7 +1027,7 @@
}
// Finally tasks on |immediate_incoming_queue| count as immediate work.
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
return !any_thread_.immediate_incoming_queue.empty();
}
@@ -1067,7 +1067,7 @@
}
bool TaskQueueImpl::IsUnregistered() const {
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
return any_thread_.unregistered;
}
@@ -1095,7 +1095,7 @@
{
// Limit the scope of the lock to ensure that the deque is destroyed
// outside of the lock to allow it to post tasks.
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
deque.swap(any_thread_.immediate_incoming_queue);
any_thread_.immediate_work_queue_empty = true;
empty_queues_to_reload_handle_.SetActive(false);
@@ -1113,7 +1113,7 @@
if (!main_thread_only().delayed_incoming_queue.empty())
return true;
- base::internal::AutoSchedulerLock lock(any_thread_lock_);
+ base::internal::CheckedAutoLock lock(any_thread_lock_);
if (!any_thread_.immediate_incoming_queue.empty())
return true;
diff --git a/base/task/sequence_manager/task_queue_impl.h b/base/task/sequence_manager/task_queue_impl.h
index e80981ae..d366d5e 100644
--- a/base/task/sequence_manager/task_queue_impl.h
+++ b/base/task/sequence_manager/task_queue_impl.h
@@ -15,6 +15,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/pending_task.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/common/intrusive_heap.h"
#include "base/task/common/operations_controller.h"
#include "base/task/sequence_manager/associated_thread_id.h"
@@ -23,7 +24,6 @@
#include "base/task/sequence_manager/lazily_deallocated_deque.h"
#include "base/task/sequence_manager/sequenced_task_source.h"
#include "base/task/sequence_manager/task_queue.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/threading/thread_checker.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
@@ -412,7 +412,7 @@
const scoped_refptr<GuardedTaskPoster> task_poster_;
- mutable base::internal::SchedulerLock any_thread_lock_;
+ mutable base::internal::CheckedLock any_thread_lock_;
struct AnyThread {
explicit AnyThread(TimeDomain* time_domain);
diff --git a/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc b/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc
index 76057a2..1886b5c 100644
--- a/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc
+++ b/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc
@@ -87,7 +87,7 @@
base::internal::ScopedSetSequenceLocalStorageMapForCurrentThread>(
&sequence_local_storage_map_);
{
- base::internal::AutoSchedulerLock task_runner_lock(task_runner_lock_);
+ base::internal::CheckedAutoLock task_runner_lock(task_runner_lock_);
if (task_runner_)
InitializeThreadTaskRunnerHandle();
}
@@ -117,7 +117,7 @@
}
void ThreadControllerWithMessagePumpImpl::ScheduleWork() {
- base::internal::SchedulerLock::AssertNoLockHeldOnCurrentThread();
+ base::internal::CheckedLock::AssertNoLockHeldOnCurrentThread();
if (work_deduplicator_.OnWorkRequested() ==
ShouldScheduleWork::kScheduleImmediate) {
pump_->ScheduleWork();
@@ -158,7 +158,7 @@
void ThreadControllerWithMessagePumpImpl::SetDefaultTaskRunner(
scoped_refptr<SingleThreadTaskRunner> task_runner) {
- base::internal::AutoSchedulerLock lock(task_runner_lock_);
+ base::internal::CheckedAutoLock lock(task_runner_lock_);
task_runner_ = task_runner;
if (associated_thread_->IsBound()) {
DCHECK(associated_thread_->IsBoundToCurrentThread());
@@ -177,7 +177,7 @@
scoped_refptr<SingleThreadTaskRunner>
ThreadControllerWithMessagePumpImpl::GetDefaultTaskRunner() {
- base::internal::AutoSchedulerLock lock(task_runner_lock_);
+ base::internal::CheckedAutoLock lock(task_runner_lock_);
return task_runner_;
}
diff --git a/base/task/sequence_manager/thread_controller_with_message_pump_impl.h b/base/task/sequence_manager/thread_controller_with_message_pump_impl.h
index af1ec41f..8f4e5b16 100644
--- a/base/task/sequence_manager/thread_controller_with_message_pump_impl.h
+++ b/base/task/sequence_manager/thread_controller_with_message_pump_impl.h
@@ -10,13 +10,13 @@
#include "base/message_loop/message_pump.h"
#include "base/message_loop/work_id_provider.h"
#include "base/run_loop.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/common/task_annotator.h"
#include "base/task/sequence_manager/associated_thread_id.h"
#include "base/task/sequence_manager/sequence_manager_impl.h"
#include "base/task/sequence_manager/sequenced_task_source.h"
#include "base/task/sequence_manager/thread_controller.h"
#include "base/task/sequence_manager/work_deduplicator.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/thread_annotations.h"
#include "base/threading/platform_thread.h"
#include "base/threading/sequence_local_storage_map.h"
@@ -144,7 +144,7 @@
scoped_refptr<AssociatedThreadId> associated_thread_;
MainThreadOnly main_thread_only_;
- mutable base::internal::SchedulerLock task_runner_lock_;
+ mutable base::internal::CheckedLock task_runner_lock_;
scoped_refptr<SingleThreadTaskRunner> task_runner_
GUARDED_BY(task_runner_lock_);
diff --git a/base/task/thread_pool/delayed_task_manager.cc b/base/task/thread_pool/delayed_task_manager.cc
index a805bec..9807d57 100644
--- a/base/task/thread_pool/delayed_task_manager.cc
+++ b/base/task/thread_pool/delayed_task_manager.cc
@@ -63,7 +63,7 @@
TimeTicks process_ripe_tasks_time;
{
- AutoSchedulerLock auto_lock(queue_lock_);
+ CheckedAutoLock auto_lock(queue_lock_);
DCHECK(!service_thread_task_runner_);
service_thread_task_runner_ = std::move(service_thread_task_runner);
process_ripe_tasks_time = GetTimeToScheduleProcessRipeTasksLockRequired();
@@ -83,7 +83,7 @@
CHECK(task.task);
TimeTicks process_ripe_tasks_time;
{
- AutoSchedulerLock auto_lock(queue_lock_);
+ CheckedAutoLock auto_lock(queue_lock_);
delayed_task_queue_.insert(DelayedTask(std::move(task),
std::move(post_task_now_callback),
std::move(task_runner)));
@@ -100,7 +100,7 @@
TimeTicks process_ripe_tasks_time;
{
- AutoSchedulerLock auto_lock(queue_lock_);
+ CheckedAutoLock auto_lock(queue_lock_);
const TimeTicks now = tick_clock_->NowTicks();
while (!delayed_task_queue_.empty() &&
delayed_task_queue_.Min().task.delayed_run_time <= now) {
diff --git a/base/task/thread_pool/delayed_task_manager.h b/base/task/thread_pool/delayed_task_manager.h
index f83901719..c5cb475 100644
--- a/base/task/thread_pool/delayed_task_manager.h
+++ b/base/task/thread_pool/delayed_task_manager.h
@@ -14,8 +14,8 @@
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/atomic_flag.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/common/intrusive_heap.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/task.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
@@ -116,7 +116,7 @@
// it is never modified. It is therefore safe to access
// |service_thread_task_runner_| without synchronization once it is observed
// that it is non-null.
- SchedulerLock queue_lock_;
+ CheckedLock queue_lock_;
DISALLOW_COPY_AND_ASSIGN(DelayedTaskManager);
};
diff --git a/base/task/thread_pool/platform_native_worker_pool.cc b/base/task/thread_pool/platform_native_worker_pool.cc
index 552369b..fb2f40d 100644
--- a/base/task/thread_pool/platform_native_worker_pool.cc
+++ b/base/task/thread_pool/platform_native_worker_pool.cc
@@ -18,7 +18,7 @@
public:
ScopedWorkersExecutor(PlatformNativeWorkerPool* outer) : outer_(outer) {}
~ScopedWorkersExecutor() {
- SchedulerLock::AssertNoLockHeldOnCurrentThread();
+ CheckedLock::AssertNoLockHeldOnCurrentThread();
for (size_t i = 0; i < num_threadpool_work_to_submit_; ++i)
outer_->SubmitWork();
@@ -60,7 +60,7 @@
StartImpl();
ScopedWorkersExecutor executor(this);
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(!started_);
started_ = true;
EnsureEnoughWorkersLockRequired(&executor);
@@ -87,7 +87,7 @@
ScopedReenqueueExecutor reenqueue_executor;
auto task_source_and_transaction =
TaskSourceAndTransaction::FromTaskSource(std::move(task_source));
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
ReEnqueueTaskSourceLockRequired(&workers_executor, &reenqueue_executor,
std::move(task_source_and_transaction));
}
@@ -95,7 +95,7 @@
}
scoped_refptr<TaskSource> PlatformNativeWorkerPool::GetWork() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK_GT(num_pending_threadpool_work_, 0U);
--num_pending_threadpool_work_;
// There can be more pending threadpool work than TaskSources in the
@@ -158,7 +158,7 @@
void PlatformNativeWorkerPool::DidUpdateCanRunPolicy() {
ScopedWorkersExecutor executor(this);
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
EnsureEnoughWorkersLockRequired(&executor);
}
diff --git a/base/task/thread_pool/priority_queue.h b/base/task/thread_pool/priority_queue.h
index 1ec5c7d..be4683f1 100644
--- a/base/task/thread_pool/priority_queue.h
+++ b/base/task/thread_pool/priority_queue.h
@@ -10,8 +10,8 @@
#include "base/base_export.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/common/intrusive_heap.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task_source.h"
diff --git a/base/task/thread_pool/scheduler_lock.h b/base/task/thread_pool/scheduler_lock.h
deleted file mode 100644
index f39b206..0000000
--- a/base/task/thread_pool/scheduler_lock.h
+++ /dev/null
@@ -1,131 +0,0 @@
-// 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_THREAD_POOL_SCHEDULER_LOCK_H_
-#define BASE_TASK_THREAD_POOL_SCHEDULER_LOCK_H_
-
-#include <memory>
-
-#include "base/base_export.h"
-#include "base/macros.h"
-#include "base/synchronization/condition_variable.h"
-#include "base/synchronization/lock.h"
-#include "base/task/thread_pool/scheduler_lock_impl.h"
-#include "base/thread_annotations.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.
-// Okay if a universal predecessor is acquired.
-//
-// 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
-// either |predecessor| or a universal predecessor. Okay if there
-// was no previous lock acquired.
-//
-// SchedulerLock(UniversalPredecessor universal_predecessor)
-// Constructor for a lock that will allow the acquisition of any lock after
-// it, without needing to explicitly be named a predecessor. Can only be
-// acquired if no locks are currently held by this thread.
-// DCHECKs
-// On Acquisition if any scheduler lock is acquired on this thread.
-//
-// void Acquire()
-// Acquires the lock.
-//
-// void Release()
-// Releases the lock.
-//
-// void AssertAcquired().
-// DCHECKs if the lock is not acquired.
-//
-// std::unique_ptr<ConditionVariable> CreateConditionVariable()
-// Creates a condition variable using this as a lock.
-
-#if DCHECK_IS_ON()
-class LOCKABLE SchedulerLock : public SchedulerLockImpl {
- public:
- SchedulerLock() = default;
- explicit SchedulerLock(const SchedulerLock* predecessor)
- : SchedulerLockImpl(predecessor) {}
- explicit SchedulerLock(UniversalPredecessor universal_predecessor)
- : SchedulerLockImpl(universal_predecessor) {}
-};
-#else // DCHECK_IS_ON()
-class LOCKABLE SchedulerLock : public Lock {
- public:
- SchedulerLock() = default;
- explicit SchedulerLock(const SchedulerLock*) {}
- explicit SchedulerLock(UniversalPredecessor) {}
- static void AssertNoLockHeldOnCurrentThread() {}
-
- std::unique_ptr<ConditionVariable> CreateConditionVariable() {
- return std::unique_ptr<ConditionVariable>(new ConditionVariable(this));
- }
-};
-#endif // DCHECK_IS_ON()
-
-// Provides the same functionality as base::AutoLock for SchedulerLock.
-using AutoSchedulerLock = internal::BasicAutoLock<SchedulerLock>;
-
-// Provides the same functionality as base::AutoUnlock for SchedulerLock.
-using AutoSchedulerUnlock = internal::BasicAutoUnlock<SchedulerLock>;
-
-// Provides the same functionality as base::AutoLockMaybe for SchedulerLock.
-using AutoSchedulerLockMaybe = internal::BasicAutoLockMaybe<SchedulerLock>;
-
-// Informs the clang thread safety analysis that an aliased lock is acquired.
-// Because the clang thread safety analysis doesn't understand aliased locks
-// [1], this code wouldn't compile without AnnotateAcquiredLockAlias:
-//
-// class Example {
-// public:
-// SchedulerLock lock_;
-// int value = 0 GUARDED_BY(lock_);
-// };
-//
-// Example example;
-// SchedulerLock* acquired = &example.lock_;
-// AutoSchedulerLock auto_lock(*acquired);
-// AnnotateAcquiredLockAlias annotate(*acquired, example.lock_);
-// example.value = 42; // Doesn't compile without |annotate|.
-//
-// [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#no-alias-analysis
-class SCOPED_LOCKABLE AnnotateAcquiredLockAlias {
- public:
- // |acquired_lock| is an acquired lock. |lock_alias| is an alias of
- // |acquired_lock|.
- AnnotateAcquiredLockAlias(const SchedulerLock& acquired_lock,
- const SchedulerLock& lock_alias)
- EXCLUSIVE_LOCK_FUNCTION(lock_alias)
- : acquired_lock_(acquired_lock) {
- DCHECK_EQ(&acquired_lock, &lock_alias);
- acquired_lock_.AssertAcquired();
- }
- ~AnnotateAcquiredLockAlias() UNLOCK_FUNCTION() {
- acquired_lock_.AssertAcquired();
- }
-
- private:
- const SchedulerLock& acquired_lock_;
-
- DISALLOW_COPY_AND_ASSIGN(AnnotateAcquiredLockAlias);
-};
-
-} // namespace internal
-} // namespace base
-
-#endif // BASE_TASK_THREAD_POOL_SCHEDULER_LOCK_H_
diff --git a/base/task/thread_pool/scheduler_parallel_task_runner.cc b/base/task/thread_pool/scheduler_parallel_task_runner.cc
index 35c41541..f83395a8 100644
--- a/base/task/thread_pool/scheduler_parallel_task_runner.cc
+++ b/base/task/thread_pool/scheduler_parallel_task_runner.cc
@@ -29,7 +29,7 @@
traits_, this, TaskSourceExecutionMode::kParallel);
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
sequences_.insert(sequence.get());
}
@@ -44,7 +44,7 @@
void SchedulerParallelTaskRunner::UnregisterSequence(Sequence* sequence) {
DCHECK(sequence);
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
sequences_.erase(sequence);
}
diff --git a/base/task/thread_pool/scheduler_parallel_task_runner.h b/base/task/thread_pool/scheduler_parallel_task_runner.h
index 40ca662..ede136e 100644
--- a/base/task/thread_pool/scheduler_parallel_task_runner.h
+++ b/base/task/thread_pool/scheduler_parallel_task_runner.h
@@ -9,8 +9,8 @@
#include "base/callback_forward.h"
#include "base/containers/flat_set.h"
#include "base/location.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/task_traits.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task_runner.h"
#include "base/thread_annotations.h"
#include "base/time/time.h"
@@ -45,7 +45,7 @@
const TaskTraits traits_;
SchedulerTaskRunnerDelegate* const scheduler_task_runner_delegate_;
- SchedulerLock lock_;
+ CheckedLock lock_;
// List of alive Sequences instantiated by this SchedulerParallelTaskRunner.
// Sequences are added when they are instantiated, and removed when they are
diff --git a/base/task/thread_pool/scheduler_single_thread_task_runner_manager.cc b/base/task/thread_pool/scheduler_single_thread_task_runner_manager.cc
index a72fd18..1d355d4 100644
--- a/base/task/thread_pool/scheduler_single_thread_task_runner_manager.cc
+++ b/base/task/thread_pool/scheduler_single_thread_task_runner_manager.cc
@@ -101,7 +101,7 @@
}
scoped_refptr<TaskSource> GetWork(SchedulerWorker* worker) override {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(worker_awake_);
auto task_source = GetWorkLockRequired(worker);
if (task_source == nullptr) {
@@ -143,7 +143,7 @@
void DidUpdateCanRunPolicy() {
bool should_wakeup = false;
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
if (!worker_awake_ && CanRunNextTaskSource()) {
should_wakeup = true;
worker_awake_ = true;
@@ -154,7 +154,7 @@
}
void EnableFlushPriorityQueueTaskSourcesOnDestroyForTesting() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
priority_queue_.EnableFlushTaskSourcesOnDestroyForTesting();
}
@@ -169,7 +169,7 @@
const TrackedRef<TaskTracker>& task_tracker() { return task_tracker_; }
- SchedulerLock lock_;
+ CheckedLock lock_;
bool worker_awake_ GUARDED_BY(lock_) = false;
private:
@@ -177,7 +177,7 @@
// Returns true iff the worker must wakeup, i.e. task source is allowed to run
// and the worker was not awake.
bool EnqueueTaskSource(TaskSourceAndTransaction task_source_and_transaction) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
priority_queue_.Push(std::move(task_source_and_transaction.task_source),
task_source_and_transaction.transaction.GetSortKey());
if (!worker_awake_ && CanRunNextTaskSource()) {
@@ -239,7 +239,7 @@
// * Both SchedulerWorkerDelegate::GetWork() and the Windows Message Queue
// have work:
// Process task sources from each source round-robin style.
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(worker_awake_);
scoped_refptr<TaskSource> task_source;
if (get_work_first_) {
@@ -249,7 +249,7 @@
}
if (!task_source) {
- AutoSchedulerUnlock auto_unlock(lock_);
+ CheckedAutoUnlock auto_unlock(lock_);
task_source = GetWorkFromWindowsMessageQueue();
if (task_source)
get_work_first_ = true;
@@ -282,7 +282,7 @@
DWORD reason = MsgWaitForMultipleObjectsEx(
1, &wake_up_event_handle, milliseconds_wait, QS_ALLINPUT, 0);
if (reason != WAIT_OBJECT_0) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
worker_awake_ = true;
}
}
@@ -462,7 +462,7 @@
decltype(workers_) workers_to_start;
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
started_ = true;
workers_to_start = workers_;
}
@@ -481,7 +481,7 @@
decltype(workers_) workers_to_update;
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
if (!started_)
return;
workers_to_update = workers_;
@@ -547,7 +547,7 @@
bool new_worker = false;
bool started;
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
if (!worker) {
const auto& environment_params =
kEnvironmentParams[GetEnvironmentIndexForTraits(traits)];
@@ -575,7 +575,7 @@
void SchedulerSingleThreadTaskRunnerManager::JoinForTesting() {
decltype(workers_) local_workers;
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
local_workers = std::move(workers_);
}
@@ -586,7 +586,7 @@
}
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(workers_.empty())
<< "New worker(s) unexpectedly registered during join.";
workers_ = std::move(local_workers);
@@ -665,10 +665,10 @@
void SchedulerSingleThreadTaskRunnerManager::UnregisterSchedulerWorker(
SchedulerWorker* worker) {
- // Cleanup uses a SchedulerLock, so call Cleanup() after releasing |lock_|.
+ // Cleanup uses a CheckedLock, so call Cleanup() after releasing |lock_|.
scoped_refptr<SchedulerWorker> worker_to_destroy;
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
// Skip when joining (the join logic takes care of the rest).
if (workers_.empty())
@@ -688,7 +688,7 @@
decltype(shared_com_scheduler_workers_) local_shared_com_scheduler_workers;
#endif
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
for (size_t i = 0; i < base::size(shared_scheduler_workers_); ++i) {
for (size_t j = 0; j < base::size(shared_scheduler_workers_[i]); ++j) {
local_shared_scheduler_workers[i][j] = shared_scheduler_workers_[i][j];
diff --git a/base/task/thread_pool/scheduler_single_thread_task_runner_manager.h b/base/task/thread_pool/scheduler_single_thread_task_runner_manager.h
index ef6ae77..bb665f6 100644
--- a/base/task/thread_pool/scheduler_single_thread_task_runner_manager.h
+++ b/base/task/thread_pool/scheduler_single_thread_task_runner_manager.h
@@ -12,9 +12,9 @@
#include "base/base_export.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/single_thread_task_runner_thread_mode.h"
#include "base/task/thread_pool/environment_config.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/tracked_ref.h"
#include "base/thread_annotations.h"
#include "base/threading/platform_thread.h"
@@ -130,7 +130,7 @@
// function. Set in Start() and never modified afterwards.
SchedulerWorkerObserver* scheduler_worker_observer_ = nullptr;
- SchedulerLock lock_;
+ CheckedLock lock_;
std::vector<scoped_refptr<SchedulerWorker>> workers_ GUARDED_BY(lock_);
int next_worker_id_ GUARDED_BY(lock_) = 0;
diff --git a/base/task/thread_pool/scheduler_worker.cc b/base/task/thread_pool/scheduler_worker.cc
index d105fb9c..83309f747 100644
--- a/base/task/thread_pool/scheduler_worker.cc
+++ b/base/task/thread_pool/scheduler_worker.cc
@@ -42,7 +42,7 @@
ThreadPriority priority_hint,
std::unique_ptr<Delegate> delegate,
TrackedRef<TaskTracker> task_tracker,
- const SchedulerLock* predecessor_lock,
+ const CheckedLock* predecessor_lock,
SchedulerBackwardCompatibility backward_compatibility)
: thread_lock_(predecessor_lock),
delegate_(std::move(delegate)),
@@ -63,8 +63,8 @@
bool SchedulerWorker::Start(
SchedulerWorkerObserver* scheduler_worker_observer) {
- SchedulerLock::AssertNoLockHeldOnCurrentThread();
- AutoSchedulerLock auto_lock(thread_lock_);
+ CheckedLock::AssertNoLockHeldOnCurrentThread();
+ CheckedAutoLock auto_lock(thread_lock_);
DCHECK(thread_handle_.is_null());
if (should_exit_.IsSet() || join_called_for_testing_.IsSet())
@@ -91,7 +91,7 @@
// Signalling an event can deschedule the current thread. Since being
// descheduled while holding a lock is undesirable (https://crbug.com/890978),
// assert that no lock is held by the current thread.
- SchedulerLock::AssertNoLockHeldOnCurrentThread();
+ CheckedLock::AssertNoLockHeldOnCurrentThread();
// Calling WakeUp() after Cleanup() or Join() is wrong because the
// SchedulerWorker cannot run more tasks.
DCHECK(!join_called_for_testing_.IsSet());
@@ -107,7 +107,7 @@
PlatformThreadHandle thread_handle;
{
- AutoSchedulerLock auto_lock(thread_lock_);
+ CheckedAutoLock auto_lock(thread_lock_);
if (thread_handle_.is_null())
return;
@@ -121,12 +121,12 @@
}
bool SchedulerWorker::ThreadAliveForTesting() const {
- AutoSchedulerLock auto_lock(thread_lock_);
+ CheckedAutoLock auto_lock(thread_lock_);
return !thread_handle_.is_null();
}
SchedulerWorker::~SchedulerWorker() {
- AutoSchedulerLock auto_lock(thread_lock_);
+ CheckedAutoLock auto_lock(thread_lock_);
// If |thread_handle_| wasn't joined, detach it.
if (!thread_handle_.is_null()) {
@@ -142,19 +142,19 @@
}
void SchedulerWorker::BeginUnusedPeriod() {
- AutoSchedulerLock auto_lock(thread_lock_);
+ CheckedAutoLock auto_lock(thread_lock_);
DCHECK(last_used_time_.is_null());
last_used_time_ = TimeTicks::Now();
}
void SchedulerWorker::EndUnusedPeriod() {
- AutoSchedulerLock auto_lock(thread_lock_);
+ CheckedAutoLock auto_lock(thread_lock_);
DCHECK(!last_used_time_.is_null());
last_used_time_ = TimeTicks();
}
TimeTicks SchedulerWorker::GetLastUsedTime() const {
- AutoSchedulerLock auto_lock(thread_lock_);
+ CheckedAutoLock auto_lock(thread_lock_);
return last_used_time_;
}
diff --git a/base/task/thread_pool/scheduler_worker.h b/base/task/thread_pool/scheduler_worker.h
index e5f9eb9b..f85e8583 100644
--- a/base/task/thread_pool/scheduler_worker.h
+++ b/base/task/thread_pool/scheduler_worker.h
@@ -12,7 +12,7 @@
#include "base/memory/ref_counted.h"
#include "base/synchronization/atomic_flag.h"
#include "base/synchronization/waitable_event.h"
-#include "base/task/thread_pool/scheduler_lock.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/thread_pool/scheduler_worker_params.h"
#include "base/task/thread_pool/task_source.h"
#include "base/task/thread_pool/tracked_ref.h"
@@ -111,7 +111,7 @@
SchedulerWorker(ThreadPriority priority_hint,
std::unique_ptr<Delegate> delegate,
TrackedRef<TaskTracker> task_tracker,
- const SchedulerLock* predecessor_lock = nullptr,
+ const CheckedLock* predecessor_lock = nullptr,
SchedulerBackwardCompatibility backward_compatibility =
SchedulerBackwardCompatibility::DISABLED);
@@ -208,7 +208,7 @@
// thread is created and the second access occurs on the thread.
scoped_refptr<SchedulerWorker> self_;
- mutable SchedulerLock thread_lock_;
+ mutable CheckedLock thread_lock_;
// Handle for the thread managed by |this|.
PlatformThreadHandle thread_handle_ GUARDED_BY(thread_lock_);
diff --git a/base/task/thread_pool/scheduler_worker_pool.cc b/base/task/thread_pool/scheduler_worker_pool.cc
index dbb6e1b..ca44ea6d 100644
--- a/base/task/thread_pool/scheduler_worker_pool.cc
+++ b/base/task/thread_pool/scheduler_worker_pool.cc
@@ -115,7 +115,7 @@
bool SchedulerWorkerPool::RemoveTaskSource(
scoped_refptr<TaskSource> task_source) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return priority_queue_.RemoveTaskSource(std::move(task_source));
}
@@ -143,7 +143,7 @@
void SchedulerWorkerPool::UpdateSortKeyImpl(
BaseScopedWorkersExecutor* executor,
TaskSourceAndTransaction task_source_and_transaction) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
priority_queue_.UpdateSortKey(std::move(task_source_and_transaction));
EnsureEnoughWorkersLockRequired(executor);
}
@@ -151,7 +151,7 @@
void SchedulerWorkerPool::PushTaskSourceAndWakeUpWorkersImpl(
BaseScopedWorkersExecutor* executor,
TaskSourceAndTransaction task_source_and_transaction) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(!replacement_pool_);
priority_queue_.Push(std::move(task_source_and_transaction.task_source),
task_source_and_transaction.transaction.GetSortKey());
@@ -160,8 +160,8 @@
void SchedulerWorkerPool::InvalidateAndHandoffAllTaskSourcesToOtherPool(
SchedulerWorkerPool* destination_pool) {
- AutoSchedulerLock current_pool_lock(lock_);
- AutoSchedulerLock destination_pool_lock(destination_pool->lock_);
+ CheckedAutoLock current_pool_lock(lock_);
+ CheckedAutoLock destination_pool_lock(destination_pool->lock_);
destination_pool->priority_queue_ = std::move(priority_queue_);
replacement_pool_ = destination_pool;
}
diff --git a/base/task/thread_pool/scheduler_worker_pool.h b/base/task/thread_pool/scheduler_worker_pool.h
index 75c14071..0b85a3e 100644
--- a/base/task/thread_pool/scheduler_worker_pool.h
+++ b/base/task/thread_pool/scheduler_worker_pool.h
@@ -7,8 +7,8 @@
#include "base/base_export.h"
#include "base/memory/ref_counted.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/thread_pool/priority_queue.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/sequence.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/task_source.h"
@@ -192,7 +192,7 @@
// atomic, nor immutable after start. Since this lock is a bottleneck to post
// and schedule work, only simple data structure manipulations are allowed
// within its scope (no thread creation or wake up).
- mutable SchedulerLock lock_;
+ mutable CheckedLock lock_;
// PriorityQueue from which all threads of this worker pool get work.
PriorityQueue priority_queue_ GUARDED_BY(lock_);
diff --git a/base/task/thread_pool/scheduler_worker_pool_impl.cc b/base/task/thread_pool/scheduler_worker_pool_impl.cc
index 0da65e8..0f8fd5b 100644
--- a/base/task/thread_pool/scheduler_worker_pool_impl.cc
+++ b/base/task/thread_pool/scheduler_worker_pool_impl.cc
@@ -111,7 +111,7 @@
workers_to_start_.AddWorker(std::move(worker));
}
- void Flush(SchedulerLock* held_lock) {
+ void Flush(CheckedLock* held_lock) {
static_assert(std::is_pod<BaseScopedWorkersExecutor>::value &&
sizeof(BaseScopedWorkersExecutor) == 1,
"Must add BaseScopedWorkersExecutor::Flush() if it becomes "
@@ -119,7 +119,7 @@
if (workers_to_wake_up_.empty() && workers_to_start_.empty())
return;
- AutoSchedulerUnlock auto_unlock(*held_lock);
+ CheckedAutoUnlock auto_unlock(*held_lock);
FlushImpl();
workers_to_wake_up_.clear();
workers_to_start_.clear();
@@ -173,7 +173,7 @@
};
void FlushImpl() {
- SchedulerLock::AssertNoLockHeldOnCurrentThread();
+ CheckedLock::AssertNoLockHeldOnCurrentThread();
// Wake up workers.
workers_to_wake_up_.ForEachWorker(
@@ -239,9 +239,9 @@
return read_any().is_running_best_effort_task;
}
- // Exposed for AnnotateSchedulerLockAcquired in
+ // Exposed for AnnotateCheckedLockAcquired in
// SchedulerWorkerPoolImpl::AdjustMaxTasks()
- const SchedulerLock& lock() const LOCK_RETURNED(outer_->lock_) {
+ const CheckedLock& lock() const LOCK_RETURNED(outer_->lock_) {
return outer_->lock_;
}
@@ -394,7 +394,7 @@
ScopedWorkersExecutor executor(this);
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(workers_.empty());
@@ -451,7 +451,7 @@
size_t SchedulerWorkerPoolImpl::GetMaxConcurrentNonBlockedTasksDeprecated()
const {
#if DCHECK_IS_ON()
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK_NE(after_start().initial_max_tasks, 0U)
<< "GetMaxConcurrentTasksDeprecated() should only be called after the "
<< "worker pool has started.";
@@ -460,7 +460,7 @@
}
void SchedulerWorkerPoolImpl::WaitForWorkersIdleForTesting(size_t n) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
#if DCHECK_IS_ON()
DCHECK(!some_workers_cleaned_up_for_testing_)
@@ -473,12 +473,12 @@
}
void SchedulerWorkerPoolImpl::WaitForAllWorkersIdleForTesting() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
WaitForWorkersIdleLockRequiredForTesting(workers_.size());
}
void SchedulerWorkerPoolImpl::WaitForWorkersCleanedUpForTesting(size_t n) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
if (!num_workers_cleaned_up_for_testing_cv_)
num_workers_cleaned_up_for_testing_cv_ = lock_.CreateConditionVariable();
@@ -496,7 +496,7 @@
decltype(workers_) workers_copy;
{
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
priority_queue_.EnableFlushTaskSourcesOnDestroyForTesting();
DCHECK_GT(workers_.size(), size_t(0)) << "Joined an unstarted worker pool.";
@@ -513,29 +513,29 @@
for (const auto& worker : workers_copy)
worker->JoinForTesting();
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(workers_ == workers_copy);
// Release |workers_| to clear their TrackedRef against |this|.
workers_.clear();
}
size_t SchedulerWorkerPoolImpl::NumberOfWorkersForTesting() const {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return workers_.size();
}
size_t SchedulerWorkerPoolImpl::GetMaxTasksForTesting() const {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return max_tasks_;
}
size_t SchedulerWorkerPoolImpl::NumberOfIdleWorkersForTesting() const {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return idle_workers_stack_.Size();
}
void SchedulerWorkerPoolImpl::ReportHeartbeatMetrics() const {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
num_workers_histogram_->Add(workers_.size());
num_active_workers_histogram_->Add(workers_.size() -
@@ -565,7 +565,7 @@
{
#if DCHECK_IS_ON()
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
DCHECK(ContainsWorker(outer_->workers_, worker));
#endif
}
@@ -601,7 +601,7 @@
DCHECK(!read_worker().is_running_best_effort_task);
ScopedWorkersExecutor executor(outer_.get());
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
DCHECK(ContainsWorker(outer_->workers_, worker));
@@ -670,7 +670,7 @@
ScopedWorkersExecutor workers_executor(outer_.get());
ScopedReenqueueExecutor reenqueue_executor;
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
DCHECK(!incremented_max_tasks_since_blocked_);
@@ -791,7 +791,7 @@
#if DCHECK_IS_ON()
{
bool shutdown_complete = outer_->task_tracker_->IsShutdownComplete();
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
// |worker| should already have been removed from the idle workers stack and
// |workers_| by the time the thread is about to exit. (except in the cases
@@ -839,7 +839,7 @@
return;
{
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
// Don't do anything if a MAY_BLOCK ScopedBlockingCall instantiated in the
// same scope already caused the max tasks to be incremented.
@@ -863,7 +863,7 @@
DCHECK_CALLED_ON_VALID_THREAD(worker_thread_checker_);
DCHECK(worker_only().is_running_task);
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
if (incremented_max_tasks_since_blocked_) {
outer_->DecrementMaxTasksLockRequired(
read_worker().is_running_best_effort_task);
@@ -883,7 +883,7 @@
DCHECK(worker_only().is_running_task);
ScopedWorkersExecutor executor(outer_.get());
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
DCHECK(!incremented_max_tasks_since_blocked_);
DCHECK(read_worker().may_block_start_time.is_null());
@@ -900,7 +900,7 @@
DCHECK(worker_only().is_running_task);
ScopedWorkersExecutor executor(outer_.get());
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
DCHECK(!incremented_max_tasks_since_blocked_);
DCHECK(read_worker().may_block_start_time.is_null());
@@ -1047,7 +1047,7 @@
void SchedulerWorkerPoolImpl::DidUpdateCanRunPolicy() {
ScopedWorkersExecutor executor(this);
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
EnsureEnoughWorkersLockRequired(&executor);
}
@@ -1092,7 +1092,7 @@
after_start().service_thread_task_runner->RunsTasksInCurrentSequence());
ScopedWorkersExecutor executor(this);
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
DCHECK(adjust_max_tasks_posted_);
adjust_max_tasks_posted_ = false;
diff --git a/base/task/thread_pool/scheduler_worker_pool_unittest.cc b/base/task/thread_pool/scheduler_worker_pool_unittest.cc
index 1f615b3..7fd55c4 100644
--- a/base/task/thread_pool/scheduler_worker_pool_unittest.cc
+++ b/base/task/thread_pool/scheduler_worker_pool_unittest.cc
@@ -382,7 +382,7 @@
TEST_P(ThreadPoolWorkerPoolTest, UpdatePriorityBestEffortToUserBlocking) {
StartWorkerPool();
- SchedulerLock num_tasks_running_lock;
+ CheckedLock num_tasks_running_lock;
std::unique_ptr<ConditionVariable> num_tasks_running_cv =
num_tasks_running_lock.CreateConditionVariable();
size_t num_tasks_running = 0;
@@ -398,13 +398,13 @@
FROM_HERE, BindLambdaForTesting([&]() {
// Increment the number of tasks running.
{
- AutoSchedulerLock auto_lock(num_tasks_running_lock);
+ CheckedAutoLock auto_lock(num_tasks_running_lock);
++num_tasks_running;
}
num_tasks_running_cv->Broadcast();
// Wait until all posted tasks are running.
- AutoSchedulerLock auto_lock(num_tasks_running_lock);
+ CheckedAutoLock auto_lock(num_tasks_running_lock);
while (num_tasks_running < kMaxTasks) {
ScopedClearBlockingObserverForTesting clear_blocking_observer;
ScopedAllowBaseSyncPrimitivesForTesting allow_base_sync_primitives;
@@ -415,7 +415,7 @@
// Wait until |kMaxBestEffort| tasks start running.
{
- AutoSchedulerLock auto_lock(num_tasks_running_lock);
+ CheckedAutoLock auto_lock(num_tasks_running_lock);
while (num_tasks_running < kMaxBestEffortTasks)
num_tasks_running_cv->Wait();
}
@@ -429,7 +429,7 @@
// tasks lower than |kMaxTasks|.
static_assert(kMaxBestEffortTasks < kMaxTasks, "");
{
- AutoSchedulerLock auto_lock(num_tasks_running_lock);
+ CheckedAutoLock auto_lock(num_tasks_running_lock);
while (num_tasks_running < kMaxTasks)
num_tasks_running_cv->Wait();
}
diff --git a/base/task/thread_pool/scheduler_worker_unittest.cc b/base/task/thread_pool/scheduler_worker_unittest.cc
index a43da7e..4882fbd5 100644
--- a/base/task/thread_pool/scheduler_worker_unittest.cc
+++ b/base/task/thread_pool/scheduler_worker_unittest.cc
@@ -16,8 +16,8 @@
#include "base/memory/ref_counted.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/waitable_event.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/thread_pool/environment_config.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/scheduler_worker_observer.h"
#include "base/task/thread_pool/sequence.h"
#include "base/task/thread_pool/task.h"
@@ -96,34 +96,34 @@
// Wait until GetWork() has been called |num_get_work| times.
void WaitForNumGetWork(size_t num_get_work) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
while (num_get_work_ < num_get_work)
num_get_work_cv_->Wait();
}
void SetMaxGetWork(size_t max_get_work) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
max_get_work_ = max_get_work;
}
void SetNumSequencesToCreate(size_t num_sequences_to_create) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
EXPECT_EQ(0U, num_sequences_to_create_);
num_sequences_to_create_ = num_sequences_to_create;
}
size_t NumRunTasks() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return num_run_tasks_;
}
std::vector<scoped_refptr<TaskSource>> CreatedTaskSources() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return created_sequences_;
}
std::vector<scoped_refptr<TaskSource>> DidRunTaskSequences() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return did_run_task_sequences_;
}
@@ -146,7 +146,7 @@
// Without synchronization, OnMainEntry() could be called twice without
// generating an error.
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
EXPECT_FALSE(outer_->main_entry_called_.IsSignaled());
outer_->main_entry_called_.Signal();
}
@@ -156,7 +156,7 @@
EXPECT_EQ(outer_->worker_.get(), worker);
{
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
// Increment the number of times that this method has been called.
++outer_->num_get_work_;
@@ -189,7 +189,7 @@
{
// Add the Sequence to the vector of created Sequences.
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
outer_->created_sequences_.push_back(sequence);
}
@@ -202,7 +202,7 @@
// execution.
void DidRunTask(scoped_refptr<TaskSource> sequence) override {
{
- AutoSchedulerLock auto_lock(expect_did_run_task_lock_);
+ CheckedAutoLock auto_lock(expect_did_run_task_lock_);
EXPECT_TRUE(expect_did_run_task_);
expect_did_run_task_ = false;
}
@@ -223,7 +223,7 @@
}
// Add |sequence| to |did_run_task_sequences_|.
- AutoSchedulerLock auto_lock(outer_->lock_);
+ CheckedAutoLock auto_lock(outer_->lock_);
outer_->did_run_task_sequences_.push_back(std::move(sequence));
EXPECT_LE(outer_->did_run_task_sequences_.size(),
outer_->created_sequences_.size());
@@ -234,19 +234,19 @@
// Expect a call to DidRunTask() before the next call to any other method of
// this delegate.
void ExpectCallToDidRunTask() {
- AutoSchedulerLock auto_lock(expect_did_run_task_lock_);
+ CheckedAutoLock auto_lock(expect_did_run_task_lock_);
expect_did_run_task_ = true;
}
bool IsCallToDidRunTaskExpected() const {
- AutoSchedulerLock auto_lock(expect_did_run_task_lock_);
+ CheckedAutoLock auto_lock(expect_did_run_task_lock_);
return expect_did_run_task_;
}
ThreadPoolWorkerTest* outer_;
// Synchronizes access to |expect_did_run_task_|.
- mutable SchedulerLock expect_did_run_task_lock_;
+ mutable CheckedLock expect_did_run_task_lock_;
// Whether the next method called on this delegate should be DidRunTask().
bool expect_did_run_task_ = false;
@@ -255,7 +255,7 @@
};
void RunTaskCallback() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
++num_run_tasks_;
EXPECT_LE(num_run_tasks_, created_sequences_.size());
}
@@ -263,7 +263,7 @@
TaskTracker task_tracker_ = {"Test"};
// Synchronizes access to all members below.
- mutable SchedulerLock lock_;
+ mutable CheckedLock lock_;
// Signaled once OnMainEntry() has been called.
WaitableEvent main_entry_called_;
@@ -710,7 +710,7 @@
private:
void VerifyThreadPriority() {
- AutoSchedulerLock auto_lock(expected_thread_priority_lock_);
+ CheckedAutoLock auto_lock(expected_thread_priority_lock_);
EXPECT_EQ(expected_thread_priority_,
PlatformThread::GetCurrentThreadPriority());
}
@@ -719,7 +719,7 @@
WaitableEvent priority_verified_in_get_work_event_;
// Synchronizes access to |expected_thread_priority_|.
- SchedulerLock expected_thread_priority_lock_;
+ CheckedLock expected_thread_priority_lock_;
// Expected thread priority for the next call to OnMainEntry() or GetWork().
ThreadPriority expected_thread_priority_;
diff --git a/base/task/thread_pool/task_source.h b/base/task/thread_pool/task_source.h
index 92f1fda..b61ad8d7 100644
--- a/base/task/thread_pool/task_source.h
+++ b/base/task/thread_pool/task_source.h
@@ -12,9 +12,9 @@
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "base/sequence_token.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/common/intrusive_heap.h"
#include "base/task/task_traits.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task.h"
#include "base/threading/sequence_local_storage_map.h"
@@ -173,7 +173,7 @@
friend class RefCountedThreadSafe<TaskSource>;
// Synchronizes access to all members.
- mutable SchedulerLock lock_{UniversalPredecessor()};
+ mutable CheckedLock lock_{UniversalPredecessor()};
// The TaskSource's position in its current PriorityQueue. Access is protected
// by the PriorityQueue's lock.
diff --git a/base/task/thread_pool/task_tracker.cc b/base/task/thread_pool/task_tracker.cc
index 88cec79..b258169 100644
--- a/base/task/thread_pool/task_tracker.cc
+++ b/base/task/thread_pool/task_tracker.cc
@@ -300,7 +300,7 @@
TaskTracker::~TaskTracker() = default;
void TaskTracker::StartShutdown() {
- AutoSchedulerLock auto_lock(shutdown_lock_);
+ CheckedAutoLock auto_lock(shutdown_lock_);
// This method can only be called once.
DCHECK(!shutdown_event_);
@@ -337,14 +337,14 @@
// Unblock FlushForTesting() and perform the FlushAsyncForTesting callback
// when shutdown completes.
{
- AutoSchedulerLock auto_lock(flush_lock_);
+ CheckedAutoLock auto_lock(flush_lock_);
flush_cv_->Signal();
}
CallFlushCallbackForTesting();
}
void TaskTracker::FlushForTesting() {
- AutoSchedulerLock auto_lock(flush_lock_);
+ CheckedAutoLock auto_lock(flush_lock_);
while (subtle::Acquire_Load(&num_incomplete_undelayed_tasks_) != 0 &&
!IsShutdownComplete()) {
flush_cv_->Wait();
@@ -354,7 +354,7 @@
void TaskTracker::FlushAsyncForTesting(OnceClosure flush_callback) {
DCHECK(flush_callback);
{
- AutoSchedulerLock auto_lock(flush_lock_);
+ CheckedAutoLock auto_lock(flush_lock_);
DCHECK(!flush_callback_for_testing_)
<< "Only one FlushAsyncForTesting() may be pending at any time.";
flush_callback_for_testing_ = std::move(flush_callback);
@@ -449,7 +449,7 @@
}
bool TaskTracker::IsShutdownComplete() const {
- AutoSchedulerLock auto_lock(shutdown_lock_);
+ CheckedAutoLock auto_lock(shutdown_lock_);
return shutdown_event_ && shutdown_event_->IsSignaled();
}
@@ -587,7 +587,7 @@
const bool shutdown_started = state_->IncrementNumTasksBlockingShutdown();
if (shutdown_started) {
- AutoSchedulerLock auto_lock(shutdown_lock_);
+ CheckedAutoLock auto_lock(shutdown_lock_);
// A BLOCK_SHUTDOWN task posted after shutdown has completed is an
// ordering bug. This aims to catch those early.
@@ -668,7 +668,7 @@
}
void TaskTracker::OnBlockingShutdownTasksComplete() {
- AutoSchedulerLock auto_lock(shutdown_lock_);
+ CheckedAutoLock auto_lock(shutdown_lock_);
// This method can only be called after shutdown has started.
DCHECK(state_->HasShutdownStarted());
@@ -683,7 +683,7 @@
DCHECK_GE(new_num_incomplete_undelayed_tasks, 0);
if (new_num_incomplete_undelayed_tasks == 0) {
{
- AutoSchedulerLock auto_lock(flush_lock_);
+ CheckedAutoLock auto_lock(flush_lock_);
flush_cv_->Signal();
}
CallFlushCallbackForTesting();
@@ -693,7 +693,7 @@
void TaskTracker::CallFlushCallbackForTesting() {
OnceClosure flush_callback;
{
- AutoSchedulerLock auto_lock(flush_lock_);
+ CheckedAutoLock auto_lock(flush_lock_);
flush_callback = std::move(flush_callback_for_testing_);
}
if (flush_callback)
diff --git a/base/task/thread_pool/task_tracker.h b/base/task/thread_pool/task_tracker.h
index 91701e8..357ff20 100644
--- a/base/task/thread_pool/task_tracker.h
+++ b/base/task/thread_pool/task_tracker.h
@@ -20,9 +20,9 @@
#include "base/sequence_checker.h"
#include "base/strings/string_piece.h"
#include "base/synchronization/waitable_event.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/common/task_annotator.h"
#include "base/task/task_traits.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/task_source.h"
#include "base/task/thread_pool/tracked_ref.h"
@@ -232,7 +232,7 @@
// because it's atomic, but synchronization is needed to coordinate waking and
// sleeping at the right time. Fully synchronizes access to
// |flush_callback_for_testing_|.
- mutable SchedulerLock flush_lock_;
+ mutable CheckedLock flush_lock_;
// Signaled when |num_incomplete_undelayed_tasks_| is or reaches zero or when
// shutdown completes.
@@ -243,7 +243,7 @@
OnceClosure flush_callback_for_testing_;
// Synchronizes access to shutdown related members below.
- mutable SchedulerLock shutdown_lock_;
+ mutable CheckedLock shutdown_lock_;
// Event instantiated when shutdown starts and signaled when shutdown
// completes.
diff --git a/base/task/thread_pool/task_tracker_unittest.cc b/base/task/thread_pool/task_tracker_unittest.cc
index bf63f84..cbd5adc 100644
--- a/base/task/thread_pool/task_tracker_unittest.cc
+++ b/base/task/thread_pool/task_tracker_unittest.cc
@@ -25,8 +25,8 @@
#include "base/single_thread_task_runner.h"
#include "base/synchronization/atomic_flag.h"
#include "base/synchronization/waitable_event.h"
+#include "base/task/common/checked_lock.h"
#include "base/task/task_traits.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/test_utils.h"
#include "base/test/gtest_util.h"
@@ -216,7 +216,7 @@
}
size_t NumTasksExecuted() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
return num_tasks_executed_;
}
@@ -224,7 +224,7 @@
private:
void RunTaskCallback() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
++num_tasks_executed_;
}
@@ -232,7 +232,7 @@
std::unique_ptr<CallbackThread> thread_calling_flush_;
// Synchronizes accesses to |num_tasks_executed_|.
- SchedulerLock lock_;
+ CheckedLock lock_;
size_t num_tasks_executed_ = 0;
diff --git a/base/task/thread_pool/test_utils.cc b/base/task/thread_pool/test_utils.cc
index 649ee80..db69497 100644
--- a/base/task/thread_pool/test_utils.cc
+++ b/base/task/thread_pool/test_utils.cc
@@ -26,19 +26,19 @@
}
void MockSchedulerWorkerObserver::AllowCallsOnMainExit(int num_calls) {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
EXPECT_EQ(0, allowed_calls_on_main_exit_);
allowed_calls_on_main_exit_ = num_calls;
}
void MockSchedulerWorkerObserver::WaitCallsOnMainExit() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
while (allowed_calls_on_main_exit_ != 0)
on_main_exit_cv_->Wait();
}
void MockSchedulerWorkerObserver::OnSchedulerWorkerMainExit() {
- AutoSchedulerLock auto_lock(lock_);
+ CheckedAutoLock auto_lock(lock_);
EXPECT_GE(allowed_calls_on_main_exit_, 0);
--allowed_calls_on_main_exit_;
if (allowed_calls_on_main_exit_ == 0)
diff --git a/base/task/thread_pool/test_utils.h b/base/task/thread_pool/test_utils.h
index eb48c3eb..ee5835b 100644
--- a/base/task/thread_pool/test_utils.h
+++ b/base/task/thread_pool/test_utils.h
@@ -5,9 +5,9 @@
#ifndef BASE_TASK_THREAD_POOL_TEST_UTILS_H_
#define BASE_TASK_THREAD_POOL_TEST_UTILS_H_
+#include "base/task/common/checked_lock.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool/delayed_task_manager.h"
-#include "base/task/thread_pool/scheduler_lock.h"
#include "base/task/thread_pool/scheduler_task_runner_delegate.h"
#include "base/task/thread_pool/scheduler_worker_observer.h"
#include "base/task/thread_pool/scheduler_worker_pool.h"
@@ -40,7 +40,7 @@
void OnSchedulerWorkerMainExit() override;
private:
- SchedulerLock lock_;
+ CheckedLock lock_;
std::unique_ptr<ConditionVariable> on_main_exit_cv_ GUARDED_BY(lock_);
int allowed_calls_on_main_exit_ GUARDED_BY(lock_) = 0;