diff options
author | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-03-22 15:31:08 +0100 |
---|---|---|
committer | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-03-22 15:31:08 +0100 |
commit | e8a56c51780cd3e3a0043c4f6a8849d4c2d87dd6 (patch) | |
tree | 85dc5ef1ce13d7e197c3bb3fd6f845ab7da93449 /Source/JavaScriptCore/heap/HeapTimer.cpp | |
parent | 68753e64d1d606d7627fae83e05863d110226c15 (diff) | |
parent | 99783e2c7e917224da401ddbd33354c131b3a377 (diff) | |
download | qtwebkit-e8a56c51780cd3e3a0043c4f6a8849d4c2d87dd6.tar.gz |
Merge branch 'dev' into stable
This starts Qt 5.1 release cycle
Conflicts:
Source/sync.profile
Change-Id: I570f2804b9e5baf6d2b5573d1030887866077124
Diffstat (limited to 'Source/JavaScriptCore/heap/HeapTimer.cpp')
-rw-r--r-- | Source/JavaScriptCore/heap/HeapTimer.cpp | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/Source/JavaScriptCore/heap/HeapTimer.cpp b/Source/JavaScriptCore/heap/HeapTimer.cpp index 214f86757..d69ee9607 100644 --- a/Source/JavaScriptCore/heap/HeapTimer.cpp +++ b/Source/JavaScriptCore/heap/HeapTimer.cpp @@ -33,6 +33,13 @@ #include <wtf/MainThread.h> #include <wtf/Threading.h> +#if PLATFORM(QT) +#include <QCoreApplication> +#include <QMutexLocker> +#include <QThread> +#include <QTimerEvent> +#endif + namespace JSC { #if USE(CF) @@ -132,8 +139,70 @@ void HeapTimer::didStartVMShutdown() delete this; } -#else +#elif PLATFORM(QT) + +HeapTimer::HeapTimer(JSGlobalData* globalData) + : m_globalData(globalData) + , m_newThread(0) + , m_mutex(QMutex::NonRecursive) +{ + // The HeapTimer might be created before the runLoop is started, + // but we need to ensure the thread has an eventDispatcher already. + QEventLoop fakeLoop(this); +} + +HeapTimer::~HeapTimer() +{ +} + +void HeapTimer::timerEvent(QTimerEvent*) +{ + QMutexLocker lock(&m_mutex); + if (m_newThread) { + // We need to wait with processing until we are on the right thread. + return; + } + + APIEntryShim shim(m_globalData, APIEntryShimWithoutLock::DontRefGlobalData); + doWork(); +} +void HeapTimer::customEvent(QEvent*) +{ + ASSERT(m_newThread); + QMutexLocker lock(&m_mutex); + moveToThread(m_newThread); + m_newThread = 0; +} + +void HeapTimer::synchronize() +{ + if (thread() != QThread::currentThread()) { + // We can only move from the objects own thread to another, so we fire an + // event into the owning thread to trigger the move. + // This must be processed before any timerEvents so giving it high priority. + QMutexLocker lock(&m_mutex); + m_newThread = QThread::currentThread(); + QCoreApplication::postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority); + } +} + +void HeapTimer::invalidate() +{ + QMutexLocker lock(&m_mutex); + m_timer.stop(); +} + +void HeapTimer::didStartVMShutdown() +{ + invalidate(); + if (thread() == QThread::currentThread()) + delete this; + else + deleteLater(); +} + +#else HeapTimer::HeapTimer(JSGlobalData* globalData) : m_globalData(globalData) { |