Skip to content

Commit 4128327

Browse files
committed
Greatly increase warning thresholds in tsan
1 parent e15f7e3 commit 4128327

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ static Lock<RecursiveTimedMutexImpl> s_mutexGlobalLock( "global", 0, LockDebugIn
122122

123123
#if STEAMNETWORKINGSOCKETS_LOCK_DEBUG_LEVEL > 0
124124

125-
// By default, complain if we hold the lock for more than this long
125+
// By default, complain if we hold the lock for more than this long.
126+
// TSan adds 10-20x overhead so the threshold is scaled up accordingly.
127+
#ifdef __SANITIZE_THREAD__
128+
constexpr SteamNetworkingMicroseconds k_usecDefaultLongLockHeldWarningThreshold = 5*1000*20;
129+
#else
126130
constexpr SteamNetworkingMicroseconds k_usecDefaultLongLockHeldWarningThreshold = 5*1000;
131+
#endif
127132

128133
// Debug the locks active on the cu
129134
struct ThreadLockDebugInfo
@@ -2870,7 +2875,13 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
28702875
SteamNetworkingMicroseconds usecElapsedWaitingForLock = SteamNetworkingSockets_GetLocalTimestamp() - usecStartedLocking;
28712876
// Hm, if another thread indicated that they expected to hold the lock for a while,
28722877
// perhaps we should ignore this assert?
2873-
AssertMsg1( usecElapsedWaitingForLock < 50*1000 || Plat_IsInDebugSession(),
2878+
// TSan adds 10-20x overhead so the threshold is scaled up accordingly.
2879+
#ifdef __SANITIZE_THREAD__
2880+
constexpr SteamNetworkingMicroseconds k_usecServiceThreadLockWaitWarning = 50*1000*20;
2881+
#else
2882+
constexpr SteamNetworkingMicroseconds k_usecServiceThreadLockWaitWarning = 50*1000;
2883+
#endif
2884+
AssertMsg1( usecElapsedWaitingForLock < k_usecServiceThreadLockWaitWarning || Plat_IsInDebugSession(),
28742885
"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 ) );
28752886
}
28762887
#endif

0 commit comments

Comments
 (0)