Browse Source

Give all threads created by client human-readable name for debug

Ivan Savenko 2 years ago
parent
commit
142889e3a5

+ 9 - 3
client/CMT.cpp

@@ -27,11 +27,12 @@
 #include "render/IScreenHandler.h"
 #include "render/Graphics.h"
 
-#include "../lib/filesystem/Filesystem.h"
+#include "../lib/CConfigHandler.h"
 #include "../lib/CGeneralTextHandler.h"
+#include "../lib/CThreadHelper.h"
 #include "../lib/VCMIDirs.h"
 #include "../lib/VCMI_Lib.h"
-#include "../lib/CConfigHandler.h"
+#include "../lib/filesystem/Filesystem.h"
 
 #include "../lib/logging/CBasicLogConfigurator.h"
 
@@ -297,7 +298,11 @@ int main(int argc, char * argv[])
 
 #ifndef VCMI_NO_THREADED_LOAD
 	//we can properly play intro only in the main thread, so we have to move loading to the separate thread
-	boost::thread loading(init);
+	boost::thread loading([]()
+	{
+		setThreadName("initialize");
+		init();
+	});
 #else
 	init();
 #endif
@@ -429,6 +434,7 @@ void playIntro()
 
 static void mainLoop()
 {
+	setThreadName("MainGUI");
 	inGuiThread.reset(new bool(true));
 
 	while(1) //main SDL events loop

+ 3 - 0
client/CPlayerInterface.cpp

@@ -76,6 +76,7 @@
 #include "../lib/UnlockGuard.h"
 #include "../lib/RoadHandler.h"
 #include "../lib/TerrainHandler.h"
+#include "../lib/CThreadHelper.h"
 #include "CServerHandler.h"
 // FIXME: only needed for CGameState::mutex
 #include "../lib/gameState/CGameState.h"
@@ -1933,6 +1934,8 @@ void CPlayerInterface::setMovementStatus(bool value)
 
 void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
 {
+	setThreadName("doMoveHero");
+
 	int i = 1;
 	auto getObj = [&](int3 coord, bool ignoreHero)
 	{

+ 2 - 2
client/CServerHandler.cpp

@@ -817,7 +817,7 @@ public:
 
 void CServerHandler::threadHandleConnection()
 {
-	setThreadName("CServerHandler::threadHandleConnection");
+	setThreadName("threadHandleConnection");
 	c->enterLobbyConnectionMode();
 
 	try
@@ -898,7 +898,7 @@ void CServerHandler::visitForClient(CPackForClient & clientPack)
 void CServerHandler::threadRunServer()
 {
 #if !defined(VCMI_MOBILE)
-	setThreadName("CServerHandler::threadRunServer");
+	setThreadName("threadRunServer");
 	const std::string logName = (VCMIDirs::get().userLogsPath() / "server_log.txt").string();
 	std::string comm = VCMIDirs::get().serverPath().string()
 		+ " --port=" + std::to_string(getHostPort())

+ 2 - 0
client/adventureMap/CInGameConsole.cpp

@@ -27,6 +27,7 @@
 
 #include "../../CCallback.h"
 #include "../../lib/CConfigHandler.h"
+#include "../../lib/CThreadHelper.h"
 #include "../../lib/TextOperations.h"
 #include "../../lib/mapObjects/CArmedInstance.h"
 
@@ -255,6 +256,7 @@ void CInGameConsole::endEnteringText(bool processEnteredText)
 			//some commands like gosolo don't work when executed from GUI thread
 			auto threadFunction = [=]()
 			{
+				setThreadName("processCommand");
 				ClientCommandManager commandController;
 				commandController.processCommand(txt.substr(1), true);
 			};

+ 2 - 0
client/battle/BattleInterface.cpp

@@ -43,6 +43,7 @@
 #include "../../lib/NetPacks.h"
 #include "../../lib/UnlockGuard.h"
 #include "../../lib/TerrainHandler.h"
+#include "../../lib/CThreadHelper.h"
 
 BattleInterface::BattleInterface(const CCreatureSet *army1, const CCreatureSet *army2,
 		const CGHeroInstance *hero1, const CGHeroInstance *hero2,
@@ -731,6 +732,7 @@ void BattleInterface::requestAutofightingAIToTakeAction()
 			// HOWEVER this thread won't atttempt to lock game state, potentially leading to races
 			boost::thread aiThread([this, activeStack]()
 			{
+				setThreadName("autofightingAI");
 				curInt->autofightingAI->activeStack(activeStack);
 			});
 			aiThread.detach();

+ 1 - 1
client/mainmenu/CMainMenu.cpp

@@ -567,7 +567,7 @@ void CSimpleJoinScreen::startConnectThread(const std::string & addr, ui16 port)
 
 void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
 {
-	setThreadName("CSimpleJoinScreen::connectThread");
+	setThreadName("connectThread");
 	if(!addr.length())
 		CSH->startLocalServerAndConnect();
 	else