clean algo (work for all tests)

This commit is contained in:
Rémi Heredero 2023-10-21 15:42:56 +02:00
parent 20fd0631c6
commit 05f186188f
2 changed files with 26 additions and 36 deletions

View File

@ -13,30 +13,28 @@
@startuml
start
:rTime = 0
relInterval = 0
:newTime = 0
totalTime = 0
isEnd = it == list.end()
lTime = 0;
if (!isEnd) then (not end)
:relInterval = it.getRelTicks()
rTime += relInterval;
lastTime = 0;
while ( !isEnd && ( relInterval <= 0 || (rTime < dTime) ) is (goForward)
#tomato:if (!isEnd) then (not end)
#tomato:totalTime += it.getRelTicks();
endif
while ( !isEnd && (totalTime <= newTime) ) is (goForward)
:isEnd = (++it == list.end());
if (!isEnd) then (not end)
:relInterval = it.getRelTicks()
lTime = rTime
rTime += relInterval;
:lastTime = totalTime;
#tomato:if (!isEnd) then (not end)
#tomato:totalTime += it.getRelTicks();
endif
endwhile
#tomato:if (!isEnd) then (not end)
#tomato:subRelTicks(newTime- lastTime);
endif
if (!isEnd) then (not end)
: subRelTicks(dTime- lTime);
endif
:it.setRelTicks(dTime - rTime);
:insert(it, timeout);
:it.setRelTicks(newTime - lastTime);
:insert(it, newTimeout);
@enduml

View File

@ -34,37 +34,29 @@ XFTimeoutManager::~XFTimeoutManager() {
void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) {
const int dTime = pNewTimeout->getInterval();
int rTime = 0;
int relInterval = 0;
const int newTime = pNewTimeout->getInterval();
int totalTime = 0;
bool isEnd = true;
int lTime = 0;
int lastTime = 0;
this->pMutex_->lock();
TimeoutList::iterator it = this->timeouts_.begin();
isEnd = (it == this->timeouts_.end());
if(!isEnd){
relInterval = (*it)->getRelTicks();
rTime += relInterval;
}
if(!isEnd) totalTime += (*it)->getRelTicks();
while(!isEnd && ( false || (rTime <= dTime) )) {
while(!isEnd && (totalTime <= newTime)) {
isEnd = (++it == this->timeouts_.end());
lTime = rTime;
if(!isEnd) {
relInterval = (*it)->getRelTicks();
rTime += relInterval;
}
lastTime = totalTime;
if(!isEnd) totalTime += (*it)->getRelTicks();
}
if(it == this->timeouts_.begin())
if(!isEnd) (*it)->substractFromRelTicks(dTime-lTime);
//it--;
pNewTimeout->setRelTicks(dTime-lTime);
if(!isEnd) (*it)->substractFromRelTicks(newTime-lastTime);
pNewTimeout->setRelTicks(newTime-lastTime);
this->timeouts_.insert(it, pNewTimeout);
this->pMutex_->unlock();
return;
}