From b31499ec72edd1554d4612d1b54808fce0360e14 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Sat, 9 Mar 2013 12:02:57 -0500 Subject: Clean up shutdown process --- src/net.cpp | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index 557bd6f87..f1ece2c2e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -45,7 +45,6 @@ static bool vfReachable[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {}; static CNode* pnodeLocalHost = NULL; uint64 nLocalHostNonce = 0; -array vnThreadsRunning; static std::vector vhListenSocket; CAddrMan addrman; @@ -147,8 +146,7 @@ bool RecvLine(SOCKET hSocket, string& strLine) } else if (nBytes <= 0) { - if (fShutdown) - return false; + boost::this_thread::interruption_point(); if (nBytes < 0) { int nErr = WSAGetLastError(); @@ -1775,10 +1773,8 @@ void static Discover() NewThread(ThreadGetMyExternalIP, NULL); } -void StartNode(void* parg) +void StartNode(boost::thread_group& threadGroup) { - boost::thread_group* threadGroup = (boost::thread_group*)parg; - // Make this thread recognisable as the startup thread RenameThread("bitcoin-start"); @@ -1800,25 +1796,27 @@ void StartNode(void* parg) if (!GetBoolArg("-dnsseed", true)) printf("DNS seeding disabled\n"); else - threadGroup->create_thread(boost::bind(&TraceThread >, "dnsseed", &ThreadDNSAddressSeed)); + threadGroup.create_thread(boost::bind(&TraceThread >, "dnsseed", &ThreadDNSAddressSeed)); +#ifdef USE_UPNP // Map ports with UPnP MapPort(GetBoolArg("-upnp", USE_UPNP)); +#endif // Send and receive from sockets, accept connections - threadGroup->create_thread(boost::bind(&TraceThread, "net", &ThreadSocketHandler)); + threadGroup.create_thread(boost::bind(&TraceThread, "net", &ThreadSocketHandler)); // Initiate outbound connections from -addnode - threadGroup->create_thread(boost::bind(&TraceThread, "addcon", &ThreadOpenAddedConnections)); + threadGroup.create_thread(boost::bind(&TraceThread, "addcon", &ThreadOpenAddedConnections)); // Initiate outbound connections - threadGroup->create_thread(boost::bind(&TraceThread, "opencon", &ThreadOpenConnections)); + threadGroup.create_thread(boost::bind(&TraceThread, "opencon", &ThreadOpenConnections)); // Process messages - threadGroup->create_thread(boost::bind(&TraceThread, "msghand", &ThreadMessageHandler)); + threadGroup.create_thread(boost::bind(&TraceThread, "msghand", &ThreadMessageHandler)); // Dump network addresses - threadGroup->create_thread(boost::bind(&LoopForever, "dumpaddr", &DumpAddresses, 10000)); + threadGroup.create_thread(boost::bind(&LoopForever, "dumpaddr", &DumpAddresses, 10000)); } bool StopNode() @@ -1826,23 +1824,10 @@ bool StopNode() printf("StopNode()\n"); GenerateBitcoins(false, NULL); MapPort(false); - fShutdown = true; nTransactionsUpdated++; - int64 nStart = GetTime(); if (semOutbound) for (int i=0; ipost(); - do - { - int nThreadsRunning = 0; - for (int n = 0; n < THREAD_MAX; n++) - nThreadsRunning += vnThreadsRunning[n]; - if (nThreadsRunning == 0) - break; - if (GetTime() - nStart > 20) - break; - MilliSleep(20); - } while(true); MilliSleep(50); DumpAddresses(); -- cgit v1.2.3