diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-04-18 14:48:23 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-04-18 14:48:23 +0100 |
commit | 78de357b58a495f8c714c8167af6691a7a2f78ab (patch) | |
tree | c7cd85cd488a5d7a4ab15e5b675ecce8047f6714 | |
parent | af153ac082712e54e63522f743b0d0aff91eb876 (diff) |
Related: rhbz#691083 make sure this is thread-safe
-rw-r--r-- | vcl/unx/source/gdi/gcach_xpeer.cxx | 48 | ||||
-rw-r--r-- | vcl/unx/source/gdi/gcach_xpeer.hxx | 13 |
2 files changed, 43 insertions, 18 deletions
diff --git a/vcl/unx/source/gdi/gcach_xpeer.cxx b/vcl/unx/source/gdi/gcach_xpeer.cxx index 8cbf67ffe6dc..5c6bf42885b5 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 b634659876bd..eeea6309dcf2 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 |