[Lldb-commits] [lldb] r216123 - Revert "Avoid global contstructors and place static variables

Zachary Turner zturner at google.com
Wed Aug 20 13:53:05 PDT 2014


Author: zturner
Date: Wed Aug 20 15:53:05 2014
New Revision: 216123

URL: http://llvm.org/viewvc/llvm-project?rev=216123&view=rev
Log:
Revert "Avoid global contstructors and place static variables
inside classes as static local variables and remove the static
ivars. Subclasses should use the accessor functions."

This change moved global statics to function local statics, but
forgot to make the locals static in the function, breaking all
platforms.  Furthermore, MSVC doesn't support thread-safe function
local statics, so any use of a function local static on non
primitive types is undefined behavior on MSVC.

Reverting due to the fact that it's broken on all platforms, but
would like to have a discussion about the thread-safety issue
before it goes back in.

Modified:
    lldb/trunk/include/lldb/Host/HostInfoBase.h
    lldb/trunk/source/Host/common/HostInfoBase.cpp

Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostInfoBase.h?rev=216123&r1=216122&r2=216123&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostInfoBase.h (original)
+++ lldb/trunk/include/lldb/Host/HostInfoBase.h Wed Aug 20 15:53:05 2014
@@ -80,6 +80,14 @@ class HostInfoBase
 
   protected:
     static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64);
+
+    static uint32_t m_number_cpus;
+    static std::string m_vendor_string;
+    static std::string m_os_string;
+    static std::string m_host_triple;
+
+    static ArchSpec m_host_arch_32;
+    static ArchSpec m_host_arch_64;
 };
 }
 

Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=216123&r1=216122&r2=216123&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Wed Aug 20 15:53:05 2014
@@ -22,86 +22,85 @@
 using namespace lldb;
 using namespace lldb_private;
 
+uint32_t HostInfoBase::m_number_cpus = 0;
+std::string HostInfoBase::m_vendor_string;
+std::string HostInfoBase::m_os_string;
+std::string HostInfoBase::m_host_triple;
+ArchSpec HostInfoBase::m_host_arch_32;
+ArchSpec HostInfoBase::m_host_arch_64;
 
 uint32_t
 HostInfoBase::GetNumberCPUS()
 {
     static bool is_initialized = false;
-    uint32_t g_number_cpus = 0;
     if (!is_initialized)
     {
-        g_number_cpus = std::thread::hardware_concurrency();
+        m_number_cpus = std::thread::hardware_concurrency();
         is_initialized = true;
     }
 
-    return g_number_cpus;
+    return m_number_cpus;
 }
 
 llvm::StringRef
 HostInfoBase::GetVendorString()
 {
     static bool is_initialized = false;
-    std::string g_vendor_string;
     if (!is_initialized)
     {
         const ArchSpec &host_arch = HostInfo::GetArchitecture();
         const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName();
-        g_vendor_string.assign(str_ref.begin(), str_ref.end());
+        m_vendor_string.assign(str_ref.begin(), str_ref.end());
         is_initialized = true;
     }
-    return llvm::StringRef(g_vendor_string);
+    return m_vendor_string;
 }
 
 llvm::StringRef
 HostInfoBase::GetOSString()
 {
     static bool is_initialized = false;
-    std::string g_os_string;
     if (!is_initialized)
     {
         const ArchSpec &host_arch = HostInfo::GetArchitecture();
         const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName();
-        g_os_string.assign(str_ref.begin(), str_ref.end());
+        m_os_string.assign(str_ref.begin(), str_ref.end());
         is_initialized = true;
     }
-    return llvm::StringRef(g_os_string);
+    return m_os_string;
 }
 
 llvm::StringRef
 HostInfoBase::GetTargetTriple()
 {
     static bool is_initialized = false;
-    std::string g_host_triple;
     if (!is_initialized)
     {
         const ArchSpec &host_arch = HostInfo::GetArchitecture();
-        g_host_triple = host_arch.GetTriple().getTriple();
+        m_host_triple = host_arch.GetTriple().getTriple();
         is_initialized = true;
     }
-    return g_host_triple;
+    return m_host_triple;
 }
 
 const ArchSpec &
 HostInfoBase::GetArchitecture(ArchitectureKind arch_kind)
 {
     static bool is_initialized = false;
-    static ArchSpec g_host_arch_32;
-    static ArchSpec g_host_arch_64;
-
     if (!is_initialized)
     {
-        HostInfo::ComputeHostArchitectureSupport(g_host_arch_32, g_host_arch_64);
+        HostInfo::ComputeHostArchitectureSupport(m_host_arch_32, m_host_arch_64);
         is_initialized = true;
     }
 
     // If an explicit 32 or 64-bit architecture was requested, return that.
     if (arch_kind == eArchKind32)
-        return g_host_arch_32;
+        return m_host_arch_32;
     if (arch_kind == eArchKind64)
-        return g_host_arch_64;
+        return m_host_arch_64;
 
     // Otherwise prefer the 64-bit architecture if it is valid.
-    return (g_host_arch_64.IsValid()) ? g_host_arch_64 : g_host_arch_32;
+    return (m_host_arch_64.IsValid()) ? m_host_arch_64 : m_host_arch_32;
 }
 
 void





More information about the lldb-commits mailing list