From 3304646c4ced3fd6d1791b2ddf26889d23c6c699 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 1 Sep 2007 15:24:22 +0000 Subject: [PATCH] Changed Font's mutex to become a static mutex shared between all instances of Font. This ensures single threaded access of the freetype plugin. --- include/osgText/Font | 2 +- src/osgText/Font.cpp | 6 ++++++ src/osgText/Text.cpp | 2 +- src/osgWrappers/osgText/Font.cpp | 12 ++++-------- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/osgText/Font b/include/osgText/Font index 309f72071..03f20a6a8 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -164,7 +164,7 @@ public: typedef OpenThreads::Mutex FontMutex; /** Get the mutex that enables the serialization of calls to this font.*/ - FontMutex* getSerializeFontCallsMutex() const { return &_serializeFontCallsMutex; } + static FontMutex* getSerializeFontCallsMutex(); protected: diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 6f7a6f43b..1fec08a98 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -30,6 +30,12 @@ static osg::ApplicationUsageProxy Font_e0(osg::ApplicationUsage::ENVIRONMENTAL_V static OpenThreads::Mutex s_FontFileMutex; +Font::FontMutex* osgText::Font::getSerializeFontCallsMutex() +{ + static OpenThreads::Mutex s_FontCallsMutex; + return &s_FontCallsMutex; +} + std::string osgText::findFontFile(const std::string& str) { // try looking in OSGFILEPATH etc first for fonts. diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 3cf9c3f91..1800883f8 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -464,7 +464,7 @@ void Text::computeGlyphRepresentation() return; } - OpenThreads::ScopedLock lock(*(activefont->getSerializeFontCallsMutex())); + OpenThreads::ScopedLock lock(*(Font::getSerializeFontCallsMutex())); // initialize bounding box, it will be expanded during glyph position calculation _textBB.init(); diff --git a/src/osgWrappers/osgText/Font.cpp b/src/osgWrappers/osgText/Font.cpp index eadf16fc6..a960d2637 100644 --- a/src/osgWrappers/osgText/Font.cpp +++ b/src/osgWrappers/osgText/Font.cpp @@ -213,11 +213,10 @@ BEGIN_OBJECT_REFLECTOR(osgText::Font) __void__releaseGLObjects__osg_State_P1, "If State is non-zero, this function releases OpenGL objects for the specified graphics context. ", "Otherwise, releases OpenGL objexts for all graphics contexts. "); - I_Method0(osgText::Font::FontMutex *, getSerializeFontCallsMutex, - Properties::NON_VIRTUAL, - __FontMutex_P1__getSerializeFontCallsMutex, - "Get the mutex that enables the serialization of calls to this font. ", - ""); + I_StaticMethod0(osgText::Font::FontMutex *, getSerializeFontCallsMutex, + __FontMutex_P1__getSerializeFontCallsMutex_S, + "Get the mutex that enables the serialization of calls to this font. ", + ""); I_ProtectedMethod4(void, addGlyph, IN, unsigned int, width, IN, unsigned int, height, IN, unsigned int, charcode, IN, osgText::Font::Glyph *, glyph, Properties::NON_VIRTUAL, Properties::NON_CONST, @@ -248,9 +247,6 @@ BEGIN_OBJECT_REFLECTOR(osgText::Font) I_SimpleProperty(osg::Texture::FilterMode, MinFilterHint, __osg_Texture_FilterMode__getMinFilterHint, __void__setMinFilterHint__osg_Texture_FilterMode); - I_SimpleProperty(osgText::Font::FontMutex *, SerializeFontCallsMutex, - __FontMutex_P1__getSerializeFontCallsMutex, - 0); I_SimpleProperty(osg::StateSet *, StateSet, __osg_StateSet_P1__getStateSet, __void__setStateSet__osg_StateSet_P1);