diff --git a/Kernel/Locking/ContendedResource.h b/Kernel/Locking/ContendedResource.h index cf865a248f..b3e597efde 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 676f932473..ebc347674f 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 507c88788b..ed8424a79d 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); } };