Add error log when adding/removign actors during rendering or when ConcurrentSystemLocker deadlocks

This commit is contained in:
Wojtek Figat
2025-07-15 12:34:40 +02:00
parent c882b547c8
commit 3e0c085bf3
3 changed files with 44 additions and 1 deletions

View File

@@ -2,6 +2,9 @@
#include "ConcurrentSystemLocker.h"
#include "Engine/Platform/Platform.h"
#if !BUILD_RELEASE
#include "Engine/Core/Log.h"
#endif
ConcurrentSystemLocker::ConcurrentSystemLocker()
{
@@ -12,7 +15,25 @@ void ConcurrentSystemLocker::Begin(bool write, bool exclusively)
{
volatile int64* thisCounter = &_counters[write];
volatile int64* otherCounter = &_counters[!write];
#if !BUILD_RELEASE
int32 retries = 0;
double startTime = Platform::GetTimeSeconds();
#endif
RETRY:
#if !BUILD_RELEASE
retries++;
if (retries > 1000)
{
double endTime = Platform::GetTimeSeconds();
if (endTime - startTime > 0.5f)
{
LOG(Error, "Deadlock detected in ConcurrentSystemLocker! Thread 0x{0:x} waits for {1} ms...", Platform::GetCurrentThreadID(), (int32)((endTime - startTime) * 1000.0));
retries = 0;
}
}
#endif
// Check if we can enter (cannot read while someone else is writing and vice versa)
if (Platform::AtomicRead(otherCounter) != 0)
{
@@ -47,3 +68,8 @@ void ConcurrentSystemLocker::End(bool write)
// Mark that we left this section
Platform::InterlockedDecrement(&_counters[write]);
}
bool ConcurrentSystemLocker::HasLock(bool write) const
{
return Platform::AtomicRead(&_counters[write]) != 0;
}