diff options
author | Ben Murdoch <benm@google.com> | 2011-02-24 16:42:27 +0000 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-02-25 18:51:55 +0000 |
commit | 9fa7cd34acc40da0116376edfd9e98908acaeda3 (patch) | |
tree | ced5f7f32f86dbfeefa39774099ea9bc0bb60bb0 /WebCore/platform | |
parent | 3a89d2677bb5634df98cd01414220b8e095f58a9 (diff) | |
download | external_webkit-9fa7cd34acc40da0116376edfd9e98908acaeda3.zip external_webkit-9fa7cd34acc40da0116376edfd9e98908acaeda3.tar.gz external_webkit-9fa7cd34acc40da0116376edfd9e98908acaeda3.tar.bz2 |
Clean up synchronisation in Texture code.
Ensure that we wait in a while loop checking the condition when
we call wait, and only signal after unlocking the Mutex.
Also removes mNewRequest lock and condition in the TexturesGenerator
as it doesn't seem to be needed.
Hopefully this will clear up some ANRs.
Change-Id: I1b8b103a6effd2aa678a304e2519a6f6c484aaad
Diffstat (limited to 'WebCore/platform')
4 files changed, 51 insertions, 60 deletions
diff --git a/WebCore/platform/graphics/android/MediaTexture.cpp b/WebCore/platform/graphics/android/MediaTexture.cpp index 9e04e96..4ec50d8 100644 --- a/WebCore/platform/graphics/android/MediaTexture.cpp +++ b/WebCore/platform/graphics/android/MediaTexture.cpp @@ -71,24 +71,26 @@ VideoTexture::~VideoTexture() void VideoTexture::initNativeWindowIfNeeded() { - android::Mutex::Autolock lock(m_videoLock); + { + android::Mutex::Autolock lock(m_videoLock); - if(!m_newWindowRequest) - return; + if(!m_newWindowRequest) + return; - // reuse an existing texture if possible - if (!m_textureId) - glGenTextures(1, &m_textureId); + // reuse an existing texture if possible + if (!m_textureId) + glGenTextures(1, &m_textureId); - m_surfaceTexture = new android::SurfaceTexture(m_textureId); - m_surfaceTextureClient = new android::SurfaceTextureClient(m_surfaceTexture); + m_surfaceTexture = new android::SurfaceTexture(m_textureId); + m_surfaceTextureClient = new android::SurfaceTextureClient(m_surfaceTexture); - //setup callback - m_videoListener->resetFrameAvailable(); - m_surfaceTexture->setFrameAvailableListener(m_videoListener); + //setup callback + m_videoListener->resetFrameAvailable(); + m_surfaceTexture->setFrameAvailableListener(m_videoListener); - m_newWindowRequest = false; - m_newWindowReady = true; + m_newWindowRequest = false; + m_newWindowReady = true; + } m_newVideoRequestCond.signal(); } @@ -140,7 +142,11 @@ ANativeWindow* VideoTexture::requestNewWindow() } //block until the request can be fulfilled or we time out - m_newVideoRequestCond.waitRelative(m_videoLock, 500000000); // .5 sec + bool timedOut = false; + while (m_newWindowRequest && !timedOut) { + int ret = m_newVideoRequestCond.waitRelative(m_videoLock, 500000000); // .5 sec + timedOut = ret == TIMED_OUT; + } if (m_surfaceTextureClient.get()) m_newWindowReady = false; diff --git a/WebCore/platform/graphics/android/TexturesGenerator.cpp b/WebCore/platform/graphics/android/TexturesGenerator.cpp index 5b9c809..fae7ece 100644 --- a/WebCore/platform/graphics/android/TexturesGenerator.cpp +++ b/WebCore/platform/graphics/android/TexturesGenerator.cpp @@ -53,24 +53,24 @@ namespace WebCore { void TexturesGenerator::scheduleOperation(QueuedOperation* operation) { - android::Mutex::Autolock lock(mRequestedOperationsLock); - for (unsigned int i = 0; i < mRequestedOperations.size(); i++) { - QueuedOperation** s = &mRequestedOperations[i]; - // A similar operation is already in the queue. The newer operation may - // have additional dirty tiles so delete the existing operation and - // replace it with the new one. - if (*s && *s == operation) { - QueuedOperation* oldOperation = *s; - *s = operation; - delete oldOperation; - return; + { + android::Mutex::Autolock lock(mRequestedOperationsLock); + for (unsigned int i = 0; i < mRequestedOperations.size(); i++) { + QueuedOperation** s = &mRequestedOperations[i]; + // A similar operation is already in the queue. The newer operation may + // have additional dirty tiles so delete the existing operation and + // replace it with the new one. + if (*s && *s == operation) { + QueuedOperation* oldOperation = *s; + *s = operation; + delete oldOperation; + return; + } } - } - mRequestedOperations.append(operation); - m_newRequestLock.lock(); - m_newRequestCond.signal(); - m_newRequestLock.unlock(); + mRequestedOperations.append(operation); + } + mRequestedOperationsCond.signal(); } void TexturesGenerator::removeOperationsForPage(TiledPage* page) @@ -90,7 +90,7 @@ void TexturesGenerator::removeOperationsForTexture(LayerTexture* texture) void TexturesGenerator::removeOperationsForFilter(OperationFilter* filter) { - mRequestedOperationsLock.lock(); + android::Mutex::Autolock lock(mRequestedOperationsLock); for (unsigned int i = 0; i < mRequestedOperations.size();) { QueuedOperation* operation = mRequestedOperations[i]; if (filter->check(operation)) { @@ -105,23 +105,14 @@ void TexturesGenerator::removeOperationsForFilter(OperationFilter* filter) if (operation && filter->check(operation)) m_waitForCompletion = true; - mRequestedOperationsLock.unlock(); - delete filter; - mRequestedOperationsLock.lock(); - if (!m_waitForCompletion) { - mRequestedOperationsLock.unlock(); - return; // operation treated - } - // At this point, it means that we are currently executing an operation that // we want to be removed -- we should wait until it is done, so that // when we return our caller can be sure that there is no more operations // in the queue matching the given filter. - mRequestedOperationsCond.wait(mRequestedOperationsLock); - m_waitForCompletion = false; - mRequestedOperationsLock.unlock(); + while (m_waitForCompletion) + mRequestedOperationsCond.wait(mRequestedOperationsLock); } status_t TexturesGenerator::readyToRun() @@ -133,19 +124,13 @@ status_t TexturesGenerator::readyToRun() bool TexturesGenerator::threadLoop() { + // Check if we have any pending operations. mRequestedOperationsLock.lock(); + while (!mRequestedOperations.size()) + mRequestedOperationsCond.wait(mRequestedOperationsLock); - if (!mRequestedOperations.size()) { - XLOG("threadLoop, waiting for signal"); - m_newRequestLock.lock(); - mRequestedOperationsLock.unlock(); - m_newRequestCond.wait(m_newRequestLock); - m_newRequestLock.unlock(); - XLOG("threadLoop, got signal"); - } else { - XLOG("threadLoop going as we already have something in the queue"); - mRequestedOperationsLock.unlock(); - } + XLOG("threadLoop, got signal"); + mRequestedOperationsLock.unlock(); m_currentOperation = 0; bool stop = false; @@ -170,15 +155,15 @@ bool TexturesGenerator::threadLoop() if (m_currentOperation) { delete m_currentOperation; m_currentOperation = 0; - mRequestedOperationsCond.signal(); } if (!mRequestedOperations.size()) stop = true; if (m_waitForCompletion) { - mRequestedOperationsCond.signal(); m_waitForCompletion = false; + mRequestedOperationsCond.signal(); } mRequestedOperationsLock.unlock(); + } return true; diff --git a/WebCore/platform/graphics/android/TexturesGenerator.h b/WebCore/platform/graphics/android/TexturesGenerator.h index d98eb5b..e36d85e 100644 --- a/WebCore/platform/graphics/android/TexturesGenerator.h +++ b/WebCore/platform/graphics/android/TexturesGenerator.h @@ -61,8 +61,6 @@ private: Vector<QueuedOperation*> mRequestedOperations; android::Mutex mRequestedOperationsLock; android::Condition mRequestedOperationsCond; - android::Mutex m_newRequestLock; - android::Condition m_newRequestCond; bool m_waitForCompletion; QueuedOperation* m_currentOperation; }; diff --git a/WebCore/platform/graphics/android/TilesManager.h b/WebCore/platform/graphics/android/TilesManager.h index 107b121..8c44bea 100644 --- a/WebCore/platform/graphics/android/TilesManager.h +++ b/WebCore/platform/graphics/android/TilesManager.h @@ -84,9 +84,11 @@ public: void markGeneratorAsReady() { - android::Mutex::Autolock lock(m_generatorLock); + { + android::Mutex::Autolock lock(m_generatorLock); + m_generatorReady = true; + } m_generatorReadyCond.signal(); - m_generatorReady = true; } void printTextures(); @@ -123,7 +125,7 @@ private: void waitForGenerator() { android::Mutex::Autolock lock(m_generatorLock); - if (!m_generatorReady) + while (!m_generatorReady) m_generatorReadyCond.wait(m_generatorLock); } |