Add SteamNetworkingSockets_SetServiceThreadInitCallback

Also, make sure thread affinity is not set on the playstation.
Tweak thread name from 'SteamNetworking' to 'SteamNetworkingSockets'

P4:8088043
This commit is contained in:
Fletcher Dunn
2023-05-27 17:12:38 -07:00
parent c7c0f2b600
commit 356afe93d1
2 changed files with 21 additions and 1 deletions
+4
View File
@@ -42,6 +42,10 @@ STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockWaitWarningT
STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockAcquiredCallback( void (*callback)( const char *tags, SteamNetworkingMicroseconds usecWaited ) );
STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockHeldCallback( void (*callback)( const char *tags, SteamNetworkingMicroseconds usecWaited ) );
/// Called from the service thread at initialization time.
/// Use this to customize its priority / affinity, etc
STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetServiceThreadInitCallback( void (*callback)() );
}
#endif // STEAMNETWORKINGSOCKETS_H
@@ -1349,6 +1349,7 @@ static bool AddFDToEPoll( int fd, CRawUDPSocketImpl *pSock, SteamNetworkingErrMs
#endif
static std::thread *s_pServiceThread = nullptr;
static void (*s_fnServiceThreadInitCallback)() = nullptr;
bool IsServiceThreadRunning()
{
@@ -2786,6 +2787,10 @@ static void SteamNetworkingThreadProc()
}
#endif
#if IsPlaystation()
ClearCurrentThreadAffinity();
#endif
#if defined(_WIN32) && !defined(__GNUC__)
#pragma warning( disable: 6132 ) // Possible infinite loop: use of the constant EXCEPTION_CONTINUE_EXECUTION in the exception-filter expression of a try-except. Execution restarts in the protected block.
@@ -2802,7 +2807,7 @@ static void SteamNetworkingThreadProc()
THREADNAME_INFO info;
{
info.dwType = 0x1000;
info.szName = "SteamNetworking";
info.szName = "SteamNetworkingSockets";
info.dwThreadID = GetCurrentThreadId();
info.dwFlags = 0;
}
@@ -2814,11 +2819,17 @@ static void SteamNetworkingThreadProc()
{
}
#elif IsPlaystation()
SetCurrentThreadName( "SteamNetworkingSockets" );
#else
// Help! Really we should do this for all platforms. Seems it's not
// totally straightforward the correct way to do this on Linux.
#endif
// Invoke user callback, if any
if ( s_fnServiceThreadInitCallback )
(*s_fnServiceThreadInitCallback)();
// In the loop, we will always hold global lock while we're awake.
// So go ahead and acquire it now. But watch out for a race condition
// where we want to shut down immediately after starting the thread
@@ -3864,6 +3875,11 @@ STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_DefaultPreFormatDeb
pfnDebugOutput( eType, buf );
}
STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetServiceThreadInitCallback( void (*callback)() )
{
AssertMsg( !IsServiceThreadRunning(), "Too late!" );
s_fnServiceThreadInitCallback = callback;
}
/////////////////////////////////////////////////////////////////////////////
//