diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 72d3a24ea..0b289aade 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -44,7 +44,11 @@ osg::ref_ptr& Font::getDefaultFont() return s_defaultFont; } -static OpenThreads::ReentrantMutex s_FontFileMutex; +static OpenThreads::ReentrantMutex& getFontFileMutex() +{ + static OpenThreads::ReentrantMutex s_FontFileMutex; + return s_FontFileMutex; +} std::string osgText::findFontFile(const std::string& str) { @@ -52,7 +56,7 @@ std::string osgText::findFontFile(const std::string& str) std::string filename = osgDB::findDataFile(str); if (!filename.empty()) return filename; - OpenThreads::ScopedLock lock(s_FontFileMutex); + OpenThreads::ScopedLock lock(getFontFileMutex()); static osgDB::FilePathList s_FontFilePath; static bool initialized = false; @@ -107,7 +111,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename, const osgDB::R if (foundFile.empty()) foundFile = filename; - OpenThreads::ScopedLock lock(s_FontFileMutex); + OpenThreads::ScopedLock lock(getFontFileMutex()); osg::ref_ptr localOptions; if (!userOptions) @@ -129,7 +133,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename, const osgDB::R osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions) { - OpenThreads::ScopedLock lock(s_FontFileMutex); + OpenThreads::ScopedLock lock(getFontFileMutex()); osg::ref_ptr localOptions; if (!userOptions) @@ -168,7 +172,7 @@ osg::ref_ptr osgText::readRefFontFile(const std::string& filename, const o if (foundFile.empty()) foundFile = filename; - OpenThreads::ScopedLock lock(s_FontFileMutex); + OpenThreads::ScopedLock lock(getFontFileMutex()); osg::ref_ptr localOptions; if (!userOptions) @@ -188,7 +192,7 @@ osg::ref_ptr osgText::readRefFontFile(const std::string& filename, const o osg::ref_ptr osgText::readRefFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions) { - OpenThreads::ScopedLock lock(s_FontFileMutex); + OpenThreads::ScopedLock lock(getFontFileMutex()); osg::ref_ptr localOptions; if (!userOptions) diff --git a/src/osgViewer/Scene.cpp b/src/osgViewer/Scene.cpp index e07523b79..fcec0a2c6 100644 --- a/src/osgViewer/Scene.cpp +++ b/src/osgViewer/Scene.cpp @@ -17,8 +17,18 @@ using namespace osgViewer; typedef std::vector< osg::observer_ptr > SceneCache; -static OpenThreads::Mutex s_sceneCacheMutex; -static SceneCache s_sceneCache; + +static SceneCache& getSceneCache() +{ + static SceneCache s_sceneCache; + return s_sceneCache; +} + +static OpenThreads::Mutex& getSceneCacheMutex() +{ + static OpenThreads::Mutex s_sceneCacheMutex; + return s_sceneCacheMutex; +} Scene::Scene(): osg::Referenced(true) @@ -26,21 +36,21 @@ Scene::Scene(): setDatabasePager(osgDB::DatabasePager::create()); setImagePager(new osgDB::ImagePager); - OpenThreads::ScopedLock lock(s_sceneCacheMutex); - s_sceneCache.push_back(this); + OpenThreads::ScopedLock lock(getSceneCacheMutex()); + getSceneCache().push_back(this); } Scene::~Scene() { - OpenThreads::ScopedLock lock(s_sceneCacheMutex); - for(SceneCache::iterator itr = s_sceneCache.begin(); - itr != s_sceneCache.end(); + OpenThreads::ScopedLock lock(getSceneCacheMutex()); + for(SceneCache::iterator itr = getSceneCache().begin(); + itr != getSceneCache().end(); ++itr) { Scene* scene = itr->get(); if (scene==this) { - s_sceneCache.erase(itr); + getSceneCache().erase(itr); break; } } @@ -97,9 +107,9 @@ void Scene::updateSceneGraph(osg::NodeVisitor& updateVisitor) Scene* Scene::getScene(osg::Node* node) { - OpenThreads::ScopedLock lock(s_sceneCacheMutex); - for(SceneCache::iterator itr = s_sceneCache.begin(); - itr != s_sceneCache.end(); + OpenThreads::ScopedLock lock(getSceneCacheMutex()); + for(SceneCache::iterator itr = getSceneCache().begin(); + itr != getSceneCache().end(); ++itr) { Scene* scene = itr->get();