From 1b5c59db75ea735c9a97b71e2abb17ce809b2372 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 13 Oct 2013 11:59:43 -0700 Subject: [PATCH 1/3] Correctly exit work queue on done, race condition fix. done_ might've been set to true while processing the item, making the wait wait forever. --- thread/prioritizedworkqueue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thread/prioritizedworkqueue.cpp b/thread/prioritizedworkqueue.cpp index 18369ed617..e2b3e7ef09 100644 --- a/thread/prioritizedworkqueue.cpp +++ b/thread/prioritizedworkqueue.cpp @@ -12,8 +12,8 @@ PrioritizedWorkQueue::~PrioritizedWorkQueue() { void PrioritizedWorkQueue::Add(PrioritizedWorkQueueItem *item) { mutex_.lock(); queue_.push_back(item); - mutex_.unlock(); notEmpty_.notify_one(); + mutex_.unlock(); } void PrioritizedWorkQueue::Stop() { @@ -38,7 +38,7 @@ void PrioritizedWorkQueue::Flush() { // The worker should simply call this in a loop. Will block when appropriate. PrioritizedWorkQueueItem *PrioritizedWorkQueue::Pop() { mutex_.lock(); - while (queue_.empty()) { + while (queue_.empty() && !done_) { notEmpty_.wait(mutex_); if (done_) { mutex_.unlock(); From 12fb5c4f32f56a09deff5a89d8d9c94075fb9588 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 13 Oct 2013 12:02:52 -0700 Subject: [PATCH 2/3] iOS: Don't try to use GLES3 for now. --- gfx_es2/gl3stub.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gfx_es2/gl3stub.c b/gfx_es2/gl3stub.c index c9f7c87b9a..5e5d9abec5 100644 --- a/gfx_es2/gl3stub.c +++ b/gfx_es2/gl3stub.c @@ -14,6 +14,8 @@ * limitations under the License. */ +#ifndef IOS + #include "gl3stub.h" #if defined(USING_GLES2) && !defined(__SYMBIAN32__) @@ -344,3 +346,4 @@ GL_APICALL void (* GL_APIENTRY glTexStorage3D) (GLenum target, GLsizei GL_APICALL void (* GL_APIENTRY glGetInternalformativ) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params); #endif +#endif From adca06c6963532902af1eed15d34f87f5112ed6d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 13 Oct 2013 12:09:09 -0700 Subject: [PATCH 3/3] Use guards, avoid the "not sure how" case. --- thread/prioritizedworkqueue.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/thread/prioritizedworkqueue.cpp b/thread/prioritizedworkqueue.cpp index e2b3e7ef09..0d10d9a0b2 100644 --- a/thread/prioritizedworkqueue.cpp +++ b/thread/prioritizedworkqueue.cpp @@ -10,38 +10,38 @@ PrioritizedWorkQueue::~PrioritizedWorkQueue() { } void PrioritizedWorkQueue::Add(PrioritizedWorkQueueItem *item) { - mutex_.lock(); + lock_guard guard(mutex_); queue_.push_back(item); notEmpty_.notify_one(); - mutex_.unlock(); } void PrioritizedWorkQueue::Stop() { - mutex_.lock(); + lock_guard guard(mutex_); done_ = true; notEmpty_.notify_one(); - mutex_.unlock(); } void PrioritizedWorkQueue::Flush() { if (queue_.empty()) return; - mutex_.lock(); + lock_guard guard(mutex_); for (auto iter = queue_.begin(); iter != queue_.end(); ++iter) { delete *iter; } queue_.clear(); - mutex_.unlock(); } // The worker should simply call this in a loop. Will block when appropriate. PrioritizedWorkQueueItem *PrioritizedWorkQueue::Pop() { - mutex_.lock(); - while (queue_.empty() && !done_) { + lock_guard guard(mutex_); + if (done_) { + return 0; + } + + while (queue_.empty()) { notEmpty_.wait(mutex_); if (done_) { - mutex_.unlock(); return 0; } } @@ -59,11 +59,9 @@ PrioritizedWorkQueueItem *PrioritizedWorkQueue::Pop() { if (best != queue_.end()) { PrioritizedWorkQueueItem *poppedItem = *best; queue_.erase(best); - mutex_.unlock(); return poppedItem; } else { // Not really sure how this can happen, but let's be safe. - mutex_.unlock(); return 0; } }