From bffcb3e92a9158f6117546db7b7b38d1a5f32225 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sat, 7 Aug 2021 04:28:59 -0700 Subject: [PATCH] Kernel: Add lock debugging to ProtectedValue / RefCountedContended Enable the LOCK_DEBUG functionality for these new APIs, as it looks like we want to move the whole system to use this in the not so distant future. :^) --- Kernel/Locking/ContendedResource.h | 4 ++-- Kernel/Locking/ProtectedValue.h | 23 +++++++++++++---------- Kernel/Locking/RefCountedContended.h | 23 +++++++++++++---------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Kernel/Locking/ContendedResource.h b/Kernel/Locking/ContendedResource.h index cf865a248f8..b3e597efdea 100644 --- a/Kernel/Locking/ContendedResource.h +++ b/Kernel/Locking/ContendedResource.h @@ -16,9 +16,9 @@ class LockedResource { AK_MAKE_NONCOPYABLE(LockedResource); public: - LockedResource(T* value, Mutex& mutex) + LockedResource(T* value, Mutex& mutex, LockLocation const& location) : m_value(value) - , m_mutex_locker(mutex, LockingMode) + , m_mutex_locker(mutex, LockingMode, location) { } diff --git a/Kernel/Locking/ProtectedValue.h b/Kernel/Locking/ProtectedValue.h index 676f932473f..ebc347674fd 100644 --- a/Kernel/Locking/ProtectedValue.h +++ b/Kernel/Locking/ProtectedValue.h @@ -7,6 +7,7 @@ #pragma once #include +#include namespace Kernel { @@ -20,8 +21,8 @@ protected: using LockedShared = LockedResource; using LockedExclusive = LockedResource; - LockedShared lock_shared() const { return LockedShared(this, this->ContendedResource::m_mutex); } - LockedExclusive lock_exclusive() { return LockedExclusive(this, this->ContendedResource::m_mutex); } + LockedShared lock_shared(LockLocation const& location) const { return LockedShared(this, this->ContendedResource::m_mutex, location); } + LockedExclusive lock_exclusive(LockLocation const& location) { return LockedExclusive(this, this->ContendedResource::m_mutex, location); } public: using T::T; @@ -29,35 +30,37 @@ public: ProtectedValue() = default; template - decltype(auto) with_shared(Callback callback) const + decltype(auto) with_shared(Callback callback, LockLocation const& location = LockLocation::current()) const { - auto lock = lock_shared(); + auto lock = lock_shared(location); return callback(*lock); } template - decltype(auto) with_exclusive(Callback callback) + decltype(auto) with_exclusive(Callback callback, LockLocation const& location = LockLocation::current()) { - auto lock = lock_exclusive(); + auto lock = lock_exclusive(location); return callback(*lock); } template - void for_each_shared(Callback callback) const + void for_each_shared(Callback callback, LockLocation const& location = LockLocation::current()) const { with_shared([&](const auto& value) { for (auto& item : value) callback(item); - }); + }, + location); } template - void for_each_exclusive(Callback callback) + void for_each_exclusive(Callback callback, LockLocation const& location = LockLocation::current()) { with_exclusive([&](auto& value) { for (auto& item : value) callback(item); - }); + }, + location); } }; diff --git a/Kernel/Locking/RefCountedContended.h b/Kernel/Locking/RefCountedContended.h index 507c88788b9..ed8424a79de 100644 --- a/Kernel/Locking/RefCountedContended.h +++ b/Kernel/Locking/RefCountedContended.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace Kernel { @@ -22,8 +23,8 @@ protected: using LockedShared = LockedResource; using LockedExclusive = LockedResource; - LockedShared lock_shared() const { return LockedShared(static_cast(this), this->ContendedResource::m_mutex); } - LockedExclusive lock_exclusive() { return LockedExclusive(static_cast(this), this->ContendedResource::m_mutex); } + LockedShared lock_shared(LockLocation const& location) const { return LockedShared(static_cast(this), this->ContendedResource::m_mutex, location); } + LockedExclusive lock_exclusive(LockLocation const& location) { return LockedExclusive(static_cast(this), this->ContendedResource::m_mutex, location); } public: RefCountedContended() = default; @@ -42,35 +43,37 @@ public: } template - decltype(auto) with_shared(Callback callback) const + decltype(auto) with_shared(Callback callback, LockLocation const& location = LockLocation::current()) const { - auto lock = lock_shared(); + auto lock = lock_shared(location); return callback(*lock); } template - decltype(auto) with_exclusive(Callback callback) + decltype(auto) with_exclusive(Callback callback, LockLocation const& location = LockLocation::current()) { - auto lock = lock_exclusive(); + auto lock = lock_exclusive(location); return callback(*lock); } template - void for_each_shared(Callback callback) const + void for_each_shared(Callback callback, LockLocation const& location = LockLocation::current()) const { with_shared([&](const auto& value) { for (auto& item : value) callback(item); - }); + }, + location); } template - void for_each_exclusive(Callback callback) + void for_each_exclusive(Callback callback, LockLocation const& location = LockLocation::current()) { with_exclusive([&](auto& value) { for (auto& item : value) callback(item); - }); + }, + location); } };