Lock assertions now report leaf file and line.

This commit is contained in:
Fletcher Dunn
2021-02-06 12:53:17 -08:00
parent 19e6358ba9
commit 99b16c33be
3 changed files with 21 additions and 13 deletions
@@ -484,9 +484,9 @@ public:
// Almost all connections use this default lock. (A few special cases use a different lock
// so that they are locked at the same time as other objects.)
ConnectionLock m_defaultLock;
void AssertLocksHeldByCurrentThread( const char *pszTag = nullptr ) const
void _AssertLocksHeldByCurrentThread( const char *pszFile, int line, const char *pszTag = nullptr ) const
{
SteamNetworkingGlobalLock::AssertHeldByCurrentThread( pszTag );
SteamNetworkingGlobalLock::_AssertHeldByCurrentThread( pszFile, line, pszTag );
m_pLock->AssertHeldByCurrentThread();
}
@@ -872,9 +872,9 @@ public:
inline const SteamNetworkingIdentity &IdentityRemote() const { return m_connection.m_identityRemote; }
inline const char *ConnectionDescription() const { return m_connection.GetDescription(); }
void AssertLocksHeldByCurrentThread( const char *pszTag = nullptr ) const
void _AssertLocksHeldByCurrentThread( const char *pszFile, int line, const char *pszTag = nullptr ) const
{
m_connection.AssertLocksHeldByCurrentThread( pszTag );
m_connection._AssertLocksHeldByCurrentThread( pszFile, line, pszTag );
}
// Useful so we can use ScheduledMethodThinkerLockable
@@ -338,7 +338,7 @@ void LockDebugInfo::AboutToUnlock()
AssertMsg( false, "Unlocked a lock '%s' that wasn't held?", m_pszName );
}
void LockDebugInfo::AssertHeldByCurrentThread( const char *pszTag ) const
void LockDebugInfo::_AssertHeldByCurrentThread( const char *pszFile, int line, const char *pszTag ) const
{
ThreadLockDebugInfo &t = GetThreadDebugInfo();
for ( int i = t.m_nHeldLocks-1 ; i >= 0 ; --i )
@@ -350,7 +350,7 @@ void LockDebugInfo::AssertHeldByCurrentThread( const char *pszTag ) const
}
}
AssertMsg( false, "Lock '%s' not held", m_pszName );
AssertMsg( false, "%s(%d): Lock '%s' not held", pszFile, line, m_pszName );
}
@@ -381,14 +381,14 @@ void SteamNetworkingGlobalLock::SetLongLockWarningThresholdMS( const char *pszTa
}
}
void SteamNetworkingGlobalLock::AssertHeldByCurrentThread()
void SteamNetworkingGlobalLock::_AssertHeldByCurrentThread( const char *pszFile, int line )
{
s_mutexGlobalLock.AssertHeldByCurrentThread();
s_mutexGlobalLock._AssertHeldByCurrentThread( pszFile, line );
}
void SteamNetworkingGlobalLock::AssertHeldByCurrentThread( const char *pszTag )
void SteamNetworkingGlobalLock::_AssertHeldByCurrentThread( const char *pszFile, int line, const char *pszTag )
{
s_mutexGlobalLock.AssertHeldByCurrentThread();
s_mutexGlobalLock._AssertHeldByCurrentThread( pszFile, line );
AddThreadLockTag( pszTag );
}
@@ -378,7 +378,7 @@ struct LockDebugInfo
const char *const m_pszName;
const int m_nFlags;
void AssertHeldByCurrentThread( const char *pszTag = nullptr ) const;
void _AssertHeldByCurrentThread( const char *pszFile, int line, const char *pszTag = nullptr ) const;
protected:
LockDebugInfo( const char *pszName, int nFlags ) : m_pszName( pszName ), m_nFlags( nFlags ) {}
@@ -457,6 +457,14 @@ struct ShortDurationLock : Lock<ShortDurationMutexImpl>
};
using ShortDurationScopeLock = ScopeLock<ShortDurationLock>;
#ifdef DBGFLAG_ASSERT
#define AssertHeldByCurrentThread( ... ) _AssertHeldByCurrentThread( __FILE__, __LINE__ ,## __VA_ARGS__ )
#define AssertLocksHeldByCurrentThread( ... ) _AssertLocksHeldByCurrentThread( __FILE__, __LINE__,## __VA_ARGS__ )
#else
#define AssertHeldByCurrentThread( ... ) _AssertHeldByCurrentThread( nullptr, 0,## __VA_ARGS__ )
#define AssertLocksHeldByCurrentThread( ... ) _AssertLocksHeldByCurrentThread( nullptr, 0,## __VA_ARGS__ )
#endif
/// Special utilities for acquiring the global lock
struct SteamNetworkingGlobalLock
{
@@ -465,8 +473,8 @@ struct SteamNetworkingGlobalLock
static void Lock( const char *pszTag );
static bool TryLock( const char *pszTag, int msTimeout );
static void Unlock();
static void AssertHeldByCurrentThread();
static void AssertHeldByCurrentThread( const char *pszTag );
static void _AssertHeldByCurrentThread( const char *pszFile, int line );
static void _AssertHeldByCurrentThread( const char *pszFile, int line, const char *pszTag );
static void SetLongLockWarningThresholdMS( const char *pszTag, int msWarningThreshold );
};