Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // funçao de thread que verifica quais Nos estao inativos por timer_interv segundos
- void *erase_nodes( void *ptr )
- {
- struct timespec t1;
- struct timespec t2;
- struct timespec deltaT; // diferenca entre o timestamp atual e anterior
- std::list<nodes>::iterator it; // variavel para percorrer a lista
- while(1)
- {
- //usleep(10); // delay de mais ou menos 1 segundo, depende do processador
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t2); // pega timestamp atual
- //std::cout << "erase_nodes:" << timer_++ << endl;
- for (it = nodes_RTS.begin(); it != nodes_RTS.end(); it++) { // percorre a lista
- //pthread_mutex_lock(&lock2); // protege a variavel t1.tv_sec contra outras threads
- t1.tv_nsec = (*it).t1;
- //pthread_mutex_unlock(&lock2); // libera a variavel
- deltaT.tv_nsec = diff(t1, t2).tv_nsec; // armazena o delta dos timestamps
- if(deltaT.tv_nsec > timer_interv) // nenhum pacote foi enviado nos ultimos timer_interv segundos
- {
- std::cout << "No rm:" << (*it).num_node << endl;
- //std::cout << "deltaT:" << deltaT.tv_nsec << endl;
- it = nodes_RTS.erase(it); // remove Noh
- }
- }
- }
- }
- // verifica se Noh ja existe e adiciona a lista nodes_RTS
- void Mac802_11t::add_list_RTS(int node)
- {
- bool add = true;
- struct timespec t1;
- std::list<nodes>::iterator it; // variavel para percorrer a lista: it
- list_rts = (struct nodes*)malloc(sizeof(struct nodes)); // variavel para guardar informaçoes sobre o Noh na lista
- //percorre a lista
- for (it = nodes_RTS.begin(); it != nodes_RTS.end(); it++)
- {
- if((*it).num_node == node) { // verifica se Noh ja existe na lista
- add = false;
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
- (*it).t1 = t1.tv_nsec; // guarda timestamp do Noh
- break; // sai porque ja achou o noh procurado
- }
- }
- if( add ) // o Noh ainda nao existe na lista ou foi removido
- {
- add = false;
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
- list_rts->t1 = t1.tv_nsec; // guarda timestamp do Noh
- list_rts->num_node = node; // guarda o numero do Noh
- nodes_RTS.push_back(*list_rts); // adiciona o Noh a lista
- std::cout << "No " << list_rts->num_node <<
- " adicionado" //<< endl;
- << " N:" << nodes_RTS.size() //<< endl;
- << " Fator atual: " << calc_factor() << endl;
- }
- free(list_rts); // libera variavel
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement