diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h index b039e29..183e98c 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.h @@ -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 diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp index 472cb30..228c6e5 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp @@ -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 ); } diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h index d11a8cf..04f092b 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.h @@ -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 }; using ShortDurationScopeLock = ScopeLock; +#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 ); };