[llvm] r190921 - Make DynamicLibrary use ManagedStatic. This is pretty simple and should just work as

Timur Iskhodzhanov timurrrr at google.com
Tue Sep 17 23:23:19 PDT 2013


FYI this results in a build failure on Windows:

lib\support\Windows/DynamicLibrary.inc(74) : error C3861: 'getMutex':
identifier not found
lib\support\Windows/DynamicLibrary.inc(117) : error C3861: 'getMutex':
identifier not found
lib\support\Windows/DynamicLibrary.inc(120) : error C2451: conditional
expression of type 'llvm::ManagedStatic<C>' is illegal
        with
        [
            C=llvm::StringMap<void *>
        ]
        No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called


2013/9/18 Filip Pizlo <fpizlo at apple.com>

> Author: fpizlo
> Date: Wed Sep 18 01:03:27 2013
> New Revision: 190921
>
> URL: http://llvm.org/viewvc/llvm-project?rev=190921&view=rev
> Log:
> Make DynamicLibrary use ManagedStatic. This is pretty simple and should
> just work as
> advertised - but it does have the caveat that calls to
> DynamicLibrary::AddSymbol will
> "reset" if you shutdown llvm and try to come back for seconds.  This is a
> subtle
> behavior change, but I'm assuming that nobody is affected by it.
>
>
> Modified:
>     llvm/trunk/lib/Support/DynamicLibrary.cpp
>
> Modified: llvm/trunk/lib/Support/DynamicLibrary.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DynamicLibrary.cpp?rev=190921&r1=190920&r2=190921&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Support/DynamicLibrary.cpp (original)
> +++ llvm/trunk/lib/Support/DynamicLibrary.cpp Wed Sep 18 01:03:27 2013
> @@ -14,6 +14,7 @@
>
>  //===----------------------------------------------------------------------===//
>
>  #include "llvm/Support/DynamicLibrary.h"
> +#include "llvm/Support/ManagedStatic.h"
>  #include "llvm/ADT/DenseSet.h"
>  #include "llvm/ADT/StringMap.h"
>  #include "llvm/Config/config.h"
> @@ -22,31 +23,12 @@
>  #include <cstring>
>
>  // Collection of symbol name/value pairs to be searched prior to any
> libraries.
> -static llvm::StringMap<void *> *ExplicitSymbols = 0;
> -
> -namespace {
> -
> -struct ExplicitSymbolsDeleter {
> -  ~ExplicitSymbolsDeleter() {
> -    delete ExplicitSymbols;
> -  }
> -};
> -
> -}
> -
> -static ExplicitSymbolsDeleter Dummy;
> -
> -
> -static llvm::sys::SmartMutex<true>& getMutex() {
> -  static llvm::sys::SmartMutex<true> HandlesMutex;
> -  return HandlesMutex;
> -}
> +static llvm::ManagedStatic<llvm::StringMap<void *> > ExplicitSymbols;
> +static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > SymbolsMutex;
>
>  void llvm::sys::DynamicLibrary::AddSymbol(StringRef symbolName,
>                                            void *symbolValue) {
> -  SmartScopedLock<true> lock(getMutex());
> -  if (ExplicitSymbols == 0)
> -    ExplicitSymbols = new StringMap<void*>();
> +  SmartScopedLock<true> lock(*SymbolsMutex);
>    (*ExplicitSymbols)[symbolName] = symbolValue;
>  }
>
> @@ -72,7 +54,7 @@ static DenseSet<void *> *OpenedHandles =
>
>  DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
>                                                     std::string *errMsg) {
> -  SmartScopedLock<true> lock(getMutex());
> +  SmartScopedLock<true> lock(*SymbolsMutex);
>
>    void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL);
>    if (handle == 0) {
> @@ -126,10 +108,10 @@ void *SearchForAddressOfSpecialSymbol(co
>  }
>
>  void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
> -  SmartScopedLock<true> Lock(getMutex());
> +  SmartScopedLock<true> Lock(*SymbolsMutex);
>
>    // First check symbols added via AddSymbol().
> -  if (ExplicitSymbols) {
> +  if (ExplicitSymbols.isConstructed()) {
>      StringMap<void *>::iterator i = ExplicitSymbols->find(symbolName);
>
>      if (i != ExplicitSymbols->end())
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130918/0e58c805/attachment.html>


More information about the llvm-commits mailing list