Compare commits
	
		
			3 Commits
		
	
	
		
			268c270a4d
			...
			57720e50f7
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 57720e50f7 | |||
| 05f186188f | |||
| 20fd0631c6 | 
							
								
								
									
										34
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								readme.md
									
									
									
									
									
								
							@@ -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>
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||

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

 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
</details>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user