Beispiel #1
0
void DefaultTimerManager::handler() {
	Common::StackLock lock(_mutex);

	const uint32 curTime = g_system->getMillis();

	// Repeat as long as there is a TimerSlot that is scheduled to fire.
	TimerSlot *slot = _head->next;
	while (slot && slot->nextFireTime < curTime) {
		// Remove the slot from the priority queue
		_head->next = slot->next;

		// Update the fire time and reinsert the TimerSlot into the priority
		// queue.
		assert(slot->interval > 0);
		slot->nextFireTime += (slot->interval / 1000);
		slot->nextFireTimeMicro += (slot->interval % 1000);
		if (slot->nextFireTimeMicro > 1000) {
			slot->nextFireTime += slot->nextFireTimeMicro / 1000;
			slot->nextFireTimeMicro %= 1000;
		}
		insertPrioQueue(_head, slot);

		// Invoke the timer callback
		assert(slot->callback);
		slot->callback(slot->refCon);

		// Look at the next scheduled timer
		slot = _head->next;
	}
}
Beispiel #2
0
TizenTimerManager::~TizenTimerManager() {
	for (Common::List<TimerSlot *>::iterator it = _timers.begin(); it != _timers.end(); ) {
		TimerSlot *slot = (*it);
		slot->Quit();
		slot->Join();
		delete slot;
		it = _timers.erase(it);
	}
}
Beispiel #3
0
void TizenTimerManager::removeTimerProc(TimerProc proc) {
	for (Common::List<TimerSlot *>::iterator it = _timers.begin(); it != _timers.end(); ++it) {
		TimerSlot *slot = (*it);
		if (slot->_callback == proc) {
			slot->Quit();
			slot->Join();
			delete slot;
			it = _timers.erase(it);
		}
	}
}
Beispiel #4
0
int TimerMaster::CascadeTimers(TimerVec *v, int index) {
  TList *l = &(*v)[index];
  for (TList::iterator it = l->begin();
       it != l->end();) {
    TimerSlot *s = &*it;
    ++it;
    s->unlink();
    InternalAddTimer(s, s->weak_timer, s->jiffies);
  }
  CHECK(l->empty());
  return index;
}
Beispiel #5
0
void TimerMaster::Update(int jiffies) {
  CHECK_GE(jiffies, timer_jiffies_);
  TimerVec &v0 = vecs_[0];
  while (jiffies - timer_jiffies_ >= 0) {
    vector<pair<TimerSlot*, boost::shared_ptr<Timer> > > timers;
    {
      boost::mutex::scoped_lock lock(mutex_);
      const int index = timer_jiffies_ & kTVMask;
      if (!index && !CascadeTimers(&vecs_[1], INDEX(1)) &&
          !CascadeTimers(&vecs_[2], INDEX(2))) {
        CascadeTimers(&vecs_[3], INDEX(3));
      }
      TList *l = &v0[index];
      for (TList::iterator it = l->begin();
           it != l->end();) {
        TimerSlot *s = &*it;
        ++it;
        s->unlink();
        boost::weak_ptr<Timer> weak_timer = s->weak_timer;
        boost::shared_ptr<Timer> timer = weak_timer.lock();
        if (weak_timer.expired()) {
          delete s;
          continue;
        }
        timers.push_back(make_pair(s, timer));
      }
    }
    const int old_timer_jiffies = timer_jiffies_;
    ++timer_jiffies_;
    for (vector<pair<TimerSlot*, boost::shared_ptr<Timer> > >::iterator it =
         timers.begin(); it != timers.end(); ++it) {
      it->second->Expired();
    }
    {
      for (int i = 0; i < timers.size(); ++i) {
        TimerSlot *s = timers[i].first;
        boost::shared_ptr<Timer> timer = timers[i].second;
        if (timer->period()) {
          boost::mutex::scoped_lock lock(mutex_);
          InternalAddTimer(s, timer, timer->timeout() + old_timer_jiffies);
        } else {
          delete s;
        }
      }
    }
  }
}
Beispiel #6
0
bool TizenTimerManager::installTimerProc(TimerProc proc, int32 interval, void *refCon, const Common::String &id) {
	TimerSlot *slot = new TimerSlot(proc, interval / 1000, refCon);

	if (IsFailed(slot->Construct())) {
		AppLog("Failed to create timer thread");
		delete slot;
		return false;
	}

	if (IsFailed(slot->Start())) {
		delete slot;
		AppLog("Failed to start timer thread");
		return false;
	}

	_timers.push_back(slot);
	return true;
}
Beispiel #7
0
bool BadaTimerManager::installTimerProc(TimerProc proc, int32 interval, void *refCon) {
	logEntered();
	TimerSlot* slot = new TimerSlot(proc, interval / 1000, refCon);

	if (IsFailed(slot->Construct(THREAD_TYPE_EVENT_DRIVEN))) {
		AppLog("Failed to create timer thread");
		delete slot;
		return false;
	}

	if (IsFailed(slot->Start())) {
		delete slot;
		AppLog("Failed to start timer thread");
		return false;
	}

	_timers.push_back(*slot);
	return true;
}