aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-22 22:30:56 +0000
committerOwen Anderson <resistor@mac.com>2009-06-22 22:30:56 +0000
commit7c9c068d664d0840f960644686b2ed21ceeb2d15 (patch)
treefff60d64cdb0a2158eb871d597758d87493f8ec8 /lib/ExecutionEngine
parentfa97492da49ef4c4c36d15a76021397aa444421a (diff)
downloadexternal_llvm-7c9c068d664d0840f960644686b2ed21ceeb2d15.zip
external_llvm-7c9c068d664d0840f960644686b2ed21ceeb2d15.tar.gz
external_llvm-7c9c068d664d0840f960644686b2ed21ceeb2d15.tar.bz2
Add locking around the external function lookup table for the interpreter.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73912 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 160f1ba..b8525a3 100644
--- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -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 @@ static ExFunc lookupFunction(const Function *F) {
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 @@ GenericValue Interpreter::callExternalFunction(Function *F,
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 @@ GenericValue Interpreter::callExternalFunction(Function *F,
} else {
RawFn = RF->second;
}
+
+ FunctionsLock->release();
GenericValue Result;
if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getTargetData(), Result))
@@ -529,6 +539,7 @@ GenericValue lle_X_fprintf(const FunctionType *FT,
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;