From 362edaa1b9a9c4aa59f37eacdfed38378a3e68d0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 17 Dec 2010 13:43:41 +0000 Subject: [PATCH] From Tim Moore, fix for race conditions in takeOrGenerate() methods --- src/osg/BufferObject.cpp | 13 ++++++++----- src/osg/Texture.cpp | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index 1b8c97678..798333d71 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -749,14 +749,17 @@ GLBufferObject* GLBufferObjectSet::takeFromOrphans(BufferObject* bufferObject) GLBufferObject* GLBufferObjectSet::takeOrGenerate(BufferObject* bufferObject) { - // see if we can recyle GLBufferObject from the orphane list - if (!_pendingOrphanedGLBufferObjects.empty()) + // see if we can recyle GLBufferObject from the orphan list { OpenThreads::ScopedLock lock(_mutex); - handlePendingOrphandedGLBufferObjects(); - return takeFromOrphans(bufferObject); + if (!_pendingOrphanedGLBufferObjects.empty()) + { + handlePendingOrphandedGLBufferObjects(); + return takeFromOrphans(bufferObject); + } } - else if (!_orphanedGLBufferObjects.empty()) + + if (!_orphanedGLBufferObjects.empty()) { return takeFromOrphans(bufferObject); } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 641553d50..526bed599 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -514,14 +514,17 @@ Texture::TextureObject* Texture::TextureObjectSet::takeFromOrphans(Texture* text Texture::TextureObject* Texture::TextureObjectSet::takeOrGenerate(Texture* texture) { - // see if we can recyle TextureObject from the orphane list - if (!_pendingOrphanedTextureObjects.empty()) + // see if we can recyle TextureObject from the orphan list { OpenThreads::ScopedLock lock(_mutex); - handlePendingOrphandedTextureObjects(); - return takeFromOrphans(texture); + if (!_pendingOrphanedTextureObjects.empty()) + { + handlePendingOrphandedTextureObjects(); + return takeFromOrphans(texture); + } } - else if (!_orphanedTextureObjects.empty()) + + if (!_orphanedTextureObjects.empty()) { return takeFromOrphans(texture); }