void *TorumProcess(void* queue) { printf("TorumProcess Thread created\n"); wqueue<Packet*>*m_queue=(wqueue<Packet*>*)queue; Torum *node = Torum::getInstance(); sleep(5); // Remove 1 item at a time and process it. Blocks if no items are // available to process. for (int i = 0;; i++) { printf("TorumProcessing Thread , loop %d - waiting for item...\n", i); Packet* item = m_queue->remove(); //printf("thread loop %d - got one item\n", i); //printf("Received: messageType - %d, SEQ number - %ld\n",item->TYPE, item->SEQ); if (item->TYPE == SEND_TOKEN){ printf("SEND_TOKEN recieved from Node %d and packet type is %d\n",item->ORIGIN,item->TYPE); node->receiveToken(*item); }else if (item->TYPE == MAKE_REQUEST){ printf("MAKE_REQUEST recieved from Controller %d and packet type is %d\n",item->ORIGIN,item->TYPE); node->requestCS(); }else if (item->TYPE == HAVE_TOKEN){ printf("HAVE_TOKEN recieved from Node %d and packet type is %d\n",item->ORIGIN,item->TYPE); node->receiveHaveTkn(*item); }else if (item->TYPE == RELEASE){ printf("RELEASE recieved from Node %d and packet type is %d\n",item->ORIGIN,item->TYPE); node->receiveRelease(*item); }else if (item->TYPE == REQUEST){ printf("REQUEST recieved from Node %d and packet type is %d\n",item->ORIGIN,item->TYPE); node->receiveRequest(*item); } delete item; } return NULL; }
void *TorumProcess(void* mqueue) { printf("TorumProcess Thread created\n"); long messageCounter = 0; long timeCounter = 0; wqueue<Packet*>*m_queue=(wqueue<Packet*>*)mqueue; //getting time for CS grant long utime, seconds, useconds; queue<struct timeval> timequeue; Torum *node = Torum::getInstance(); sleep(5); node->displayStatus(); // Remove 1 item at a time and process it. Blocks if no items are // available to process. for (int i = 0;; i++) { printf("\nTorumProcessing Thread , loop %d - waiting for message...\n", i); Packet* item = m_queue->remove(); //printf("thread loop %d - got one item\n", i); //printf("Received: messageType - %d, SEQ number - %ld\n",item->TYPE, item->SEQ); //uncomment for unreliable //if(!randDecision()){ // printf("===>Missed a packet from Node %d(Origin: %d) and packet type is %d\n",item->sender,item->ORIGIN,item->TYPE); // delete item; // continue; //} if (item->TYPE == SEND_TOKEN){ printf("##SEND_TOKEN recieved from Node %d(Origin: %d) and packet type is %d\n",item->sender,item->ORIGIN,item->TYPE); node->flagforCS = false; struct timeval end; gettimeofday(&end, NULL); struct timeval start = timequeue.front(); seconds = end.tv_sec - start.tv_sec; useconds = end.tv_usec - start.tv_usec; utime = ((seconds) * 1000000 + useconds) + 0.5; node->receiveToken(*item); if(node->flagforCS){//node entered CS using this Token //struct timeval end; //gettimeofday(&end, NULL); //struct timeval start = timequeue.front(); timequeue.pop(); //seconds = end.tv_sec - start.tv_sec; //useconds = end.tv_usec - start.tv_usec; //utime = ((seconds) * 1000000 + useconds) + 0.5; timeCounter += utime; } if(item->sender != node->ID) messageCounter++; }else if (item->TYPE == MAKE_REQUEST){ printf("##MAKE_REQUEST recieved from Controller %d and packet type is %d\n",item->ORIGIN,item->TYPE); struct timeval start; gettimeofday(&start, NULL); timequeue.push(start); node->requestCS(); }else if (item->TYPE == HAVE_TOKEN){ if(item->sender != node->ID) messageCounter++; printf("##HAVE_TOKEN recieved from Node %d(Origin: %d) and packet type is %d\n",item->sender,item->ORIGIN,item->TYPE); node->receiveHaveTkn(*item); }else if (item->TYPE == RELEASE){ if(item->sender != node->ID) messageCounter++; printf("##RELEASE recieved from Node %d(Origin: %d) and packet type is %d\n",item->sender,item->ORIGIN,item->TYPE); node->receiveRelease(*item); }else if (item->TYPE == REQUEST){ if(item->sender != node->ID) messageCounter++; printf("##REQUEST recieved from Node %d(Origin: %d) and packet type is %d\n",item->sender,item->ORIGIN,item->TYPE); node->receiveRequest(*item); } else if(item->TYPE == END_PROCESS) { printf("##END_PROCESS recieved from Node %d(Origin: %d) and packet type is %d\n",item->sender,item->ORIGIN,item->TYPE); endProcessing(node->ID,messageCounter,timeCounter); } delete item; node->displayStatus(); } return NULL; }