5e41dab
From fca3e47954fe36687989328ac90cbc6747e4bc4e Mon Sep 17 00:00:00 2001
5e41dab
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
5e41dab
Date: Mon, 14 Mar 2011 10:20:12 +0000
5e41dab
Subject: [PATCH] Related: rhbz#684477 make sure this is thread safe
5e41dab
5e41dab
---
5e41dab
 basegfx/source/polygon/b2dpolygontools.cxx |   36 +++++++++++++++++----------
5e41dab
 1 files changed, 23 insertions(+), 13 deletions(-)
5e41dab
5e41dab
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx
5e41dab
index 1967e6e..3271314 100644
5e41dab
--- a/basegfx/source/polygon/b2dpolygontools.cxx
5e41dab
+++ b/basegfx/source/polygon/b2dpolygontools.cxx
5e41dab
@@ -32,6 +32,7 @@
5e41dab
 #include <basegfx/polygon/b2dpolygontools.hxx>
5e41dab
 #include <osl/diagnose.h>
5e41dab
 #include <rtl/math.hxx>
5e41dab
+#include <rtl/instance.hxx>
5e41dab
 #include <basegfx/polygon/b2dpolygon.hxx>
5e41dab
 #include <basegfx/polygon/b2dpolypolygon.hxx>
5e41dab
 #include <basegfx/range/b2drange.hxx>
5e41dab
@@ -1836,22 +1837,31 @@ namespace basegfx
5e41dab
             return aRetval;
5e41dab
         }
5e41dab
 
5e41dab
-        B2DPolygon createUnitPolygon()
5e41dab
+        namespace
5e41dab
         {
5e41dab
-            static B2DPolygon aRetval;
5e41dab
-
5e41dab
-            if(!aRetval.count())
5e41dab
+            struct theUnitPolygon :
5e41dab
+                public rtl::StaticWithInit<B2DPolygon, theUnitPolygon>
5e41dab
             {
5e41dab
-                aRetval.append( B2DPoint( 0.0, 0.0 ) );
5e41dab
-                aRetval.append( B2DPoint( 1.0, 0.0 ) );
5e41dab
-                aRetval.append( B2DPoint( 1.0, 1.0 ) );
5e41dab
-                aRetval.append( B2DPoint( 0.0, 1.0 ) );
5e41dab
+                B2DPolygon operator () ()
5e41dab
+                {
5e41dab
+                    B2DPolygon aRetval;
5e41dab
 
5e41dab
-                // close
5e41dab
-                aRetval.setClosed( true );
5e41dab
-            }
5e41dab
-            
5e41dab
-            return aRetval;
5e41dab
+                    aRetval.append( B2DPoint( 0.0, 0.0 ) );
5e41dab
+                    aRetval.append( B2DPoint( 1.0, 0.0 ) );
5e41dab
+                    aRetval.append( B2DPoint( 1.0, 1.0 ) );
5e41dab
+                    aRetval.append( B2DPoint( 0.0, 1.0 ) );
5e41dab
+
5e41dab
+                    // close
5e41dab
+                    aRetval.setClosed( true );
5e41dab
+
5e41dab
+                    return aRetval;
5e41dab
+                }
5e41dab
+            };
5e41dab
+        }
5e41dab
+
5e41dab
+        B2DPolygon createUnitPolygon()
5e41dab
+        {
5e41dab
+            return theUnitPolygon::get();
5e41dab
         }
5e41dab
 
5e41dab
         B2DPolygon createPolygonFromCircle( const B2DPoint& rCenter, double fRadius )
5e41dab
-- 
5e41dab
1.7.4.1
5e41dab