Commit 8f7e66fa authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

WTF: Replace most uses of WTF::MutexBase::Locked with AssertAcquired.

This matches the API of base::Lock, which we intend to eventually switch to,
better, and doing a DCHECK is the only reasonable thing to do with the result
of Locked anyhow.

Bug: 856641
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ibd31cb7d1c0982929b6aa09135c7b331cadec984
Reviewed-on: https://chromium-review.googlesource.com/1183633Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585021}
parent 9187c7d0
...@@ -66,9 +66,7 @@ class SourceStreamDataQueue { ...@@ -66,9 +66,7 @@ class SourceStreamDataQueue {
private: private:
bool TryGetData(const uint8_t** data, size_t* length) { bool TryGetData(const uint8_t** data, size_t* length) {
#if DCHECK_IS_ON() mutex_.AssertAcquired();
DCHECK(mutex_.Locked());
#endif
if (!data_.IsEmpty()) { if (!data_.IsEmpty()) {
std::pair<const uint8_t*, size_t> next_data = data_.TakeFirst(); std::pair<const uint8_t*, size_t> next_data = data_.TakeFirst();
*data = next_data.first; *data = next_data.first;
......
...@@ -32,7 +32,7 @@ Mutex& IsolatesMutex() { ...@@ -32,7 +32,7 @@ Mutex& IsolatesMutex() {
HashSet<v8::Isolate*>& Isolates() { HashSet<v8::Isolate*>& Isolates() {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(IsolatesMutex().Locked()); IsolatesMutex().AssertAcquired();
#endif #endif
static HashSet<v8::Isolate*>& isolates = *new HashSet<v8::Isolate*>(); static HashSet<v8::Isolate*>& isolates = *new HashSet<v8::Isolate*>();
return isolates; return isolates;
......
...@@ -100,7 +100,7 @@ class DatabaseVersionCache { ...@@ -100,7 +100,7 @@ class DatabaseVersionCache {
// lifetime of the process. // lifetime of the process.
DatabaseGuid RegisterOriginAndName(const String& origin, const String& name) DatabaseGuid RegisterOriginAndName(const String& origin, const String& name)
EXCLUSIVE_LOCKS_REQUIRED(mutex_) { EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
CheckLocked(); mutex_.AssertAcquired();
String string_id = origin + "/" + name; String string_id = origin + "/" + name;
DCHECK(string_id.IsSafeToSendToAnotherThread()); DCHECK(string_id.IsSafeToSendToAnotherThread());
DatabaseGuid guid = origin_name_to_guid_.at(string_id); DatabaseGuid guid = origin_name_to_guid_.at(string_id);
...@@ -116,7 +116,7 @@ class DatabaseVersionCache { ...@@ -116,7 +116,7 @@ class DatabaseVersionCache {
// RegisterOriginAndName). If all uses are released, the cached version will // RegisterOriginAndName). If all uses are released, the cached version will
// be erased from memory. // be erased from memory.
void ReleaseGuid(DatabaseGuid guid) EXCLUSIVE_LOCKS_REQUIRED(mutex_) { void ReleaseGuid(DatabaseGuid guid) EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
CheckLocked(); mutex_.AssertAcquired();
DCHECK(count_.Contains(guid)); DCHECK(count_.Contains(guid));
if (count_.erase(guid)) if (count_.erase(guid))
guid_to_version_.erase(guid); guid_to_version_.erase(guid);
...@@ -124,7 +124,7 @@ class DatabaseVersionCache { ...@@ -124,7 +124,7 @@ class DatabaseVersionCache {
// The null string is returned only if the cached version has not been set. // The null string is returned only if the cached version has not been set.
String GetVersion(DatabaseGuid guid) const EXCLUSIVE_LOCKS_REQUIRED(mutex_) { String GetVersion(DatabaseGuid guid) const EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
CheckLocked(); mutex_.AssertAcquired();
return guid_to_version_.at(guid).IsolatedCopy(); return guid_to_version_.at(guid).IsolatedCopy();
} }
...@@ -132,19 +132,13 @@ class DatabaseVersionCache { ...@@ -132,19 +132,13 @@ class DatabaseVersionCache {
// The null string is treated as the empty string. // The null string is treated as the empty string.
void SetVersion(DatabaseGuid guid, const String& new_version) void SetVersion(DatabaseGuid guid, const String& new_version)
EXCLUSIVE_LOCKS_REQUIRED(mutex_) { EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
CheckLocked(); mutex_.AssertAcquired();
guid_to_version_.Set(guid, new_version.IsNull() guid_to_version_.Set(guid, new_version.IsNull()
? g_empty_string ? g_empty_string
: new_version.IsolatedCopy()); : new_version.IsolatedCopy());
} }
private: private:
void CheckLocked() const ASSERT_EXCLUSIVE_LOCK(mutex_) {
#if DCHECK_IS_ON()
DCHECK(mutex_.Locked());
#endif
}
mutable Mutex mutex_; mutable Mutex mutex_;
HashMap<String, DatabaseGuid> origin_name_to_guid_ GUARDED_BY(mutex_); HashMap<String, DatabaseGuid> origin_name_to_guid_ GUARDED_BY(mutex_);
HashCountedSet<DatabaseGuid> count_ GUARDED_BY(mutex_); HashCountedSet<DatabaseGuid> count_ GUARDED_BY(mutex_);
...@@ -375,9 +369,7 @@ void Database::InProgressTransactionCompleted() { ...@@ -375,9 +369,7 @@ void Database::InProgressTransactionCompleted() {
} }
void Database::ScheduleTransaction() { void Database::ScheduleTransaction() {
#if DCHECK_IS_ON() transaction_in_progress_mutex_.AssertAcquired();
DCHECK(transaction_in_progress_mutex_.Locked()); // Locked by caller.
#endif // DCHECK_IS_ON()
SQLTransactionBackend* transaction = nullptr; SQLTransactionBackend* transaction = nullptr;
if (is_transaction_queue_enabled_ && !transaction_queue_.IsEmpty()) if (is_transaction_queue_enabled_ && !transaction_queue_.IsEmpty())
......
...@@ -239,9 +239,7 @@ SkBitmap ImageFrameGenerator::TryToResumeDecode( ...@@ -239,9 +239,7 @@ SkBitmap ImageFrameGenerator::TryToResumeDecode(
SkBitmap::Allocator& allocator, SkBitmap::Allocator& allocator,
ImageDecoder::AlphaOption alpha_option, ImageDecoder::AlphaOption alpha_option,
ImageDecoder::HighBitDepthDecodingOption high_bit_depth_decoding_option) { ImageDecoder::HighBitDepthDecodingOption high_bit_depth_decoding_option) {
#if DCHECK_IS_ON() decode_mutex_.AssertAcquired();
DCHECK(decode_mutex_.Locked());
#endif
TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecode", "frame index", TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecode", "frame index",
static_cast<int>(index)); static_cast<int>(index));
...@@ -334,9 +332,7 @@ ImageFrame* ImageFrameGenerator::Decode( ...@@ -334,9 +332,7 @@ ImageFrame* ImageFrameGenerator::Decode(
ImageDecoder::HighBitDepthDecodingOption high_bit_depth_decoding_option, ImageDecoder::HighBitDepthDecodingOption high_bit_depth_decoding_option,
const SkISize& scaled_size, const SkISize& scaled_size,
bool& used_external_allocator) { bool& used_external_allocator) {
#if DCHECK_IS_ON() decode_mutex_.AssertAcquired();
DCHECK(decode_mutex_.Locked());
#endif
TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width",
full_size_.width(), "height", full_size_.height()); full_size_.width(), "height", full_size_.height());
......
...@@ -186,7 +186,7 @@ class PersistentBase { ...@@ -186,7 +186,7 @@ class PersistentBase {
crossThreadnessConfiguration == kCrossThreadPersistentConfiguration, crossThreadnessConfiguration == kCrossThreadPersistentConfiguration,
"This Persistent does not require the cross-thread lock."); "This Persistent does not require the cross-thread lock.");
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(ProcessHeap::CrossThreadPersistentMutex().Locked()); ProcessHeap::CrossThreadPersistentMutex().AssertAcquired();
#endif #endif
raw_ = nullptr; raw_ = nullptr;
CrossThreadPersistentRegion& region = CrossThreadPersistentRegion& region =
...@@ -342,7 +342,7 @@ class PersistentBase { ...@@ -342,7 +342,7 @@ class PersistentBase {
kWeakPersistentConfiguration, kWeakPersistentConfiguration,
kCrossThreadPersistentConfiguration>* persistent) { kCrossThreadPersistentConfiguration>* persistent) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(ProcessHeap::CrossThreadPersistentMutex().Locked()); ProcessHeap::CrossThreadPersistentMutex().AssertAcquired();
#endif #endif
persistent->ClearWithLockHeld(); persistent->ClearWithLockHeld();
} }
......
...@@ -174,7 +174,7 @@ class CrossThreadPersistentRegion final { ...@@ -174,7 +174,7 @@ class CrossThreadPersistentRegion final {
void* self, void* self,
TraceCallback trace) { TraceCallback trace) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(ProcessHeap::CrossThreadPersistentMutex().Locked()); ProcessHeap::CrossThreadPersistentMutex().AssertAcquired();
#endif #endif
PersistentNode* node = PersistentNode* node =
persistent_region_.AllocatePersistentNode(self, trace); persistent_region_.AllocatePersistentNode(self, trace);
...@@ -204,7 +204,7 @@ class CrossThreadPersistentRegion final { ...@@ -204,7 +204,7 @@ class CrossThreadPersistentRegion final {
void TracePersistentNodes(Visitor* visitor) { void TracePersistentNodes(Visitor* visitor) {
// If this assert triggers, you're tracing without being in a LockScope. // If this assert triggers, you're tracing without being in a LockScope.
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(ProcessHeap::CrossThreadPersistentMutex().Locked()); ProcessHeap::CrossThreadPersistentMutex().AssertAcquired();
#endif #endif
persistent_region_.TracePersistentNodes( persistent_region_.TracePersistentNodes(
visitor, CrossThreadPersistentRegion::ShouldTracePersistentNode); visitor, CrossThreadPersistentRegion::ShouldTracePersistentNode);
......
...@@ -72,7 +72,12 @@ class WTF_EXPORT MutexBase { ...@@ -72,7 +72,12 @@ class WTF_EXPORT MutexBase {
void lock(); void lock();
void unlock(); void unlock();
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
bool Locked() { return mutex_.recursion_count_ > 0; } // Deprecated in favour of AssertAcquired.
bool Locked() const { return mutex_.recursion_count_ > 0; }
void AssertAcquired() const { DCHECK(Locked()); }
#else
void AssertAcquired() const {}
#endif #endif
public: public:
...@@ -91,10 +96,13 @@ class LOCKABLE WTF_EXPORT Mutex : public MutexBase { ...@@ -91,10 +96,13 @@ class LOCKABLE WTF_EXPORT Mutex : public MutexBase {
Mutex() : MutexBase(false) {} Mutex() : MutexBase(false) {}
bool TryLock() EXCLUSIVE_TRYLOCK_FUNCTION(true); bool TryLock() EXCLUSIVE_TRYLOCK_FUNCTION(true);
// lock() and unlock() are overridden solely for the purpose of annotating // Overridden solely for the purpose of annotating them.
// them. The compiler is expected to optimize the calls away. // The compiler is expected to optimize the calls away.
void lock() EXCLUSIVE_LOCK_FUNCTION() { MutexBase::lock(); } void lock() EXCLUSIVE_LOCK_FUNCTION() { MutexBase::lock(); }
void unlock() UNLOCK_FUNCTION() { MutexBase::unlock(); } void unlock() UNLOCK_FUNCTION() { MutexBase::unlock(); }
void AssertAcquired() const ASSERT_EXCLUSIVE_LOCK() {
MutexBase::AssertAcquired();
}
}; };
class WTF_EXPORT RecursiveMutex : public MutexBase { class WTF_EXPORT RecursiveMutex : public MutexBase {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment