Commit 66f287b425bf6a828d70033568b0c356f354fbbc

  • avatar
  • Antti Koivisto <antti @esdhcp…4135.research.nokia.com>
  • Fri Jan 08 10:59:33 CET 2010
  • Tree SHA1: 4242280
  • Parent SHA1: e5aa9dd (Merge branch 'engine-thread' of gitorious.org:~akoivisto/webkit/anttis-webkit into engine-thread)
  • raw diff | raw patch
More thread safety in the tile cache
  
7878#endif
7979
8080 // Don't use WebKit timers to avoid interfering with the engine.
81 OwnPtr<TileTimer> m_tilePaintTimer;
82 OwnPtr<TileTimer> m_tileCreationTimer;
81 TileTimer* m_tilePaintTimer;
82 TileTimer* m_tileCreationTimer;
8383
8484 IntSize m_tileSize;
8585
  
4242 Q_OBJECT
4343public:
4444 TileTimer(TileCache* cache, void (TileCache::*f)());
45 void destroy();
4546 void startOneShot(double time);
4647 bool isActive() { return m_timer.isActive(); }
4748
5353 void timerEvent(QTimerEvent* ev);
5454
5555private:
56 void moveToEngineThread();
57
5658 QBasicTimer m_timer;
5759 TileCache* m_cache;
5860 void (TileCache::*m_timerFunction)();
6666 , m_timerFunction(f)
6767 , m_inEngineThread(false)
6868{
69#if ENABLE(ENGINE_THREAD)
70 moveToEngineThread();
71#endif
6972}
70
71void TileTimer::startOneShot(double time)
73
74void TileTimer::moveToEngineThread()
7275{
7376#if ENABLE(ENGINE_THREAD)
74 if (!m_inEngineThread && EngineThread::isStarted() && QThread::currentThread() == QApplication::instance()->thread()) {
75 moveToThread(EngineThread::qThread());
77 if (m_inEngineThread)
78 return;
79 if (thread() == EngineThread::qThread()) {
7680 m_inEngineThread = true;
81 return;
7782 }
78 QMetaObject::invokeMethod(this, "start", Qt::AutoConnection, Q_ARG(double, time));
83 if (!EngineThread::isStarted() || QThread::currentThread() != thread())
84 return;
85 moveToThread(EngineThread::qThread());
86 m_inEngineThread = true;
87#endif
88}
89
90void TileTimer::startOneShot(double time)
91{
92#if ENABLE(ENGINE_THREAD)
93 moveToEngineThread();
94
95 if (EngineThread::isCurrent() && m_inEngineThread)
96 start(time);
97 else
98 QMetaObject::invokeMethod(this, "start", Qt::AutoConnection, Q_ARG(double, time));
7999#else
80100 start(time);
81101#endif
108108
109109void TileTimer::timerEvent(QTimerEvent* ev)
110110{
111#if ENABLE(ENGINE_THREAD)
112 bool needsLock = EngineThread::isCurrent();
113 if (needsLock)
114 EngineThread::lock();
115#endif
111116 m_timer.stop();
112 (m_cache->*m_timerFunction)();
117 if (m_cache)
118 (m_cache->*m_timerFunction)();
119#if ENABLE(ENGINE_THREAD)
120 if (needsLock)
121 EngineThread::unlock();
122#endif
113123}
124
125void TileTimer::destroy()
126{
127 m_cache = 0;
128 QMetaObject::invokeMethod(this, "deleteLater", Qt::AutoConnection);
129}
114130
115131class Tile : public ThreadSafeShared<Tile>
116132{
275275
276276TileCache::~TileCache()
277277{
278 m_tilePaintTimer->destroy();
279 m_tilePaintTimer = 0;
280 m_tileCreationTimer->destroy();
281 m_tileCreationTimer = 0;
278282}
279283
280284void TileCache::invalidate(const IntRect& dirtyRect)
301301
302302void TileCache::paintTiles()
303303{
304#if ENABLE(ENGINE_THREAD)
305 EngineThread::lock();
306#endif
307304 m_client->tileCachePaintBegin();
308305
309306 QRegion fullDirtyRegion;
325325 paintedArea.append(qrects[n]);
326326
327327 m_client->tileCachePaintEnd(paintedArea);
328
329#if ENABLE(ENGINE_THREAD)
330 EngineThread::unlock();
331#endif
332328
333329 {
334330 // Swap the buffers atomically