From: Felix Domke Date: Tue, 15 Nov 2005 22:33:00 +0000 (+0000) Subject: improve locking of addTimeOffset a bit X-Git-Tag: 2.6.0~5160 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/9f34bd86d0dc2c2ea51fe9aa54533aa68cfadc64 improve locking of addTimeOffset a bit --- diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp index 7300a571..7951f6e7 100644 --- a/lib/base/ebase.cpp +++ b/lib/base/ebase.cpp @@ -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::iterator it = m_timer_list.begin(); it != m_timer_list.end(); ++it ) - it->addTimeOffset(offset); + for (ePtrList::iterator it(eMainloop::existing_loops) + ;it != eMainloop::existing_loops.end(); ++it) + { + singleLock s(it->recalcLock); + for (ePtrList::iterator tit = it->m_timer_list.begin(); tit != it->m_timer_list.end(); ++tit ) + tit->addTimeOffset(offset); + } } eApplication* eApp = 0; diff --git a/lib/base/ebase.h b/lib/base/ebase.h index 7fd5af02..54b4063b 100644 --- a/lib/base/ebase.h +++ b/lib/base/ebase.h @@ -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 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); diff --git a/lib/dvb/dvbtime.cpp b/lib/dvb/dvbtime.cpp index dc98a6d3..97a59539 100644 --- a/lib/dvb/dvbtime.cpp +++ b/lib/dvb/dvbtime.cpp @@ -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::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 )