Example #1
0
void TimerBase::sharedTimerFired()
{
    // Do a re-entrancy check.
    if (timersReadyToFire)
        return;

    double fireTime = currentTime();
    Vector<TimerBase*> firingTimers;
    HashSet<const TimerBase*> firingTimersSet;

    timersReadyToFire = &firingTimersSet;

    collectFiringTimers(fireTime, firingTimers);
    fireTimers(fireTime, firingTimers);

    timersReadyToFire = 0;

    updateSharedTimer();
}
Example #2
0
    void TimerMonitor::operator()()
    {
      bool shouldShutdown = false;

#ifndef _LINUX
      pthread_setname_np("com.zslib.timer");
#endif

      do
      {
        Duration duration;
        // wait completed, do notifications from select
        {
          AutoRecursiveLock lock(mLock);
          shouldShutdown = mShouldShutdown;

          duration = fireTimers();
        }

        boost::unique_lock<boost::mutex> flagLock(mFlagLock);
        mFlagNotify.timed_wait<Duration>(flagLock, duration);

        // notify all those timers needing to be notified
      } while (!shouldShutdown);

      {
        AutoRecursiveLock lock(mLock);

        // go through timers and cancel them completely
        for (TimerMap::iterator monIter = mMonitoredTimers.begin(); monIter != mMonitoredTimers.end(); ) {
          TimerMap::iterator current = monIter;
          ++monIter;

          TimerPtr timer = current->second.lock();
          if (timer)
            timer->background(false);
        }
        mMonitoredTimers.clear();
      }
    }