add enq cancel
[enigma2.git] / lib / base / ebase.cpp
index 7300a571994ba4fe22d4c80e3d2addab778305c5..7f84cc91196fb45fac7f9f13a3900a1379804578 100644 (file)
@@ -59,7 +59,7 @@ void eTimer::startLongTimer( int seconds )
        bActive = bSingleShot = true;
        interval = 0;
        gettimeofday(&nextActivation, 0);
-//     eDebug("this = %p\nnow sec = %d, usec = %d\nadd %d msec", this, nextActivation.tv_sec, nextActivation.tv_usec, msek);
+//     eDebug("this = %p\nnow sec = %d, usec = %d\nadd %d sec", this, nextActivation.tv_sec, nextActivation.tv_usec, seconds);
        if ( seconds > 0 )
                nextActivation.tv_sec += seconds;
 //     eDebug("next Activation sec = %d, usec = %d", nextActivation.tv_sec, nextActivation.tv_usec );
@@ -160,11 +160,13 @@ void eMainloop::processOneEvent()
                /* get current time */
        timeval now;
        gettimeofday(&now, 0);
+       m_now_is_invalid = 0;
        
        int poll_timeout = -1; /* infinite in case of empty timer list */
        
        if (m_timer_list)
        {
+               singleLock s(recalcLock);
                poll_timeout = timeval_to_usec(m_timer_list.begin()->getNextActivation() - now);
                        /* if current timer already passed, don't delay infinite. */
                if (poll_timeout < 0)
@@ -225,6 +227,13 @@ void eMainloop::processOneEvent()
                /* when we not processed anything, check timers. */
        if (!ret)
        {
+               singleLock s(recalcLock);
+
+                       /* this will never change while we have the recalcLock */
+                       /* we can savely return here, the timer will be re-checked soon. */
+               if (m_now_is_invalid)
+                       return;
+
                        /* process all timers which are ready. first remove them out of the list. */
                while ((!m_timer_list.empty()) && (m_timer_list.begin()->getNextActivation() < now))
                        m_timer_list.begin()->activate();
@@ -287,9 +296,14 @@ void eMainloop::quit( int ret )   // call this to leave all loops
 
 void eMainloop::addTimeOffset(int offset)
 {
-       singleLock s(recalcLock);
-       for (ePtrList<eTimer>::iterator it = m_timer_list.begin(); it != m_timer_list.end(); ++it )
-               it->addTimeOffset(offset);
+       for (ePtrList<eMainloop>::iterator it(eMainloop::existing_loops)
+               ;it != eMainloop::existing_loops.end(); ++it)
+       {
+               singleLock s(it->recalcLock);
+               it->m_now_is_invalid = 1;
+               for (ePtrList<eTimer>::iterator tit = it->m_timer_list.begin(); tit != it->m_timer_list.end(); ++tit )
+                       tit->addTimeOffset(offset);
+       }
 }
 
 eApplication* eApp = 0;