#include <nPriorizing.h>
Public Member Functions | |
bool | Fill (nSendBuffer &buffer, nBandwidthControl &control) |
void | Timestep (REAL dt) |
bool | UseBandwidth (REAL dt) |
Protected Member Functions | |
nBandwidthArbitrator () | |
~nBandwidthArbitrator () | |
Private Member Functions | |
nType | FirstType () const |
virtual void | OnChange () |
virtual bool | DoUseBandwidth (REAL dt)=0 |
virtual tHeapBase * | Heap () const |
virtual REAL | TimeScale () |
virtual REAL | PacketOverhead () |
Private Attributes | |
nBandwidthSceduler * | sceduler_ |
Friends | |
class | nBandwidthSceduler |
class | tReferencable< nBandwidthArbitrator > |
Definition at line 119 of file nPriorizing.h.
nBandwidthArbitrator::nBandwidthArbitrator | ( | ) | [protected] |
nBandwidthArbitrator::~nBandwidthArbitrator | ( | ) | [protected] |
Definition at line 139 of file nPriorizing.cpp.
References NULL, nBandwidthSceduler::RemoveArbitrator(), tHeapElement::RemoveFromHeap(), sceduler_, and tASSERT.
00140 { 00141 if ( sceduler_ ) 00142 { 00143 sceduler_->RemoveArbitrator( *this ); 00144 } 00145 00146 tASSERT( NULL == sceduler_ ); 00147 00148 this->RemoveFromHeap(); 00149 }
bool nBandwidthArbitrator::Fill | ( | nSendBuffer & | buffer, | |
nBandwidthControl & | control | |||
) |
Definition at line 152 of file nPriorizing.cpp.
References FirstType(), Heap(), nBandwidthTaskPriorizer::Next(), nBandwidthTaskPriorizer::PeekNext(), REAL, nBandwidthControl::Score(), and tHeapElement::SetVal().
Referenced by nBandwitdhDistributor::DoUseBandwidth().
00153 { 00154 // return whether a message was sent 00155 bool ret = false; 00156 00157 // find heap to use 00158 nType type = this->FirstType(); 00159 if ( type < nBandwidthTask::Type_Count ) 00160 { 00161 REAL totalPriority = 0.0f; // total prioirty of already added messages 00162 00163 bool first = true; 00164 bool goon = true; 00165 while ( goon ) 00166 { 00167 goon = false; 00168 00169 tJUST_CONTROLLED_PTR< nBandwidthTask > next = this->PeekNext( type ); 00170 if ( next ) 00171 { 00172 REAL priority = next->Priority(); 00173 REAL value = next->Val(); 00174 00175 // see if we have enough bandwidth reservers to send message 00176 if ( !first || value * this->TimeScale() > -control.Score() ) 00177 { 00178 // see if the priority of the next sent message justifies the delay caused for the messages already in the buffer 00179 if ( priority * this->PacketOverhead() > totalPriority * next->EstimateSize() ) 00180 { 00181 // extract message 00182 next = this->Next( type ); 00183 00184 // send it 00185 next->Execute( buffer, control ); 00186 00187 // sum up priority 00188 totalPriority += priority; 00189 00190 // try another one! 00191 goon = true; 00192 ret = true; 00193 } 00194 } 00195 } 00196 00197 first = false; 00198 } 00199 } 00200 00201 // reduce priority so it is not picked until the next call to Timestep 00202 this->SetVal( this->Val() - 100.0f, *this->Heap() ); 00203 00204 return ret; 00205 }
void nBandwidthArbitrator::Timestep | ( | REAL | dt | ) |
Definition at line 208 of file nPriorizing.cpp.
References GrowingArrayBase::Len(), tHeap< T >::Len(), OnChange(), tArray< T, MALLOC >::SetLen(), and nBandwidthTaskPriorizer::Tasks().
00209 { 00210 for ( int i = 0; i < nBandwidthTask::Type_Count; ++i ) 00211 { 00212 nType type = nType(i); 00213 00214 nTaskHeap& heap = this->Tasks( type ); 00215 int j; 00216 00217 static tArray< nBandwidthTask* > tasks; 00218 tasks.SetLen( 0 ); 00219 00220 // copy heap; otherwise, we would risk updating elements twice or not al all 00221 for ( j = heap.Len()-1; j>=0; --j ) 00222 { 00223 tasks[j] = heap(j); 00224 } 00225 00226 for ( j = tasks.Len()-1; j>=0; --j ) 00227 { 00228 tasks(j)->Timestep( dt ); 00229 } 00230 } 00231 00232 this->OnChange(); 00233 }
bool nBandwidthArbitrator::UseBandwidth | ( | REAL | dt | ) | [inline] |
Definition at line 127 of file nPriorizing.h.
References DoUseBandwidth().
Referenced by nBandwidthSceduler::UseBandwidth().
00127 { return DoUseBandwidth( dt ); } // consumes some bandwidth
nBandwidthArbitrator::nType nBandwidthArbitrator::FirstType | ( | ) | const [private] |
Definition at line 236 of file nPriorizing.cpp.
Referenced by Fill().
00237 { 00238 for ( int i = 0; i < nBandwidthTask::Type_Count; ++i ) 00239 { 00240 nType type = nType(i); 00241 if ( this->Tasks(type).Len() > 0 ) 00242 { 00243 return type; 00244 } 00245 } 00246 00247 return nBandwidthTask::Type_Count; 00248 }
void nBandwidthArbitrator::OnChange | ( | ) | [private, virtual] |
Reimplemented from nBandwidthTaskPriorizer.
Definition at line 251 of file nPriorizing.cpp.
References tHeap< T >::Len(), REAL, tHeapElement::SetVal(), and nBandwidthTaskPriorizer::Tasks().
Referenced by Timestep().
00252 { 00253 REAL value = 0.0f; 00254 00255 for ( int i = 0; i < nBandwidthTask::Type_Count; ++i ) 00256 { 00257 nType type = nType(i); 00258 const nTaskHeap& heap = this->Tasks(type); 00259 if ( heap.Len() > 0 ) 00260 { 00261 value += heap(0)->Val(); 00262 } 00263 } 00264 00265 this->SetVal( value, *this->Heap() ); 00266 }
virtual bool nBandwidthArbitrator::DoUseBandwidth | ( | REAL | dt | ) | [private, pure virtual] |
Implemented in nBandwitdhDistributor.
Referenced by UseBandwidth().
tHeapBase * nBandwidthArbitrator::Heap | ( | ) | const [private, virtual] |
Implements tHeapElement.
Definition at line 268 of file nPriorizing.cpp.
References nBandwidthSceduler::arbitratorHeap_, NULL, and sceduler_.
Referenced by Fill().
00269 { 00270 if ( !sceduler_ ) 00271 { 00272 return NULL; 00273 } 00274 00275 return &sceduler_->arbitratorHeap_; 00276 }
virtual REAL nBandwidthArbitrator::TimeScale | ( | ) | [inline, private, virtual] |
Reimplemented in nBandwitdhDistributor.
Definition at line 137 of file nPriorizing.h.
00137 { return 0.1f; } // higher values let really urgent messages be sent even if the bandwidth control objectd
virtual REAL nBandwidthArbitrator::PacketOverhead | ( | ) | [inline, private, virtual] |
friend class nBandwidthSceduler [friend] |
Definition at line 121 of file nPriorizing.h.
friend class tReferencable< nBandwidthArbitrator > [friend] |
Definition at line 122 of file nPriorizing.h.
Definition at line 140 of file nPriorizing.h.
Referenced by nBandwidthSceduler::AddArbitrator(), Heap(), nBandwidthArbitrator(), nBandwidthSceduler::RemoveArbitrator(), and ~nBandwidthArbitrator().