aboutsummaryrefslogtreecommitdiff
path: root/lib/base/ebase.cpp
diff options
context:
space:
mode:
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>2008-04-16 09:53:18 +0000
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>2008-04-16 09:53:18 +0000
commitd58af85ce33b4b9c8cb065b59b591580ae8abe0c (patch)
treeaabac149c6d20c6809ee4dea0c1b371f1de24f81 /lib/base/ebase.cpp
parent5c392355566dce59c1e486ae934228aa9a5fa2bc (diff)
downloadenigma2-d58af85ce33b4b9c8cb065b59b591580ae8abe0c.tar.gz
enigma2-d58af85ce33b4b9c8cb065b59b591580ae8abe0c.zip
use clock_gettime for internal timers instead of gettimeofday .. so now our
timers are independent of the normal linux clock (and change linux time without inform e2 is now really uncritical)
Diffstat (limited to 'lib/base/ebase.cpp')
-rw-r--r--lib/base/ebase.cpp69
1 files changed, 11 insertions, 58 deletions
diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp
index 01ee6a53..038e5ad1 100644
--- a/lib/base/ebase.cpp
+++ b/lib/base/ebase.cpp
@@ -44,11 +44,10 @@ void eTimer::start(long msek, bool singleShot)
bActive = true;
bSingleShot = singleShot;
interval = msek;
- gettimeofday(&nextActivation, 0);
- nextActivation.tv_sec -= context.getTimeOffset();
-// eDebug("this = %p\nnow sec = %d, usec = %d\nadd %d msec", this, nextActivation.tv_sec, nextActivation.tv_usec, msek);
+ clock_gettime(CLOCK_MONOTONIC, &nextActivation);
+// eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d msec", this, nextActivation.tv_sec, nextActivation.tv_nsec, msek);
nextActivation += (msek<0 ? 0 : msek);
-// eDebug("next Activation sec = %d, usec = %d", nextActivation.tv_sec, nextActivation.tv_usec );
+// eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
context.addTimer(this);
}
@@ -59,12 +58,11 @@ void eTimer::startLongTimer( int seconds )
bActive = bSingleShot = true;
interval = 0;
- gettimeofday(&nextActivation, 0);
- nextActivation.tv_sec -= context.getTimeOffset();
-// eDebug("this = %p\nnow sec = %d, usec = %d\nadd %d sec", this, nextActivation.tv_sec, nextActivation.tv_usec, seconds);
+ clock_gettime(CLOCK_MONOTONIC, &nextActivation);
+// eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d sec", this, nextActivation.tv_sec, nextActivation.tv_nsec, seconds);
if ( seconds > 0 )
nextActivation.tv_sec += seconds;
-// eDebug("next Activation sec = %d, usec = %d", nextActivation.tv_sec, nextActivation.tv_usec );
+// eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
context.addTimer(this);
}
@@ -108,18 +106,12 @@ void eTimer::activate() // Internal Funktion... called from eApplication
/*emit*/ timeout();
}
-void eTimer::addTimeOffset( int offset )
-{
- nextActivation.tv_sec += offset;
-}
-
// mainloop
ePtrList<eMainloop> eMainloop::existing_loops;
eMainloop::~eMainloop()
{
existing_loops.remove(this);
- pthread_mutex_destroy(&recalcLock);
for (std::map<int, eSocketNotifier*>::iterator it(notifiers.begin());it != notifiers.end();++it)
it->second->stop();
while(m_timer_list.begin() != m_timer_list.end())
@@ -157,15 +149,11 @@ int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePy
if (!m_timer_list.empty() || twisted_timeout > 0)
{
- applyTimeOffset();
if (!m_timer_list.empty())
{
/* process all timers which are ready. first remove them out of the list. */
while (!m_timer_list.empty() && (poll_timeout = timeout_usec( m_timer_list.begin()->getNextActivation() ) ) <= 0 )
- {
m_timer_list.begin()->activate();
- applyTimeOffset();
- }
if (poll_timeout < 0)
poll_timeout = 0;
else /* convert us to ms */
@@ -216,7 +204,7 @@ int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePy
Py_END_ALLOW_THREADS
} else
ret = ::poll(pfd, fdcount, poll_timeout);
-
+
m_is_idle = 0;
/* ret > 0 means that there are some active poll entries. */
@@ -283,7 +271,7 @@ int eMainloop::iterate(unsigned int twisted_timeout, PyObject **res, ePyObject d
if (twisted_timeout)
{
- gettimeofday(&m_twisted_timer, 0);
+ clock_gettime(CLOCK_MONOTONIC, &m_twisted_timer);
m_twisted_timer += twisted_timeout;
}
@@ -302,15 +290,12 @@ int eMainloop::iterate(unsigned int twisted_timeout, PyObject **res, ePyObject d
int to = 0;
if (twisted_timeout)
{
- timeval now, timeout;
- gettimeofday(&now, 0);
- m_twisted_timer += time_offset; // apply pending offset
+ timespec now, timeout;
+ clock_gettime(CLOCK_MONOTONIC, &now);
if (m_twisted_timer<=now) // timeout
return 0;
timeout = m_twisted_timer - now;
- to = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
- // remove pending offset .. it is re-applied in next call of processOneEvent.. applyTimeOffset
- m_twisted_timer -= time_offset;
+ to = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000;
}
ret = processOneEvent(to, res, dict);
} while ( !ret && !(res && *res) );
@@ -357,38 +342,6 @@ void eMainloop::quit(int ret)
app_quit_now = true;
}
-void eMainloop::addTimeOffset(int offset)
-{
- for (ePtrList<eMainloop>::iterator it(existing_loops.begin()); it != existing_loops.end(); ++it )
- it->addInstanceTimeOffset(offset);
-}
-
-void eMainloop::addInstanceTimeOffset(int offset)
-{
- singleLock s(recalcLock);
- if (m_timer_list.empty())
- time_offset=0;
- else
- {
- if ( time_offset )
- eDebug("time_offset %d avail.. add new offset %d than new is %d",
- time_offset, offset, time_offset+offset);
- time_offset+=offset;
- }
-}
-
-void eMainloop::applyTimeOffset()
-{
- singleLock s(recalcLock);
- if ( time_offset )
- {
- for (ePtrList<eTimer>::iterator it(m_timer_list.begin()); it != m_timer_list.end(); ++it )
- it->addTimeOffset( time_offset );
- m_twisted_timer += time_offset;
- time_offset=0;
- }
-}
-
eApplication* eApp = 0;
#include "structmember.h"