[Libreoffice-commits] .: vcl/unx

Caolán McNamara caolan at kemper.freedesktop.org
Mon Apr 18 06:51:31 PDT 2011


 vcl/unx/source/gdi/gcach_xpeer.cxx |   48 +++++++++++++++++++++++++++----------
 vcl/unx/source/gdi/gcach_xpeer.hxx |   13 +++++-----
 2 files changed, 43 insertions(+), 18 deletions(-)

New commits:
commit 2acdffcaa1f529955ac57bd773c906eb26fb9582
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Apr 18 14:48:23 2011 +0100

    Related: rhbz#691083 make sure this is thread-safe

diff --git a/vcl/unx/source/gdi/gcach_xpeer.cxx b/vcl/unx/source/gdi/gcach_xpeer.cxx
index 09246f2..69a3cd1 100644
--- a/vcl/unx/source/gdi/gcach_xpeer.cxx
+++ b/vcl/unx/source/gdi/gcach_xpeer.cxx
@@ -649,27 +649,51 @@ X11GlyphCache::X11GlyphCache( X11GlyphPeer& rPeer )
 
 // ---------------------------------------------------------------------------
 
-static X11GlyphPeer* pX11GlyphPeer = NULL;
-static X11GlyphCache* pX11GlyphCache = NULL;
+namespace
+{
+    struct GlyphCacheHolder
+    {
+    private:
+        X11GlyphPeer* m_pX11GlyphPeer;
+        X11GlyphCache* m_pX11GlyphCache;
+    public:
+        GlyphCacheHolder()
+        {
+            m_pX11GlyphPeer = new X11GlyphPeer();
+            m_pX11GlyphCache = new X11GlyphCache( *m_pX11GlyphPeer );
+        }
+        void release()
+        {
+            delete m_pX11GlyphCache;
+            delete m_pX11GlyphPeer;
+            m_pX11GlyphCache = NULL;
+            m_pX11GlyphPeer = NULL;
+        }
+        X11GlyphCache& getGlyphCache()
+        {
+            return *m_pX11GlyphCache;
+        }
+        ~GlyphCacheHolder()
+        {
+            release();
+        }
+    };
+}
+
+struct theGlyphCacheHolder :
+    public rtl::Static<GlyphCacheHolder, theGlyphCacheHolder>
+{};
 
 X11GlyphCache& X11GlyphCache::GetInstance()
 {
-    if( !pX11GlyphCache )
-    {
-        pX11GlyphPeer = new X11GlyphPeer();
-        pX11GlyphCache = new X11GlyphCache( *pX11GlyphPeer );
-    }
-    return *pX11GlyphCache;
+    return theGlyphCacheHolder::get().getGlyphCache();
 }
 
 // ---------------------------------------------------------------------------
 
 void X11GlyphCache::KillInstance()
 {
-    delete pX11GlyphCache;
-    delete pX11GlyphPeer;
-    pX11GlyphCache = NULL;
-    pX11GlyphPeer = NULL;
+    return theGlyphCacheHolder::get().release();
 }
 
 // ===========================================================================
diff --git a/vcl/unx/source/gdi/gcach_xpeer.hxx b/vcl/unx/source/gdi/gcach_xpeer.hxx
index 84fe101..7795162 100644
--- a/vcl/unx/source/gdi/gcach_xpeer.hxx
+++ b/vcl/unx/source/gdi/gcach_xpeer.hxx
@@ -84,12 +84,13 @@ private:
 class X11GlyphCache : public GlyphCache
 {
 public:
-    X11GlyphPeer&      GetPeer() { return reinterpret_cast<X11GlyphPeer&>( mrPeer ); }
-static X11GlyphCache&  GetInstance();
-static void            KillInstance();
-
-private:
-                       X11GlyphCache( X11GlyphPeer& );
+    X11GlyphCache( X11GlyphPeer& );
+    X11GlyphPeer& GetPeer()
+    {
+        return reinterpret_cast<X11GlyphPeer&>(mrPeer);
+    }
+    static X11GlyphCache& GetInstance();
+    static void  KillInstance();
 };
 
 #endif // _SV_GCACH_XPEER_HXX


More information about the Libreoffice-commits mailing list