improve locking of addTimeOffset a bit
authorFelix Domke <tmbinc@elitedvb.net>
Tue, 15 Nov 2005 22:33:00 +0000 (22:33 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Tue, 15 Nov 2005 22:33:00 +0000 (22:33 +0000)
lib/base/ebase.cpp
lib/base/ebase.h
lib/dvb/dvbtime.cpp

index 7300a571994ba4fe22d4c80e3d2addab778305c5..7951f6e76ea25bb6753cb31109c2242eec19504c 100644 (file)
@@ -165,6 +165,7 @@ void eMainloop::processOneEvent()
        
        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 +226,8 @@ void eMainloop::processOneEvent()
                /* when we not processed anything, check timers. */
        if (!ret)
        {
+               singleLock s(recalcLock);
+
                        /* 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 +290,13 @@ 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);
+               for (ePtrList<eTimer>::iterator tit = it->m_timer_list.begin(); tit != it->m_timer_list.end(); ++tit )
+                       tit->addTimeOffset(offset);
+       }
 }
 
 eApplication* eApp = 0;
index 7fd5af02599bf62589f7e916d42bfd64f08fb29b..54b4063bfe147792d67f02cfa10fac55cffad1b1 100644 (file)
@@ -175,10 +175,9 @@ class eMainloop
        int loop_level;
        void processOneEvent();
        int retval;
-       int timer_offset;
        pthread_mutex_t recalcLock;
 public:
-       void addTimeOffset(int offset);
+       static void addTimeOffset(int offset);
        void addSocketNotifier(eSocketNotifier *sn);
        void removeSocketNotifier(eSocketNotifier *sn);
        void addTimer(eTimer* e);
@@ -186,7 +185,7 @@ public:
 
        static ePtrList<eMainloop> existing_loops;
        eMainloop()
-               :app_quit_now(0),loop_level(0),retval(0),timer_offset(0)
+               :app_quit_now(0),loop_level(0),retval(0)
        {
                existing_loops.push_back(this);
                pthread_mutex_init(&recalcLock, 0);
index dc98a6d3a9d00e55812874290e73eed69c5d4d20..97a59539541b2cc1f2acdc524d41809fed4cede1 100644 (file)
@@ -210,9 +210,7 @@ void eDVBLocalTimeHandler::updateTime( time_t tp_time, eDVBChannel *chan )
                                        gettimeofday(&tnow,0);
                                        tnow.tv_sec=rtc_time;
                                        settimeofday(&tnow,0);
-                                       for (ePtrList<eMainloop>::iterator it(eMainloop::existing_loops)
-                                               ;it != eMainloop::existing_loops.end(); ++it)
-                                               it->addTimeOffset(m_time_difference);
+                                       eMainloop::addTimeOffset(m_time_difference);
                                        m_time_difference=0;
                                }
                                else if ( !m_time_difference )