[llvm-commits] [llvm] r73912 - /llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp

Owen Anderson resistor at mac.com
Mon Jun 22 15:30:58 PDT 2009


Author: resistor
Date: Mon Jun 22 17:30:56 2009
New Revision: 73912

URL: http://llvm.org/viewvc/llvm-project?rev=73912&view=rev
Log:
Add locking around the external function lookup table for the interpreter.

Modified:
    llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp

Modified: llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp?rev=73912&r1=73911&r2=73912&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Mon Jun 22 17:30:56 2009
@@ -27,6 +27,7 @@
 #include "llvm/System/DynamicLibrary.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/ManagedStatic.h"
+#include "llvm/System/Mutex.h"
 #include <csignal>
 #include <cstdio>
 #include <map>
@@ -45,6 +46,8 @@
 
 using namespace llvm;
 
+static ManagedStatic<sys::Mutex> FunctionsLock;
+
 typedef GenericValue (*ExFunc)(const FunctionType *,
                                const std::vector<GenericValue> &);
 static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
@@ -94,6 +97,7 @@
     ExtName += getTypeID(FT->getContainedType(i));
   ExtName += "_" + F->getName();
 
+  sys::ScopedLock Writer(&*FunctionsLock);
   ExFunc FnPtr = FuncNames[ExtName];
   if (FnPtr == 0)
     FnPtr = FuncNames["lle_X_"+F->getName()];
@@ -246,12 +250,16 @@
                                      const std::vector<GenericValue> &ArgVals) {
   TheInterpreter = this;
 
+  FunctionsLock->acquire();
+
   // Do a lookup to see if the function is in our cache... this should just be a
   // deferred annotation!
   std::map<const Function *, ExFunc>::iterator FI = ExportedFunctions->find(F);
   if (ExFunc Fn = (FI == ExportedFunctions->end()) ? lookupFunction(F)
-                                                   : FI->second)
+                                                   : FI->second) {
+    FunctionsLock->release();
     return Fn(F->getFunctionType(), ArgVals);
+  }
 
 #ifdef USE_LIBFFI
   std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(F);
@@ -264,6 +272,8 @@
   } else {
     RawFn = RF->second;
   }
+  
+  FunctionsLock->release();
 
   GenericValue Result;
   if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getTargetData(), Result))
@@ -529,6 +539,7 @@
 
 
 void Interpreter::initializeExternalFunctions() {
+  sys::ScopedLock Writer(&*FunctionsLock);
   FuncNames["lle_X_atexit"]       = lle_X_atexit;
   FuncNames["lle_X_exit"]         = lle_X_exit;
   FuncNames["lle_X_abort"]        = lle_X_abort;





More information about the llvm-commits mailing list