start an non-fonctionnal algoritm
This commit is contained in:
parent
92c2faa858
commit
9059d77b3e
@ -34,9 +34,69 @@ XFTimeoutManager::~XFTimeoutManager() {
|
||||
|
||||
void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) {
|
||||
|
||||
const int desireInterval = pNewTimeout->getInterval();
|
||||
int intervalOfTimeout = 0;
|
||||
int ticks;
|
||||
|
||||
this->pMutex_->lock();
|
||||
|
||||
if(this->timeouts_.empty()) {
|
||||
ticks = (desireInterval-intervalOfTimeout);
|
||||
if(ticks<=0) ticks = 0;
|
||||
pNewTimeout->setRelTicks(ticks);
|
||||
this->timeouts_.push_back(pNewTimeout);
|
||||
this->pMutex_->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
TimeoutList::iterator it = this->timeouts_.begin();
|
||||
while(intervalOfTimeout < desireInterval) {
|
||||
if(++it == this->timeouts_.end()){
|
||||
ticks = (desireInterval-intervalOfTimeout);
|
||||
if(ticks<=0) ticks = 0;
|
||||
pNewTimeout->setRelTicks(ticks);
|
||||
this->timeouts_.push_back(pNewTimeout);
|
||||
this->pMutex_->unlock();
|
||||
return;
|
||||
} else {
|
||||
intervalOfTimeout += (*it)->getRelTicks();
|
||||
}
|
||||
}
|
||||
|
||||
if(intervalOfTimeout == desireInterval) {
|
||||
if(++it == this->timeouts_.end()) {
|
||||
ticks = (desireInterval-intervalOfTimeout);
|
||||
if(ticks<=0) ticks = 0;
|
||||
pNewTimeout->setRelTicks(ticks);
|
||||
this->timeouts_.push_back(pNewTimeout);
|
||||
this->pMutex_->unlock();
|
||||
return;
|
||||
} else {
|
||||
|
||||
while((*it)->getRelTicks() == 0) {
|
||||
if(++it == this->timeouts_.end()) {
|
||||
ticks = (desireInterval-intervalOfTimeout);
|
||||
if(ticks<=0) ticks = 0;
|
||||
pNewTimeout->setRelTicks(ticks);
|
||||
this->timeouts_.push_back(pNewTimeout);
|
||||
this->pMutex_->unlock();
|
||||
return;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO change for take care of 10ms ecart of timeout
|
||||
ticks = (desireInterval-intervalOfTimeout);
|
||||
ticks = ticks > 0 ? ticks/this->tickInterval_ : 0;
|
||||
|
||||
(*it)->substractFromRelTicks(ticks);
|
||||
pNewTimeout->setRelTicks(ticks);
|
||||
this->timeouts_.insert(--it, pNewTimeout);
|
||||
this->pMutex_->unlock();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
@ -70,22 +130,24 @@ void XFTimeoutManager::unscheduleTimeout(int32_t timeoutId, interface::XFBehavio
|
||||
}
|
||||
|
||||
void XFTimeoutManager::tick() {
|
||||
//Trace::out("[DEBUG] - Tick");
|
||||
|
||||
if(!this->timeouts_.empty()) {
|
||||
TimeoutList::iterator it;
|
||||
|
||||
this->pMutex_->lock();
|
||||
for(it=this->timeouts_.begin(); it != this->timeouts_.end(); it++) {
|
||||
if((*it)->getRelTicks() > 0) {
|
||||
(*it)->substractFromRelTicks(this->tickInterval_);
|
||||
} else {
|
||||
XFEvent* ev = *(it);
|
||||
XFDispatcher::getInstance()->pushEvent(ev);
|
||||
it = this->timeouts_.erase(it);
|
||||
it--;
|
||||
}
|
||||
|
||||
XFTimeout* timeout = this->timeouts_.front();
|
||||
timeout->substractFromRelTicks(tickInterval_);
|
||||
|
||||
while (timeout->getRelTicks() <= 0 ) {
|
||||
|
||||
XFDispatcher::getInstance()->pushEvent(timeout);
|
||||
this->timeouts_.pop_front();
|
||||
timeout = this->timeouts_.front();
|
||||
|
||||
}
|
||||
|
||||
this->pMutex_->unlock();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user