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 # Time Algorithm
```plantuml ```plantuml
@startuml @startuml
start start
:rTime = 0 :newTime = 0
relInterval = 0 totalTime = 0
isEnd = it == list.end(); isEnd = it == list.end()
if (!isEnd) then (not end) lastTime = 0;
: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)
rTime += relInterval; #tomato:totalTime += it.getRelTicks();
endif endif
endwhile endwhile
#tomato:if (!isEnd) then (not end)
#tomato:subRelTicks(newTime- lastTime);
endif endif
: insert ; :it.setRelTicks(newTime - lastTime);
:insert(it, newTimeout);
@enduml @enduml
``` ```
@ -48,7 +50,7 @@ The Test Factory (TestFactory01) instantiates 2 objects:
<details> <details>
<summary>QT result ✅</summary> <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 This test is successfully passed
@ -56,7 +58,7 @@ This test is successfully passed
<details> <details>
<summary>STM result ✅</summary> <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> </details>

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 interval = dTime; 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)->getInterval();
rTime += relInterval;
}
while(!isEnd && ( relInterval <= 0 || (rTime > dTime) )) { while(!isEnd && (totalTime <= newTime)) {
isEnd = (++it == this->timeouts_.end()); isEnd = (++it == this->timeouts_.end());
interval = rTime - dTime; lastTime = totalTime;
if(!isEnd) { if(!isEnd) totalTime += (*it)->getRelTicks();
relInterval = (*it)->getRelTicks();
rTime += relInterval;
} }
}
if(it == this->timeouts_.begin())
if(!isEnd) (*it)->substractFromRelTicks(interval); if(!isEnd) (*it)->substractFromRelTicks(newTime-lastTime);
it--;
pNewTimeout->setRelTicks(interval); pNewTimeout->setRelTicks(newTime-lastTime);
this->timeouts_.insert(it, pNewTimeout); this->timeouts_.insert(it, pNewTimeout);
this->pMutex_->unlock(); this->pMutex_->unlock();
return;
} }
@ -112,12 +104,12 @@ void XFTimeoutManager::tick() {
while (!isEmpty && (rTime <= 0) ) { while (!isEmpty && (rTime <= 0) ) {
rTime = timeout->getRelTicks();
XFDispatcher::getInstance()->pushEvent(timeout); XFDispatcher::getInstance()->pushEvent(timeout);
this->timeouts_.pop_front(); this->timeouts_.pop_front();
timeout = this->timeouts_.front(); timeout = this->timeouts_.front();
isEmpty = this->timeouts_.empty(); isEmpty = this->timeouts_.empty();
if(!isEmpty) rTime = timeout->getRelTicks();
} }