diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 14 | ||||
-rw-r--r-- | src/init.cpp | 4 | ||||
-rw-r--r-- | src/irc.cpp | 4 | ||||
-rw-r--r-- | src/main.cpp | 3 | ||||
-rw-r--r-- | src/net.cpp | 34 | ||||
-rw-r--r-- | src/qt/qtipcserver.cpp | 4 | ||||
-rw-r--r-- | src/util.cpp | 19 | ||||
-rw-r--r-- | src/util.h | 4 | ||||
-rw-r--r-- | src/walletdb.cpp | 3 |
9 files changed, 86 insertions, 3 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 62b0b497ed..c2bf45e1e2 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1569,11 +1569,17 @@ Value keypoolrefill(const Array& params, bool fHelp) void ThreadTopUpKeyPool(void* parg) { + // Make this thread recognisable as the key-topping-up thread + RenameThread("bitcoin-key-top"); + pwalletMain->TopUpKeyPool(); } void ThreadCleanWalletPassphrase(void* parg) { + // Make this thread recognisable as the wallet relocking thread + RenameThread("bitcoin-lock-wa"); + int64 nMyWakeTime = GetTimeMillis() + *((int64*)parg) * 1000; ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime); @@ -2479,6 +2485,10 @@ private: void ThreadRPCServer(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadRPCServer(parg)); + + // Make this thread recognisable as the RPC listener + RenameThread("bitcoin-rpclist"); + try { vnThreadsRunning[THREAD_RPCLISTENER]++; @@ -2762,6 +2772,10 @@ static CCriticalSection cs_THREAD_RPCHANDLER; void ThreadRPCServer3(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadRPCServer3(parg)); + + // Make this thread recognisable as the RPC handler + RenameThread("bitcoin-rpchand"); + { LOCK(cs_THREAD_RPCHANDLER); vnThreadsRunning[THREAD_RPCHANDLER]++; diff --git a/src/init.cpp b/src/init.cpp index 5c87af9112..83870f9f8c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -53,6 +53,10 @@ void Shutdown(void* parg) { static CCriticalSection cs_Shutdown; static bool fTaken; + + // Make this thread recognisable as the shutdown thread + RenameThread("bitcoin-shutoff"); + bool fFirstThread = false; { TRY_LOCK(cs_Shutdown, lockShutdown); diff --git a/src/irc.cpp b/src/irc.cpp index 185be02f29..a790d3f4f9 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -189,6 +189,10 @@ bool GetIPFromIRC(SOCKET hSocket, string strMyName, CNetAddr& ipRet) void ThreadIRCSeed(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadIRCSeed(parg)); + + // Make this thread recognisable as the IRC seeding thread + RenameThread("bitcoin-ircseed"); + try { ThreadIRCSeed2(parg); diff --git a/src/main.cpp b/src/main.cpp index 3052cfb8c4..c4472c4556 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3594,6 +3594,9 @@ void static BitcoinMiner(CWallet *pwallet) printf("BitcoinMiner started\n"); SetThreadPriority(THREAD_PRIORITY_LOWEST); + // Make this thread recognisable as the mining thread + RenameThread("bitcoin-miner"); + // Each thread has its own key and counter CReserveKey reservekey(pwallet); unsigned int nExtraNonce = 0; diff --git a/src/net.cpp b/src/net.cpp index fc7473003f..78b5a752db 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -407,6 +407,9 @@ bool GetMyExternalIP(CNetAddr& ipRet) void ThreadGetMyExternalIP(void* parg) { + // Make this thread recognisable as the message handling thread + RenameThread("bitcoin-ext-ip"); + CNetAddr addrLocalHost; if (GetMyExternalIP(addrLocalHost)) { @@ -636,6 +639,10 @@ void CNode::copyStats(CNodeStats &stats) void ThreadSocketHandler(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadSocketHandler(parg)); + + // Make this thread recognisable as the networking thread + RenameThread("bitcoin-net"); + try { vnThreadsRunning[THREAD_SOCKETHANDLER]++; @@ -988,6 +995,10 @@ void ThreadSocketHandler2(void* parg) void ThreadMapPort(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadMapPort(parg)); + + // Make this thread recognisable as the UPnP thread + RenameThread("bitcoin-UPnP"); + try { vnThreadsRunning[THREAD_UPNP]++; @@ -1146,6 +1157,10 @@ static const char *strDNSSeed[][2] = { void ThreadDNSAddressSeed(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadDNSAddressSeed(parg)); + + // Make this thread recognisable as the DNS seeding thread + RenameThread("bitcoin-dnsseed"); + try { vnThreadsRunning[THREAD_DNSSEED]++; @@ -1315,6 +1330,10 @@ void ThreadDumpAddress2(void* parg) void ThreadDumpAddress(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadDumpAddress(parg)); + + // Make this thread recognisable as the address dumping thread + RenameThread("bitcoin-adrdump"); + try { ThreadDumpAddress2(parg); @@ -1328,6 +1347,10 @@ void ThreadDumpAddress(void* parg) void ThreadOpenConnections(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadOpenConnections(parg)); + + // Make this thread recognisable as the connection opening thread + RenameThread("bitcoin-opencon"); + try { vnThreadsRunning[THREAD_OPENCONNECTIONS]++; @@ -1481,6 +1504,10 @@ void ThreadOpenConnections2(void* parg) void ThreadOpenAddedConnections(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadOpenAddedConnections(parg)); + + // Make this thread recognisable as the connection opening thread + RenameThread("bitcoin-opencon"); + try { vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++; @@ -1610,6 +1637,10 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu void ThreadMessageHandler(void* parg) { IMPLEMENT_RANDOMIZE_STACK(ThreadMessageHandler(parg)); + + // Make this thread recognisable as the message handling thread + RenameThread("bitcoin-msghand"); + try { vnThreadsRunning[THREAD_MESSAGEHANDLER]++; @@ -1852,6 +1883,9 @@ void static Discover() void StartNode(void* parg) { + // Make this thread recognisable as the startup thread + RenameThread("bitcoin-start"); + if (semOutbound == NULL) { // initialize semaphore int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, (int)GetArg("-maxconnections", 125)); diff --git a/src/qt/qtipcserver.cpp b/src/qt/qtipcserver.cpp index 5ff00451e5..f9ee9ad5ca 100644 --- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -14,6 +14,7 @@ #include "ui_interface.h" #include "qtipcserver.h" +#include "util.h" using namespace boost::interprocess; using namespace boost::posix_time; @@ -35,6 +36,9 @@ void ipcShutdown() void ipcThread(void* parg) { + // Make this thread recognisable as the GUI-IPC thread + RenameThread("bitcoin-gui-ipc"); + message_queue* mq = (message_queue*)parg; char strBuf[257]; size_t nSize; diff --git a/src/util.cpp b/src/util.cpp index 9881545a02..963d58cd8b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -51,6 +51,8 @@ namespace boost { #endif #include <io.h> /* for _commit */ #include "shlobj.h" +#elif defined(__linux__) +# include <sys/prctl.h> #endif using namespace std; @@ -1275,3 +1277,20 @@ void runCommand(std::string strCommand) printf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr); } +void RenameThread(const char* name) +{ +#if defined(PR_SET_NAME) + // Only the first 15 characters are used (16 - NUL terminator) + ::prctl(PR_SET_NAME, name, 0, 0, 0); +#elif 0 && (defined(__FreeBSD__) || defined(__OpenBSD__)) + // TODO: This is currently disabled because it needs to be verified to work + // on FreeBSD or OpenBSD first. When verified the '0 &&' part can be + // removed. + pthread_set_name_np(pthread_self(), name); +#elif defined(MAC_OSX) + pthread_setname_np(name); +#else + // Prevent warnings for unused parameters... + (void)name; +#endif +} diff --git a/src/util.h b/src/util.h index 7fe204c0df..4423d2ff58 100644 --- a/src/util.h +++ b/src/util.h @@ -621,9 +621,7 @@ inline void ExitThread(size_t nExitCode) } #endif - - - +void RenameThread(const char* name); inline uint32_t ByteReverse(uint32_t value) { diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 2c4d4c0ef0..72c548e602 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -323,6 +323,9 @@ int CWalletDB::LoadWallet(CWallet* pwallet) void ThreadFlushWalletDB(void* parg) { + // Make this thread recognisable as the wallet flushing thread + RenameThread("bitcoin-wallet"); + const string& strFile = ((const string*)parg)[0]; static bool fOneThread; if (fOneThread) |