Compare commits

..

3 Commits

Author SHA1 Message Date
57720e50f7 test for result test picture 2023-10-21 15:45:01 +02:00
05f186188f clean algo (work for all tests) 2023-10-21 15:42:56 +02:00
20fd0631c6 algo work on test 1 2023-10-21 13:25:40 +02:00
2 changed files with 31 additions and 37 deletions

View File

@ -9,31 +9,33 @@
# Time Algorithm
```plantuml
@startuml
start
:rTime = 0
relInterval = 0
isEnd = it == list.end();
if (!isEnd) then (not end)
:relInterval = it.getRelTicks()
rTime += relInterval;
:newTime = 0
totalTime = 0
isEnd = it == list.end()
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()
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
: insert ;
:it.setRelTicks(newTime - lastTime);
:insert(it, newTimeout);
@enduml
```
@ -48,7 +50,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
@ -56,7 +58,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,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 interval = dTime;
int lastTime = 0;
this->pMutex_->lock();
TimeoutList::iterator it = this->timeouts_.begin();
isEnd = (it == this->timeouts_.end());
if(!isEnd){
relInterval = (*it)->getInterval();
rTime += relInterval;
}
if(!isEnd) totalTime += (*it)->getRelTicks();
while(!isEnd && ( relInterval <= 0 || (rTime > dTime) )) {
while(!isEnd && (totalTime <= newTime)) {
isEnd = (++it == this->timeouts_.end());
interval = rTime - dTime;
if(!isEnd) {
relInterval = (*it)->getRelTicks();
rTime += relInterval;
}
lastTime = totalTime;
if(!isEnd) totalTime += (*it)->getRelTicks();
}
if(it == this->timeouts_.begin())
if(!isEnd) (*it)->substractFromRelTicks(interval);
it--;
pNewTimeout->setRelTicks(interval);
if(!isEnd) (*it)->substractFromRelTicks(newTime-lastTime);
pNewTimeout->setRelTicks(newTime-lastTime);
this->timeouts_.insert(it, pNewTimeout);
this->pMutex_->unlock();
return;
}
@ -112,12 +104,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();
}