Compare commits

..

No commits in common. "57720e50f7d96d802113a39b62bf2e508b212a12" and "268c270a4dc2016b205236f42fc615bb30f6b81f" have entirely different histories.

2 changed files with 38 additions and 32 deletions

View File

@ -9,33 +9,31 @@
# Time Algorithm
```plantuml
@startuml
start
:newTime = 0
totalTime = 0
isEnd = it == list.end()
lastTime = 0;
:rTime = 0
relInterval = 0
isEnd = it == list.end();
if (!isEnd) then (not end)
:relInterval = it.getRelTicks()
rTime += relInterval;
#tomato:if (!isEnd) then (not end)
#tomato:totalTime += it.getRelTicks();
endif
while ( !isEnd && (totalTime <= newTime) ) is (goForward)
while ( !isEnd && ( relInterval <= 0 || (rTime < dTime) ) is (goForward)
:isEnd = (++it == list.end());
:lastTime = totalTime;
#tomato:if (!isEnd) then (not end)
#tomato:totalTime += it.getRelTicks();
if (!isEnd) then (not end)
:relInterval = it.getRelTicks()
rTime += relInterval;
endif
endwhile
#tomato:if (!isEnd) then (not end)
#tomato:subRelTicks(newTime- lastTime);
endif
:it.setRelTicks(newTime - lastTime);
:insert(it, newTimeout);
: insert ;
@enduml
```
@ -50,7 +48,7 @@ The Test Factory (TestFactory01) instantiates 2 objects:
<details>
<summary>QT result ✅</summary>
![result.PNG](./test-bench%2Ftest1%2Fide-qtcreator-test1-idf%2Fresult.PNG)
![result.PNG](test-bench%2Ftest1%2Fide-qtcreator-test1-idf%2Fresult.PNG)
This test is successfully passed
@ -58,7 +56,7 @@ This test is successfully passed
<details>
<summary>STM result ✅</summary>
![result.png](./test-bench%2Ftest1%2Fide-cubeide-test1-idf%2Fresult.png)
![result.png](test-bench%2Ftest1%2Fide-cubeide-test1-idf%2Fresult.png)
</details>

View File

@ -34,29 +34,37 @@ XFTimeoutManager::~XFTimeoutManager() {
void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) {
const int newTime = pNewTimeout->getInterval();
int totalTime = 0;
const int dTime = pNewTimeout->getInterval();
int rTime = 0;
int relInterval = 0;
bool isEnd = true;
int lastTime = 0;
int interval = dTime;
this->pMutex_->lock();
TimeoutList::iterator it = this->timeouts_.begin();
isEnd = (it == this->timeouts_.end());
if(!isEnd) totalTime += (*it)->getRelTicks();
while(!isEnd && (totalTime <= newTime)) {
isEnd = (++it == this->timeouts_.end());
lastTime = totalTime;
if(!isEnd) totalTime += (*it)->getRelTicks();
if(!isEnd){
relInterval = (*it)->getInterval();
rTime += relInterval;
}
if(!isEnd) (*it)->substractFromRelTicks(newTime-lastTime);
while(!isEnd && ( relInterval <= 0 || (rTime > dTime) )) {
isEnd = (++it == this->timeouts_.end());
interval = rTime - dTime;
if(!isEnd) {
relInterval = (*it)->getRelTicks();
rTime += relInterval;
}
}
if(it == this->timeouts_.begin())
pNewTimeout->setRelTicks(newTime-lastTime);
if(!isEnd) (*it)->substractFromRelTicks(interval);
it--;
pNewTimeout->setRelTicks(interval);
this->timeouts_.insert(it, pNewTimeout);
this->pMutex_->unlock();
return;
}
@ -104,12 +112,12 @@ void XFTimeoutManager::tick() {
while (!isEmpty && (rTime <= 0) ) {
rTime = timeout->getRelTicks();
XFDispatcher::getInstance()->pushEvent(timeout);
this->timeouts_.pop_front();
timeout = this->timeouts_.front();
isEmpty = this->timeouts_.empty();
if(!isEmpty) rTime = timeout->getRelTicks();
}