From c6b48ebce7ed159503b41970e87b225cb1dd5042 Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 26 Mar 2012 14:44:07 -0700 Subject: [PATCH] Fix TilesManager race condition Issue: 26518 Fixes a race condition when initializing TilesManager by removing the unnecessary waitForGenerator call entirely and giving TexturesGenerator a reference to the TilesManager in its ctor, removing all calls to TilesManager::instance from a non-UI thread Change-Id: Ib1b60825275ef24f4733562ed1f6ecace0594c88 --- .../graphics/android/TexturesGenerator.cpp | 5 ++--- .../graphics/android/TexturesGenerator.h | 7 +++++-- .../graphics/android/TilesManager.cpp | 6 +----- .../platform/graphics/android/TilesManager.h | 19 +------------------ 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/Source/WebCore/platform/graphics/android/TexturesGenerator.cpp b/Source/WebCore/platform/graphics/android/TexturesGenerator.cpp index bccb99bf6..ff4168978 100644 --- a/Source/WebCore/platform/graphics/android/TexturesGenerator.cpp +++ b/Source/WebCore/platform/graphics/android/TexturesGenerator.cpp @@ -104,7 +104,7 @@ void TexturesGenerator::removeOperationsForFilter(OperationFilter* filter, bool // The solution is use this as a flag to tell Tex Gen thread that // UI thread is waiting now, Tex Gen thread should not wait for the // queue any more. - TilesManager::instance()->transferQueue()->interruptTransferQueue(true); + m_tilesManager->transferQueue()->interruptTransferQueue(true); } delete filter; @@ -122,7 +122,6 @@ void TexturesGenerator::removeOperationsForFilter(OperationFilter* filter, bool status_t TexturesGenerator::readyToRun() { - TilesManager::instance()->markGeneratorAsReady(); XLOG("Thread ready to run"); return NO_ERROR; } @@ -192,7 +191,7 @@ bool TexturesGenerator::threadLoop() stop = true; if (m_waitForCompletion) { m_waitForCompletion = false; - TilesManager::instance()->transferQueue()->interruptTransferQueue(false); + m_tilesManager->transferQueue()->interruptTransferQueue(false); mRequestedOperationsCond.signal(); } mRequestedOperationsLock.unlock(); diff --git a/Source/WebCore/platform/graphics/android/TexturesGenerator.h b/Source/WebCore/platform/graphics/android/TexturesGenerator.h index 2e3b6b498..9299e87bb 100644 --- a/Source/WebCore/platform/graphics/android/TexturesGenerator.h +++ b/Source/WebCore/platform/graphics/android/TexturesGenerator.h @@ -39,12 +39,14 @@ using namespace android; class BaseLayerAndroid; class LayerAndroid; +class TilesManager; class TexturesGenerator : public Thread { public: - TexturesGenerator() : Thread(false) + TexturesGenerator(TilesManager* instance) : Thread(false) , m_waitForCompletion(false) - , m_currentOperation(0) { } + , m_currentOperation(0) + , m_tilesManager(instance) { } virtual ~TexturesGenerator() { } virtual status_t readyToRun(); @@ -63,6 +65,7 @@ class TexturesGenerator : public Thread { android::Condition mRequestedOperationsCond; bool m_waitForCompletion; QueuedOperation* m_currentOperation; + TilesManager* m_tilesManager; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp index 30bd8d0cb..a50af1ff0 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp @@ -112,7 +112,7 @@ TilesManager::TilesManager() m_availableTextures.reserveCapacity(MAX_TEXTURE_ALLOCATION); m_tilesTextures.reserveCapacity(MAX_TEXTURE_ALLOCATION); m_availableTilesTextures.reserveCapacity(MAX_TEXTURE_ALLOCATION); - m_pixmapsGenerationThread = new TexturesGenerator(); + m_pixmapsGenerationThread = new TexturesGenerator(this); m_pixmapsGenerationThread->run("TexturesGenerator", android::PRIORITY_BACKGROUND); } @@ -411,7 +411,6 @@ void TilesManager::setMaxLayerTextureCount(int max) m_hasLayerTextures = true; } - float TilesManager::tileWidth() { return TILE_WIDTH; @@ -488,9 +487,6 @@ TilesManager* TilesManager::instance() if (!gInstance) { gInstance = new TilesManager(); XLOG("instance(), new gInstance is %x", gInstance); - XLOG("Waiting for the generator..."); - gInstance->waitForGenerator(); - XLOG("Generator ready!"); } return gInstance; } diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h index 9782fbb75..949385536 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.h +++ b/Source/WebCore/platform/graphics/android/TilesManager.h @@ -49,6 +49,7 @@ class PaintedSurface; class TilesManager { public: + // May only be called from the UI thread static TilesManager* instance(); static GLint getMaxTextureSize(); static int getMaxTextureAllocation(); @@ -93,15 +94,6 @@ class TilesManager { BaseTileTexture* getAvailableTexture(BaseTile* owner); - void markGeneratorAsReady() - { - { - android::Mutex::Autolock lock(m_generatorLock); - m_generatorReady = true; - } - m_generatorReadyCond.signal(); - } - void printTextures(); void resetTextureUsage(TiledPage* page); @@ -202,13 +194,6 @@ class TilesManager { private: TilesManager(); - void waitForGenerator() - { - android::Mutex::Autolock lock(m_generatorLock); - while (!m_generatorReady) - m_generatorReadyCond.wait(m_generatorLock); - } - void deallocateTexturesVector(unsigned long long sparedDrawCount, WTF::Vector& textures); @@ -235,8 +220,6 @@ class TilesManager { sp m_pixmapsGenerationThread; android::Mutex m_texturesLock; - android::Mutex m_generatorLock; - android::Condition m_generatorReadyCond; static TilesManager* gInstance;