X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FPluginLoader.cpp;h=36caecffeede769e1d5012b51101f6bcddee61ac;hb=4153982375811da8ffe8d8cc45e09d44c6f40642;hp=3c9de89a4265d2b8ea513b768496a16c20471c7f;hpb=1a097e30d39e60303ae2b19f7a56e813f3e3c18e;p=oota-llvm.git diff --git a/lib/Support/PluginLoader.cpp b/lib/Support/PluginLoader.cpp index 3c9de89a426..36caecffeed 100644 --- a/lib/Support/PluginLoader.cpp +++ b/lib/Support/PluginLoader.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -12,33 +12,36 @@ //===----------------------------------------------------------------------===// #define DONT_GET_PLUGIN_LOADER_OPTION +#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PluginLoader.h" -#include "llvm/Support/Streams.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/System/DynamicLibrary.h" -#include +#include "llvm/System/Mutex.h" #include using namespace llvm; -static std::vector *Plugins; +static ManagedStatic > Plugins; +static ManagedStatic > PluginsLock; void PluginLoader::operator=(const std::string &Filename) { - if (!Plugins) - Plugins = new std::vector(); - + sys::SmartScopedLock Lock(*PluginsLock); std::string Error; if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) { - cerr << "Error opening '" << Filename << "': " << Error - << "\n -load request ignored.\n"; + errs() << "Error opening '" << Filename << "': " << Error + << "\n -load request ignored.\n"; } else { Plugins->push_back(Filename); } } unsigned PluginLoader::getNumPlugins() { - return Plugins ? Plugins->size() : 0; + sys::SmartScopedLock Lock(*PluginsLock); + return Plugins.isConstructed() ? Plugins->size() : 0; } std::string &PluginLoader::getPlugin(unsigned num) { - assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin"); + sys::SmartScopedLock Lock(*PluginsLock); + assert(Plugins.isConstructed() && num < Plugins->size() && + "Asking for an out of bounds plugin"); return (*Plugins)[num]; }