Skip to content

Commit 2a40b7a

Browse files
committed
Tweak lock warning thresholds to fix tests
1 parent a7a115f commit 2a40b7a

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,21 @@ struct ThreadLockDebugInfo
156156

157157
static void (*s_fLockAcquiredCallback)( const char *tags, SteamNetworkingMicroseconds usecWaited );
158158
static void (*s_fLockHeldCallback)( const char *tags, SteamNetworkingMicroseconds usecWaited );
159+
160+
// Threshold for warning about waiting on any lock.
159161
#ifdef __SANITIZE_THREAD__
160162
static SteamNetworkingMicroseconds s_usecLockWaitWarningThreshold = 300*1000;
161163
#else
162164
static SteamNetworkingMicroseconds s_usecLockWaitWarningThreshold = 2*1000;
163165
#endif
164166

167+
// Threshold for the service-thread-specific *assert*
168+
#ifdef __SANITIZE_THREAD__
169+
static SteamNetworkingMicroseconds s_usecServiceThreadLockWaitWarning = 300*1000;
170+
#else
171+
static SteamNetworkingMicroseconds s_usecServiceThreadLockWaitWarning = 50*1000;
172+
#endif
173+
165174
/// Get the per-thread debug info
166175
static ThreadLockDebugInfo &GetThreadDebugInfo()
167176
{
@@ -2877,15 +2886,7 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
28772886
#ifdef DBGFLAG_ASSERT
28782887
{
28792888
SteamNetworkingMicroseconds usecElapsedWaitingForLock = SteamNetworkingSockets_GetLocalTimestamp() - usecStartedLocking;
2880-
// Hm, if another thread indicated that they expected to hold the lock for a while,
2881-
// perhaps we should ignore this assert?
2882-
// TSan adds 10-20x overhead so the threshold is scaled up accordingly.
2883-
#ifdef __SANITIZE_THREAD__
2884-
constexpr SteamNetworkingMicroseconds k_usecServiceThreadLockWaitWarning = 300*1000;
2885-
#else
2886-
constexpr SteamNetworkingMicroseconds k_usecServiceThreadLockWaitWarning = 50*1000;
2887-
#endif
2888-
AssertMsg1( usecElapsedWaitingForLock < k_usecServiceThreadLockWaitWarning || Plat_IsInDebugSession(),
2889+
AssertMsg1( usecElapsedWaitingForLock < s_usecServiceThreadLockWaitWarning || Plat_IsInDebugSession(),
28892890
"SteamnetworkingSockets service thread waited %dms for lock! This directly adds to network latency! It could be a bug, but it's usually caused by general performance problem such as thread starvation or a debug output handler taking too long.", int( usecElapsedWaitingForLock/1000 ) );
28902891
}
28912892
#endif
@@ -4643,9 +4644,8 @@ STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockWaitWarningT
46434644
{
46444645
#if STEAMNETWORKINGSOCKETS_LOCK_DEBUG_LEVEL > 0
46454646
s_usecLockWaitWarningThreshold = usecTheshold;
4646-
#else
4647-
// Should we assert here?
46484647
#endif
4648+
s_usecServiceThreadLockWaitWarning = usecTheshold;
46494649
}
46504650

46514651
STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockAcquiredCallback( void (*callback)( const char *tags, SteamNetworkingMicroseconds usecWaited ) )

tests/test_common.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ void TEST_Init( const SteamNetworkingIdentity *pIdentity )
111111
{
112112
TEST_InitLog( "log.txt" );
113113

114+
// Test machines are not always realtime systems and may experience thread starvation.
115+
// Set very high lock performance warnings so they don't cause test failures.
116+
SteamNetworkingSockets_SetLockWaitWarningThreshold( 500*1000 );
117+
114118
#ifdef STEAMNETWORKINGSOCKETS_OPENSOURCE
115119
SteamDatagramErrMsg errMsg;
116120
if ( !GameNetworkingSockets_Init( pIdentity, errMsg ) )

0 commit comments

Comments
 (0)