Changeset View
Changeset View
Standalone View
Standalone View
lib/Support/PluginLoader.cpp
Show All 10 Lines | |||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#define DONT_GET_PLUGIN_LOADER_OPTION | #define DONT_GET_PLUGIN_LOADER_OPTION | ||||
#include "llvm/Support/PluginLoader.h" | #include "llvm/Support/PluginLoader.h" | ||||
#include "llvm/Support/DynamicLibrary.h" | #include "llvm/Support/DynamicLibrary.h" | ||||
#include "llvm/Support/ManagedStatic.h" | #include "llvm/Support/ManagedStatic.h" | ||||
#include "llvm/Support/Mutex.h" | #include "llvm/Support/Mutex.h" | ||||
#include "llvm/Support/MutexGuard.h" | |||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
#include <vector> | #include <vector> | ||||
using namespace llvm; | using namespace llvm; | ||||
static ManagedStatic<std::vector<std::string> > Plugins; | static ManagedStatic<std::vector<std::string> > Plugins; | ||||
static ManagedStatic<sys::SmartMutex<true> > PluginsLock; | static ManagedStatic<sys::RecursiveDebugMutex> PluginsLock; | ||||
void PluginLoader::operator=(const std::string &Filename) { | void PluginLoader::operator=(const std::string &Filename) { | ||||
sys::SmartScopedLock<true> Lock(*PluginsLock); | llvm::MutexGuard Lock(*PluginsLock); | ||||
std::string Error; | std::string Error; | ||||
if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) { | if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) { | ||||
errs() << "Error opening '" << Filename << "': " << Error | errs() << "Error opening '" << Filename << "': " << Error | ||||
<< "\n -load request ignored.\n"; | << "\n -load request ignored.\n"; | ||||
} else { | } else { | ||||
Plugins->push_back(Filename); | Plugins->push_back(Filename); | ||||
} | } | ||||
} | } | ||||
unsigned PluginLoader::getNumPlugins() { | unsigned PluginLoader::getNumPlugins() { | ||||
sys::SmartScopedLock<true> Lock(*PluginsLock); | llvm::MutexGuard Lock(*PluginsLock); | ||||
return Plugins.isConstructed() ? Plugins->size() : 0; | return Plugins.isConstructed() ? Plugins->size() : 0; | ||||
} | } | ||||
std::string &PluginLoader::getPlugin(unsigned num) { | std::string &PluginLoader::getPlugin(unsigned num) { | ||||
sys::SmartScopedLock<true> Lock(*PluginsLock); | llvm::MutexGuard Lock(*PluginsLock); | ||||
assert(Plugins.isConstructed() && num < Plugins->size() && | assert(Plugins.isConstructed() && num < Plugins->size() && | ||||
"Asking for an out of bounds plugin"); | "Asking for an out of bounds plugin"); | ||||
return (*Plugins)[num]; | return (*Plugins)[num]; | ||||
} | } |