void CPathEstimator::InitEstimator(const std::string& name) { int numThreads = configHandler.GetInt("HardwareThreadCount", 0); #if 0 // FIXME mantis #1033 #if (BOOST_VERSION >= 103500) if (numThreads == 0) numThreads = boost::thread::hardware_concurrency(); #else # ifdef USE_GML if (numThreads == 0) numThreads = GML_CPU_COUNT; # endif #endif #else //if 0 numThreads = 1; #endif if (numThreads > 1) { // spawn the threads for InitVerticesAndBlocks() SpawnThreads(numThreads, 0); JoinThreads(numThreads, 0); char loadMsg[512]; sprintf(loadMsg, "Reading estimate path costs (%d threads)", numThreads); PrintLoadMsg(loadMsg); if (!ReadFile(name)) { char calcMsg[512]; sprintf(calcMsg, "Analyzing map accessibility [%d] (%d threads)", BLOCK_SIZE, numThreads); PrintLoadMsg(calcMsg); // re-spawn the threads for CalculateBlockOffsets() SpawnThreads(numThreads, 1); JoinThreads(numThreads, 1); // re-spawn the threads for EstimatePathCosts() SpawnThreads(numThreads, 2); JoinThreads(numThreads, 2); WriteFile(name); } } else { // no threading InitVerticesAndBlocks(0, nbrOfVertices, 0, nbrOfBlocks); PrintLoadMsg("Reading estimate path costs (1 thread)"); if (!ReadFile(name)) { char calcMsg[512]; sprintf(calcMsg, "Analyzing map accessibility [%d] (1 thread)", BLOCK_SIZE); PrintLoadMsg(calcMsg); CalcOffsetsAndPathCosts(0, nbrOfBlocks); WriteFile(name); } } }
BOOL CSocketThreadManager::Initialize(unsigned long ulThreadCount, LPCSTR lpClassName) { try { //Are we initialized? if (m_bInitialized) { //Report it ReportError("Initialize","Already initialized!"); //Exit return FALSE; } //Check the number of threads if (ulThreadCount>MAX_THREADS) { //Report it ReportError("Initialize","Too many threads to spawn!"); //Exit return FALSE; } //Check the number of threads if (!ulThreadCount) { //Report it ReportError("Initialize","Can't have zero threads!"); //Exit return FALSE; } //Save the count m_ulThreadCount=ulThreadCount; //Try to spawn the threads return SpawnThreads(lpClassName); } ERROR_HANDLER_RETURN("Initialize",FALSE) }