Print TIDs in every new thread

This commit is contained in:
Lion Kortlepel
2020-11-03 10:22:49 +01:00
parent 2ec65d5b84
commit b2166402a2
11 changed files with 16 additions and 9 deletions

View File

@@ -5,8 +5,8 @@
#include <string>
#include <iostream>
void InitLog();
#define DebugPrintTID(what) DebugPrintTIDInternal(what, __func__)
void DebugPrintTIDInternal(const std::string& what, const std::string& func); // prints the current thread id in debug mode, to make tracing of crashes and asserts easier
#define DebugPrintTID() DebugPrintTIDInternal(__func__)
void DebugPrintTIDInternal(const std::string& func); // prints the current thread id in debug mode, to make tracing of crashes and asserts easier
void ConsoleOut(const std::string& msg);
void QueueAbort();
void except(const std::string& toPrint);

View File

@@ -47,6 +47,7 @@ void ConsoleOut(const std::string& msg){
}
[[noreturn]] void OutputRefresh(){
DebugPrintTID();
while(true){
std::this_thread::sleep_for(std::chrono::milliseconds(10));
ProcessOut();
@@ -104,6 +105,7 @@ void SetupConsole(){
}
[[noreturn]] void ReadCin(){
DebugPrintTID();
while (true){
int In = _getch();
if (In == 13 || In == '\n') {

View File

@@ -29,6 +29,7 @@ std::string GenerateCall(){
return ret;
}
void Heartbeat(){
DebugPrintTID();
std::string R,T;
while(true){
R = GenerateCall();

View File

@@ -48,6 +48,7 @@ void FolderList(const std::string& Path,bool HotSwap){
}
}
[[noreturn]]void HotSwaps(const std::string& path){
DebugPrintTID();
while(true){
for(Lua*Script : PluginEngine){
struct stat Info{};

View File

@@ -162,6 +162,7 @@ void ExecuteAsync(Lua* lua,const std::string& FuncName){
SafeExecution(lua,FuncName);
}
void CallAsync(Lua* lua,const std::string& Func,int U){
DebugPrintTID();
lua->StopThread = false;
int D = 1000 / U;
while(!lua->StopThread){

View File

@@ -178,6 +178,7 @@ void Identify(SOCKET TCPSock){
}
void TCPServerMain(){
DebugPrintTID();
#ifdef __WIN32
WSADATA wsaData;
if (WSAStartup(514, &wsaData)){

View File

@@ -30,6 +30,7 @@ void Monitor() {
}
[[noreturn]]void Stat(){
DebugPrintTID();
while(true){
Monitor();
std::this_thread::sleep_for(std::chrono::seconds(1));

View File

@@ -56,6 +56,7 @@ void TCPRcv(Client*c){
TCPHandle(c,Buf);
}
void TCPClient(Client*c){
DebugPrintTID();
Assert(c);
if(c->GetTCPSock() == -1){
CI->RemoveClient(c);

View File

@@ -245,6 +245,7 @@ void UDPParser(Client* c, std::string Packet) {
GParser(c, Packet);
}
void LOOP() {
DebugPrintTID();
while (UDPSock != -1) {
for (PacketData* p : DataAcks) {
if (p != nullptr) {

View File

@@ -10,11 +10,11 @@
#include <mutex>
#include <thread>
void DebugPrintTIDInternal(const std::string& what, const std::string& func) {
void DebugPrintTIDInternal(const std::string& func) {
// we need to print to cout here as we might crash before all console output is handled,
// due to segfaults or asserts.
#ifdef DEBUG
std::cout << "(debug build) Thread '" << std::this_thread::get_id() << "' in " << func << " is " << what << std::endl;
std::cout << "(debug build) Thread '" << std::this_thread::get_id() << "' is " << func << std::endl;
#endif // DEBUG
}

View File

@@ -3,20 +3,18 @@
#include <thread>
#include <iostream>
[[noreturn]] void loop(){
DebugPrintTID("test loop");
DebugPrintTID();
while(true){
std::cout.flush();
Assert(false);
std::this_thread::sleep_for(std::chrono::milliseconds(600));
}
}
int main(int argc, char* argv[]) {
DebugPrintTID("main");
DebugPrintTID();
#ifdef DEBUG
std::thread t1(loop);
t1.detach();
#endif
Assert(false);
ConsoleInit();
InitServer(argc,argv);
InitConfig();