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 @startuml
start start
:rTime = 0 :newTime = 0
relInterval = 0 totalTime = 0
isEnd = it == list.end() isEnd = it == list.end()
lTime = 0; lastTime = 0;
if (!isEnd) then (not end)
:relInterval = it.getRelTicks()
rTime += relInterval;
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()); :isEnd = (++it == list.end());
if (!isEnd) then (not end) :lastTime = totalTime;
:relInterval = it.getRelTicks() #tomato:if (!isEnd) then (not end)
lTime = rTime #tomato:totalTime += it.getRelTicks();
rTime += relInterval;
endif endif
endwhile endwhile
#tomato:if (!isEnd) then (not end)
#tomato:subRelTicks(newTime- lastTime);
endif endif
if (!isEnd) then (not end) :it.setRelTicks(newTime - lastTime);
: subRelTicks(dTime- lTime); :insert(it, newTimeout);
endif
:it.setRelTicks(dTime - rTime);
:insert(it, timeout);
@enduml @enduml

View File

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