Alex Bikfalvi
SimStream Documentation
LinkQueue.cpp
00001 #include "Headers.h" 00002 #include "LinkQueue.h" 00003 00004 CLinkQueue::CLinkQueue( 00005 __uint32 size 00006 ) 00007 { 00008 assert(size); 00009 00010 this->size = size; 00011 this->queue = new CPacket*[this->size]; 00012 this->time = new __time[this->size]; 00013 this->ptr = 0; 00014 this->count = 0; 00015 this->usage = 0; 00016 } 00017 00018 CLinkQueue::~CLinkQueue() 00019 { 00020 // Delete packets stored in the queue (start from 1, because event 0 has an associated queue event and will be deleted with the event) 00021 for(__uint32 index = 1; index < this->count; index++) 00022 { 00023 __uint32 idx = (this->ptr + index) % this->size; 00024 00025 this->queue[idx]->Delete(); 00026 delete this->queue[idx]; 00027 } 00028 00029 delete[] this->queue; 00030 delete[] this->time; 00031 } 00032 00033 void CLinkQueue::Add(__time time, CPacket* packet) 00034 { 00035 assert(packet); 00036 assert(this->count < this->size); 00037 00038 __uint32 index = (this->ptr + this->count) % this->size; 00039 00040 this->queue[index] = packet; 00041 this->time[index] = time; 00042 this->count++; 00043 this->usage += packet->Size(); 00044 } 00045 00046 void CLinkQueue::Remove() 00047 { 00048 assert(this->count > 0); 00049 00050 this->usage -= this->queue[this->ptr]->Size(); 00051 this->ptr = (this->ptr + 1) % this->size; 00052 this->count--; 00053 }
Last updated: February 8, 2011