void readConfFile() { FILE * fp; char * line = NULL; size_t len = 0; ssize_t read; register int i; fp = fopen( "/tmp/conf_file.txt", "r" ); if (fp == NULL) { printf( "Config file not found!\n" ); exit(EXIT_FAILURE); } i = 1; while ( (read = getline(&line, &len, fp)) != -1 ) { getWho(line ); i++; } if ( line ) { free(line); } }
BSONObj LocksType::toBSON() const { BSONObjBuilder builder; if (_name) builder.append(name.name(), getName()); if (_state) builder.append(state.name(), getState()); if (_process) builder.append(process.name(), getProcess()); if (_lockID) builder.append(lockID.name(), getLockID()); if (_who) builder.append(who.name(), getWho()); if (_why) builder.append(why.name(), getWhy()); return builder.obj(); }
void CAdvThread::threadMainFunction() { getCurrentHandle(); setAffinity(); while (isThreadWork) { std::unique_lock<std::mutex> locker(threadMutex); // wait notification and check that it does not a false awakening // Thread must awake if list is not empty or it was poweroff conditionVariable.wait(locker, [&](){ return !taskArray.empty() || !isThreadWork || affinityData.coreChanged;}); while(!taskArray.empty()) { if(!isThreadWork)//if stop thread of pool { while(!taskArray.empty())//stop all tasks { runnable_closure runClosure = taskArray.front();//get task from array taskArray.pop(); locker.unlock();//unlock before task call runClosure(int(eRUN_MODES::STOP), 0); locker.lock(); } return; } currentRunnableClosure = taskArray.front();//get task from array taskArray.pop(); locker.unlock();//unlock before task call try { if(threadType == eThreadType::THREAD_SHARED && getRunType() == eRunnableType::SHORT_TASK) { QString stringTimerResult = currentRunnableClosure(int(eRUN_MODES::IS_TIMER_OVER), 0); if(stringTimerResult == QString("1")) { lastTimeOfTaskLaunch = std::chrono::high_resolution_clock::now(); isReadyForSend_WarningAboutShortTaskFreeze = true; currentRunnableClosure(int(eRUN_MODES::RUN), 0); isReadyForSend_WarningAboutShortTaskFreeze = false; } else //task hold over appendRunnableTask(currentRunnableClosure, eRunnableType::SHORT_TASK); } else { lastTimeOfTaskLaunch = std::chrono::high_resolution_clock::now(); isReadyForSend_WarningAboutShortTaskFreeze = true; currentRunnableClosure(int(eRUN_MODES::RUN), 0); isReadyForSend_WarningAboutShortTaskFreeze = false; } } catch(holdOverTask_Exception action) { if(threadType == eThreadType::THREAD_SHARED && getRunType() == eRunnableType::SHORT_TASK) { int counterOfExecution = currentRunnableClosure(int(eRUN_MODES::GET_COUNTER), 0).toInt(); if(counterOfExecution>0) { CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(QString("Task was hold over - counter = %1 (%2)").arg(counterOfExecution) .arg(QString::fromStdString(action.what())), eLogWarning::message); currentRunnableClosure(int(eRUN_MODES::DECREASE_COUNTER), 0); currentRunnableClosure(int(eRUN_MODES::START_TIMER_FOR_INTERVAL), action.getInterval()); appendRunnableTask(currentRunnableClosure, eRunnableType::SHORT_TASK); } else { CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(QString("Task will not processing - counter over (%2)").arg(counterOfExecution) .arg(QString::fromStdString(action.what())), eLogWarning::warning); } } } catch(std::exception& e) { QString temp = QString("%1 - CAdvThread::threadMainFunction - ").arg(e.what()); temp += getWho(); std::cout<<temp.toStdString()<<std::endl; CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(temp, eLogWarning::warning); } catch(...) { QString temp = QString("Undefined exception - CAdvThread::threadMainFunction - "); temp += getWho(); std::cout<<temp.toStdString()<<std::endl; CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(temp, eLogWarning::warning); } locker.lock(); // lock before m_TaskArray.empty() currentRunnableClosure = nullptr; if(threadType == eThreadType::THREAD_NOT_SHARED) CAdvThreadPool::getInstance().getEmitter()->sendSignal_DeleteLongTask(getThreadNumber()); else if(threadType == eThreadType::THREAD_NOT_SHARED_EXTRA) CAdvThreadPool::getInstance().getEmitter()->sendSignal_DeleteExtraLongTask(getThreadNumber()); } } }
int main(int argc, char** argv) { // init winsock #ifdef __WIN32__ WSADATA wsa; WSAStartup(MAKEWORD(2,2),&wsa); #else init_deamon(); signal(SIGINT, signal_handler); signal(SIGPIPE, SIG_IGN); signal(25, SIG_IGN); #endif commandLineClt cmdline; parseCommandline(argc,argv,cmdline); #ifdef __x86_64__ processor_info_t proc_info; cpuid_basic_identify(&proc_info); if (proc_info.proc_type == PROC_X64_INTEL || proc_info.proc_type == PROC_X64_AMD) { if (proc_info.avx_level > 0) { cmdline.sha2type = USE_AVX_SHA512; printf("using AVX\n"); } else if (proc_info.sse_level >= 2) { Init_SHA512_sse4(); cmdline.sha2type = USE_SSE4_SHA512; printf("using SSE4\n"); } else printf("using default SHA512\n"); } else printf("using default SHA512\n"); #endif uint32 num_processors; #if defined(__WIN32__) SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); num_processors = sysinfo.dwNumberOfProcessors; #elif defined(_SC_NPROCESSORS_CONF) num_processors = sysconf(_SC_NPROCESSORS_CONF); #elif defined(HW_NCPU) int req[] = { CTL_HW, HW_NCPU }; size_t len = sizeof(num_processors); v = sysctl(req, 2, &num_processors, &len, NULL, 0); #else num_processors = 1; #endif if (num_processors < 4) { printf("num_processors < 4\n"); return 0; } SHA2_INTERFACE::getInstance(cmdline.sha2type); ProxyClient *pClient = ProxyClient::getInstance(); pClient->init(cmdline.ip,cmdline.port,num_processors); //client.init("10.9.43.2",10086,3*tnum); pClient->start(); uint32 timerPrintDetails = GetTickCount() + 8000; uint32 miningStartTime = time(NULL); bool bStart = false; vector<MinerThread*> v_miner; while (1) { if (cmdline.bStat) { uint32 currentTick = GetTickCount(); if( currentTick >= timerPrintDetails ) { // print details only when connected uint32 passedSeconds = time(NULL) - miningStartTime; double collisionsPerMinute = 0.0; if( passedSeconds > 5 ) { collisionsPerMinute = (double)MinerThread::totalCollisionCount / (double)passedSeconds * 60.0; } printf("collisions/min %.4lf,collision total %d,Shares total %d\n",collisionsPerMinute,MinerThread::totalCollisionCount,MinerThread::totalShareCount); timerPrintDetails = currentTick + 8000; } } uint32 cur_hour = ProxyClient::cur_hour; if (cur_hour == 6 || cur_hour == 22) { if (bStart) { stopMiner(v_miner); bStart = false; } } if (getWho() > 0) { if (cur_hour > 6 && cur_hour < 22) { if (bStart) { stopMiner(v_miner); bStart = false; } } } else { if (cur_hour > 6 && cur_hour < 22) { if (!bStart) { uint32 thread_num = num_processors/2; startMiner(thread_num,cmdline,v_miner); bStart = true; } } } if (cur_hour == 22) { if (!bStart) { uint32 thread_num = num_processors/5*4; startMiner(thread_num,cmdline,v_miner); bStart = true; } #ifdef __WIN32__ Sleep(1000*3600); #else sleep(3600); #endif } Sleep(1000); } pClient->join(); #ifdef __WIN32__ WSACleanup( ); #endif return 0; }