[Lldb-commits] [PATCH] D44060: [lldb] Fix "code requires global destructor" warning in g_architecture_mutex

Kuba (Brecka) Mracek via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 2 17:02:13 PST 2018


kubamracek created this revision.
kubamracek added reviewers: jingham, jasonmolenda, davide, aprantl.

https://reviews.llvm.org/D44060

Files:
  source/Core/PluginManager.cpp


Index: source/Core/PluginManager.cpp
===================================================================
--- source/Core/PluginManager.cpp
+++ source/Core/PluginManager.cpp
@@ -285,7 +285,10 @@
 
 typedef std::vector<ArchitectureInstance> ArchitectureInstances;
 
-static std::mutex g_architecture_mutex;
+static std::mutex &GetArchitectureMutex() {
+    static std::mutex g_architecture_mutex;
+    return g_architecture_mutex;
+}
 
 static ArchitectureInstances &GetArchitectureInstances() {
   static ArchitectureInstances g_instances;
@@ -295,13 +298,13 @@
 void PluginManager::RegisterPlugin(const ConstString &name,
                                    llvm::StringRef description,
                                    ArchitectureCreateInstance create_callback) {
-  std::lock_guard<std::mutex> guard(g_architecture_mutex);
+  std::lock_guard<std::mutex> guard(GetArchitectureMutex());
   GetArchitectureInstances().push_back({name, description, create_callback});
 }
 
 void PluginManager::UnregisterPlugin(
     ArchitectureCreateInstance create_callback) {
-  std::lock_guard<std::mutex> guard(g_architecture_mutex);
+  std::lock_guard<std::mutex> guard(GetArchitectureMutex());
   auto &instances = GetArchitectureInstances();
 
   for (auto pos = instances.begin(), end = instances.end(); pos != end; ++pos) {
@@ -315,7 +318,7 @@
 
 std::unique_ptr<Architecture>
 PluginManager::CreateArchitectureInstance(const ArchSpec &arch) {
-  std::lock_guard<std::mutex> guard(g_architecture_mutex);
+  std::lock_guard<std::mutex> guard(GetArchitectureMutex());
   for (const auto &instances : GetArchitectureInstances()) {
     if (auto plugin_up = instances.create_callback(arch))
       return plugin_up;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44060.136886.patch
Type: text/x-patch
Size: 1708 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180303/ffce616c/attachment.bin>


More information about the lldb-commits mailing list