From bcf46f834150812b6eedbb3ba48dab48402c913b Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 24 Feb 2023 10:11:48 +0200 Subject: [PATCH] Added GetLocksCount() --- Core/Lock.cpp | 6 ++++++ include/lock.hpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/Core/Lock.cpp b/Core/Lock.cpp index 341a79f..4a3317a 100644 --- a/Core/Lock.cpp +++ b/Core/Lock.cpp @@ -6,6 +6,9 @@ #include "../kernel.h" bool ForceUnlock = false; +Atomic LocksCount = 0; + +size_t GetLocksCount() { return LocksCount; } void LockClass::DeadLock(SpinLockData Lock) { @@ -62,6 +65,7 @@ Retry: CPUData *CoreData = GetCurrentCPU(); if (CoreData != nullptr) LockData.Core = CoreData->ID; + LocksCount++; __sync; return 0; @@ -73,6 +77,7 @@ int LockClass::Unlock() IsLocked.Store(false, MemoryOrder::Release); LockData.Count--; IsLocked = false; + LocksCount--; return 0; } @@ -125,6 +130,7 @@ Retry: CPUData *CoreData = GetCurrentCPU(); if (CoreData != nullptr) LockData.Core = CoreData->ID; + LocksCount++; __sync; return 0; diff --git a/include/lock.hpp b/include/lock.hpp index 45b7c3c..df6c1fa 100644 --- a/include/lock.hpp +++ b/include/lock.hpp @@ -11,6 +11,13 @@ /* Enabled ONLY on crash. */ extern bool ForceUnlock; +/** + * @brief Get how many locks are currently in use. + * + * @return size_t + */ +size_t GetLocksCount(); + /** @brief Please use this macro to create a new lock. */ class LockClass {