[PATCH] D129123: ManagedStatic: remove from PluginLoader
Nicolai Hähnle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 5 02:17:51 PDT 2022
nhaehnle created this revision.
nhaehnle added reviewers: efriedma, lattner.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
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.442224.patch
Type: text/x-patch
Size: 1941 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/6166296d/attachment.bin>
More information about the llvm-commits
mailing list