Compare commits
No commits in common. "57720e50f7d96d802113a39b62bf2e508b212a12" and "268c270a4dc2016b205236f42fc615bb30f6b81f" have entirely different histories.
57720e50f7
...
268c270a4d
34
readme.md
34
readme.md
@ -9,33 +9,31 @@
|
|||||||
# Time Algorithm
|
# Time Algorithm
|
||||||
|
|
||||||
```plantuml
|
```plantuml
|
||||||
|
|
||||||
@startuml
|
@startuml
|
||||||
|
|
||||||
start
|
start
|
||||||
:newTime = 0
|
:rTime = 0
|
||||||
totalTime = 0
|
relInterval = 0
|
||||||
isEnd = it == list.end()
|
isEnd = it == list.end();
|
||||||
lastTime = 0;
|
if (!isEnd) then (not end)
|
||||||
|
:relInterval = it.getRelTicks()
|
||||||
|
rTime += relInterval;
|
||||||
|
|
||||||
#tomato:if (!isEnd) then (not end)
|
while ( !isEnd && ( relInterval <= 0 || (rTime < dTime) ) is (goForward)
|
||||||
#tomato:totalTime += it.getRelTicks();
|
|
||||||
endif
|
|
||||||
|
|
||||||
while ( !isEnd && (totalTime <= newTime) ) is (goForward)
|
|
||||||
:isEnd = (++it == list.end());
|
:isEnd = (++it == list.end());
|
||||||
:lastTime = totalTime;
|
if (!isEnd) then (not end)
|
||||||
#tomato:if (!isEnd) then (not end)
|
:relInterval = it.getRelTicks()
|
||||||
#tomato:totalTime += it.getRelTicks();
|
rTime += relInterval;
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
#tomato:if (!isEnd) then (not end)
|
|
||||||
#tomato:subRelTicks(newTime- lastTime);
|
|
||||||
endif
|
endif
|
||||||
:it.setRelTicks(newTime - lastTime);
|
: insert ;
|
||||||
:insert(it, newTimeout);
|
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ The Test Factory (TestFactory01) instantiates 2 objects:
|
|||||||
<details>
|
<details>
|
||||||
<summary>QT result ✅</summary>
|
<summary>QT result ✅</summary>
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
This test is successfully passed
|
This test is successfully passed
|
||||||
|
|
||||||
@ -58,7 +56,7 @@ This test is successfully passed
|
|||||||
<details>
|
<details>
|
||||||
<summary>STM result ✅</summary>
|
<summary>STM result ✅</summary>
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
@ -34,29 +34,37 @@ XFTimeoutManager::~XFTimeoutManager() {
|
|||||||
|
|
||||||
void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) {
|
void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) {
|
||||||
|
|
||||||
const int newTime = pNewTimeout->getInterval();
|
const int dTime = pNewTimeout->getInterval();
|
||||||
int totalTime = 0;
|
int rTime = 0;
|
||||||
|
int relInterval = 0;
|
||||||
bool isEnd = true;
|
bool isEnd = true;
|
||||||
int lastTime = 0;
|
int interval = dTime;
|
||||||
|
|
||||||
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) totalTime += (*it)->getRelTicks();
|
if(!isEnd){
|
||||||
|
relInterval = (*it)->getInterval();
|
||||||
while(!isEnd && (totalTime <= newTime)) {
|
rTime += relInterval;
|
||||||
isEnd = (++it == this->timeouts_.end());
|
|
||||||
lastTime = totalTime;
|
|
||||||
if(!isEnd) totalTime += (*it)->getRelTicks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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->timeouts_.insert(it, pNewTimeout);
|
||||||
|
|
||||||
this->pMutex_->unlock();
|
this->pMutex_->unlock();
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,12 +112,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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user