[PATCH] D129123: ManagedStatic: remove from PluginLoader

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 01:42:17 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2fe3589acdbb: ManagedStatic: remove from PluginLoader (authored by nhaehnle).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129123/new/

https://reviews.llvm.org/D129123

Files:
  llvm/lib/Support/PluginLoader.cpp


Index: llvm/lib/Support/PluginLoader.cpp
===================================================================
--- llvm/lib/Support/PluginLoader.cpp
+++ llvm/lib/Support/PluginLoader.cpp
@@ -13,34 +13,46 @@
 #define DONT_GET_PLUGIN_LOADER_OPTION
 #include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/DynamicLibrary.h"
-#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/raw_ostream.h"
 #include <vector>
 using namespace llvm;
 
-static ManagedStatic<std::vector<std::string> > Plugins;
-static ManagedStatic<sys::SmartMutex<true> > PluginsLock;
+namespace {
+
+struct Plugins {
+  sys::SmartMutex<true> Lock;
+  std::vector<std::string> List;
+};
+
+Plugins &getPlugins() {
+  static Plugins P;
+  return P;
+}
+
+} // anonymous namespace
 
 void PluginLoader::operator=(const std::string &Filename) {
-  sys::SmartScopedLock<true> Lock(*PluginsLock);
+  auto &P = getPlugins();
+  sys::SmartScopedLock<true> Lock(P.Lock);
   std::string Error;
   if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
     errs() << "Error opening '" << Filename << "': " << Error
            << "\n  -load request ignored.\n";
   } else {
-    Plugins->push_back(Filename);
+    P.List.push_back(Filename);
   }
 }
 
 unsigned PluginLoader::getNumPlugins() {
-  sys::SmartScopedLock<true> Lock(*PluginsLock);
-  return Plugins.isConstructed() ? Plugins->size() : 0;
+  auto &P = getPlugins();
+  sys::SmartScopedLock<true> Lock(P.Lock);
+  return P.List.size();
 }
 
 std::string &PluginLoader::getPlugin(unsigned num) {
-  sys::SmartScopedLock<true> Lock(*PluginsLock);
-  assert(Plugins.isConstructed() && num < Plugins->size() &&
-         "Asking for an out of bounds plugin");
-  return (*Plugins)[num];
+  auto &P = getPlugins();
+  sys::SmartScopedLock<true> Lock(P.Lock);
+  assert(num < P.List.size() && "Asking for an out of bounds plugin");
+  return P.List[num];
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129123.449587.patch
Type: text/x-patch
Size: 1941 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220803/1d7c7345/attachment.bin>


More information about the llvm-commits mailing list