/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { manager_t* managerPtr; client_t** clients; TIMER_T start; TIMER_T stop; /* Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_params[PARAM_CLIENTS]); managerPtr = initializeManager(); assert(managerPtr != NULL); clients = initializeClients(managerPtr); assert(clients != NULL); long numThread = global_params[PARAM_CLIENTS]; TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); /* Run transactions */ printf("Running clients... "); fflush(stdout); GOTO_SIM(); TIMER_READ(start); #ifdef OTM #pragma omp parallel { client_run(clients); } #else thread_start(client_run, (void*)clients); #endif TIMER_READ(stop); GOTO_REAL(); puts("done."); printf("Time = %0.6lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); checkTables(managerPtr); /* Clean up */ printf("Deallocating memory... "); fflush(stdout); freeClients(clients); /* * TODO: The contents of the manager's table need to be deallocated. */ manager_free(managerPtr); puts("done."); fflush(stdout); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); thread_shutdown(); MAIN_RETURN(0); }
void FishinoServer::begin() { // free any previous run data freeClients(); // start server with 100 seconds timeout _accepting = Fishino.startServer(_port, 100); }
void freeDB(pDatabase p) { freeVoos(p->voos); /*Em últmo por causa das dependências nos voos*/ freeCidades(p->cidades); freeClients(p->clients); freeUsers(p->users); free(p); }
FishinoClient FishinoServer::available() { if(!_accepting) begin(); if(!_accepting) return FishinoClient(); if(_nClients && !_processBuffers && _curClient >= _nClients) { _processBuffers = true; _curClient = 0; } // if we're emptying buffers, do it if(_processBuffers) { if(_curClient >= _nClients) _curClient = 0; // if we've still some buffer to process.... while(_curClient < _nClients) { uint8_t sock = _clientSocks[_curClient++]; FishinoSockBuf *buf = fishinoSockBuffers().GetBuf(sock); if(buf && buf->hasData()) return FishinoClient(sock); } _processBuffers = false; } // if it gets to here, we have either some socket to process // or all has been processed AND buffers are empty // so we shall check latter case if(!_nClients || _curClient >= _nClients) { freeClients(); Fishino.pollServer(false, _clientSocks, _nClients); // preallocate buffers for clients // so they don't get wiped by last client delete for(uint8_t i = 0; i < _nClients; i++) fishinoSockBuffers().AllocBuf(_clientSocks[i]); } // if still no sockets, just leave if(_curClient >= _nClients) return FishinoClient(); // create a client for current socket and return it uint8_t sock = _clientSocks[_curClient++]; return FishinoClient(sock); }
void FishinoServer::end() { Fishino.stopServer(); freeClients(); }
FishinoServer::~FishinoServer() { if(_accepting) end(); freeClients(); }