From 9c86d4f8bc19fa180b77fca0b21a66c64e3cbced Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 10 Jun 2015 19:02:33 +0200 Subject: [PATCH] Race condition fix --- components/sceneutil/workqueue.cpp | 5 +++-- components/sceneutil/workqueue.hpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/components/sceneutil/workqueue.cpp b/components/sceneutil/workqueue.cpp index a709eae85..9f23fba2d 100644 --- a/components/sceneutil/workqueue.cpp +++ b/components/sceneutil/workqueue.cpp @@ -25,6 +25,7 @@ void WorkTicket::signalDone() WorkItem::WorkItem() : mTicket(new WorkTicket) { + mTicket->setThreadSafeRefUnref(true); } WorkItem::~WorkItem() @@ -73,9 +74,9 @@ WorkQueue::~WorkQueue() } } -WorkTicket* WorkQueue::addWorkItem(WorkItem *item) +osg::ref_ptr WorkQueue::addWorkItem(WorkItem *item) { - WorkTicket* ticket = item->getTicket().get(); + osg::ref_ptr ticket = item->getTicket(); OpenThreads::ScopedLock lock(mMutex); mQueue.push(item); mCondition.signal(); diff --git a/components/sceneutil/workqueue.hpp b/components/sceneutil/workqueue.hpp index 720fbaa68..492bbd090 100644 --- a/components/sceneutil/workqueue.hpp +++ b/components/sceneutil/workqueue.hpp @@ -65,7 +65,7 @@ namespace SceneUtil /// Add a new work item to the back of the queue. /// @par The returned WorkTicket may be used by the caller to wait until the work is complete. - WorkTicket* addWorkItem(WorkItem* item); + osg::ref_ptr addWorkItem(WorkItem* item); /// Get the next work item from the front of the queue. If the queue is empty, waits until a new item is added. /// If the workqueue is in the process of being destroyed, may return NULL.