summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/efl/SharedTimerEfl.cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-10-22 13:02:20 +0100
committerBen Murdoch <benm@google.com>2010-10-26 15:21:41 +0100
commita94275402997c11dd2e778633dacf4b7e630a35d (patch)
treee66f56c67e3b01f22c9c23cd932271ee9ac558ed /WebCore/platform/efl/SharedTimerEfl.cpp
parent09e26c78506587b3f5d930d7bc72a23287ffbec0 (diff)
downloadexternal_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.zip
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.gz
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.bz2
Merge WebKit at r70209: Initial merge by Git
Change-Id: Id23a68efa36e9d1126bcce0b137872db00892c8e
Diffstat (limited to 'WebCore/platform/efl/SharedTimerEfl.cpp')
-rw-r--r--WebCore/platform/efl/SharedTimerEfl.cpp80
1 files changed, 67 insertions, 13 deletions
diff --git a/WebCore/platform/efl/SharedTimerEfl.cpp b/WebCore/platform/efl/SharedTimerEfl.cpp
index 437de64..990d0c8 100644
--- a/WebCore/platform/efl/SharedTimerEfl.cpp
+++ b/WebCore/platform/efl/SharedTimerEfl.cpp
@@ -30,43 +30,97 @@
#include "SharedTimer.h"
#include <Ecore.h>
+#include <pthread.h>
#include <stdio.h>
#include <wtf/Assertions.h>
#include <wtf/CurrentTime.h>
+#include <wtf/MainThread.h>
namespace WebCore {
-static Ecore_Timer *g_sharedTimer = 0;
+static pthread_mutex_t timerMutex = PTHREAD_MUTEX_INITIALIZER;
+static Ecore_Timer *_sharedTimer = 0;
+static Ecore_Pipe *_pipe = 0;
-static void (*g_timerFunction)();
+static void (*_timerFunction)();
+
+struct timerOp {
+ double time;
+ unsigned char op; // 0 - add a timer; 1 - del a timer;
+};
void setSharedTimerFiredFunction(void (*func)())
{
- g_timerFunction = func;
+ _timerFunction = func;
}
static Eina_Bool timerEvent(void*)
{
- if (g_timerFunction)
- g_timerFunction();
+ if (_timerFunction)
+ _timerFunction();
+
+ _sharedTimer = 0;
return ECORE_CALLBACK_CANCEL;
}
-void stopSharedTimer()
+void processTimers(struct timerOp *tOp)
{
- if (g_sharedTimer) {
- ecore_timer_del(g_sharedTimer);
- g_sharedTimer = 0;
+ if (_sharedTimer) {
+ ecore_timer_del(_sharedTimer);
+ _sharedTimer = 0;
}
+
+ if (tOp->op == 1)
+ return;
+
+ double interval = tOp->time - currentTime();
+
+ if (interval <= ecore_animator_frametime_get()) {
+ if (_timerFunction)
+ _timerFunction();
+ return;
+ }
+
+ _sharedTimer = ecore_timer_add(interval, timerEvent, 0);
}
-void setSharedTimerFireTime(double fireTime)
+void pipeHandlerCb(void *data, void *buffer, unsigned int nbyte)
+{
+ ASSERT(nbyte == sizeof(struct timerOp));
+
+ struct timerOp *tOp = (struct timerOp *)buffer;
+ processTimers(tOp);
+}
+
+void stopSharedTimer()
{
- double interval = fireTime - currentTime();
+ struct timerOp tOp;
+ pthread_mutex_lock(&timerMutex);
+ if (!_pipe)
+ _pipe = ecore_pipe_add(pipeHandlerCb, 0);
+ pthread_mutex_unlock(&timerMutex);
- stopSharedTimer();
- g_sharedTimer = ecore_timer_add(interval, timerEvent, 0);
+ tOp.op = 1;
+ ecore_pipe_write(_pipe, &tOp, sizeof(tOp));
+}
+
+void addNewTimer(double fireTime)
+{
+ struct timerOp tOp;
+ pthread_mutex_lock(&timerMutex);
+ if (!_pipe)
+ _pipe = ecore_pipe_add(pipeHandlerCb, 0);
+ pthread_mutex_unlock(&timerMutex);
+
+ tOp.time = fireTime;
+ tOp.op = 0;
+ ecore_pipe_write(_pipe, &tOp, sizeof(tOp));
+}
+
+void setSharedTimerFireTime(double fireTime)
+{
+ addNewTimer(fireTime);
}
}