Added GetLocksCount()

This commit is contained in:
Alex 2023-02-24 10:11:48 +02:00
parent 3e76830978
commit bcf46f8341
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 13 additions and 0 deletions

View File

@ -6,6 +6,9 @@
#include "../kernel.h" #include "../kernel.h"
bool ForceUnlock = false; bool ForceUnlock = false;
Atomic<size_t> LocksCount = 0;
size_t GetLocksCount() { return LocksCount; }
void LockClass::DeadLock(SpinLockData Lock) void LockClass::DeadLock(SpinLockData Lock)
{ {
@ -62,6 +65,7 @@ Retry:
CPUData *CoreData = GetCurrentCPU(); CPUData *CoreData = GetCurrentCPU();
if (CoreData != nullptr) if (CoreData != nullptr)
LockData.Core = CoreData->ID; LockData.Core = CoreData->ID;
LocksCount++;
__sync; __sync;
return 0; return 0;
@ -73,6 +77,7 @@ int LockClass::Unlock()
IsLocked.Store(false, MemoryOrder::Release); IsLocked.Store(false, MemoryOrder::Release);
LockData.Count--; LockData.Count--;
IsLocked = false; IsLocked = false;
LocksCount--;
return 0; return 0;
} }
@ -125,6 +130,7 @@ Retry:
CPUData *CoreData = GetCurrentCPU(); CPUData *CoreData = GetCurrentCPU();
if (CoreData != nullptr) if (CoreData != nullptr)
LockData.Core = CoreData->ID; LockData.Core = CoreData->ID;
LocksCount++;
__sync; __sync;
return 0; return 0;

View File

@ -11,6 +11,13 @@
/* Enabled ONLY on crash. */ /* Enabled ONLY on crash. */
extern bool ForceUnlock; 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. */ /** @brief Please use this macro to create a new lock. */
class LockClass class LockClass
{ {