]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
call GetCache() from a global object ctor to ensure that it is done before any thread...
[wxWidgets.git] / src / common / string.cpp
index c97125d2c46b1c6bd73fa3cd270ea54bae912297..827099f0a611bd82f7329006aeca04923e3d8ea8 100644 (file)
 const size_t wxString::npos = (size_t) -1;
 
 #if wxUSE_STRING_POS_CACHE
-wxTLS_TYPE(wxString::Cache) wxString::ms_cache;
+
+struct wxStrCacheInitializer
+{
+    wxStrCacheInitializer()
+    {
+        // calling this function triggers s_cache initialization in it, and
+        // from now on it becomes safe to call from multiple threads
+        wxString::GetCache();
+    }
+};
+
+static wxStrCacheInitializer gs_stringCacheInit;
 
 // gdb seems to be unable to display thread-local variables correctly, at least
 // not my 6.4.98 version under amd64, so provide this debugging helper to do it
 #ifdef __WXDEBUG__
 
+namespace
+{
+
 struct wxStrCacheDumper
 {
     static void ShowAll()
@@ -73,11 +87,11 @@ struct wxStrCacheDumper
         for ( unsigned n = 0; n < wxString::Cache::SIZE; n++ )
         {
             const wxString::Cache::Element&
-                c = wxString::ms_cache.cached[n];
+                c = wxString::GetCacheBegin()[n];
 
             printf("\t%u%s\t%p: pos=(%lu, %lu), len=%ld\n",
                    n,
-                   n == wxString::ms_cache.lastUsed ? " [*]" : "",
+                   n == wxString::LastUsedCacheElement() ? " [*]" : "",
                    c.str,
                    (unsigned long)c.pos,
                    (unsigned long)c.impl,
@@ -86,6 +100,8 @@ struct wxStrCacheDumper
     }
 };
 
+} // anonymous namespace
+
 void wxDumpStrCache() { wxStrCacheDumper::ShowAll(); }
 
 #endif // __WXDEBUG__