fixed: expreval is not reentrant

thus we have to use a lock when running with multithreading

git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@1404 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
akva 2012-01-18 13:43:31 +00:00 committed by Knut Morten Okstad
parent 5a19d2187d
commit f70fc31825
2 changed files with 23 additions and 2 deletions

View File

@ -371,6 +371,9 @@ EvalFunction::EvalFunction(const char* function)
x = v->GetAddress("x");
y = v->GetAddress("y");
z = v->GetAddress("z");
#ifdef USE_OPENMP
omp_init_lock(&lock);
#endif
} catch(...) {
std::cerr <<" *** Error parsing function: " << function << std::endl;
}
@ -381,19 +384,30 @@ EvalFunction::~EvalFunction()
delete expr;
delete f;
delete v;
#ifdef USE_OPENMP
omp_destroy_lock(&lock);
#endif
}
real EvalFunction::evaluate(const Vec3& X) const
{
#ifdef USE_OPENMP
omp_set_lock(const_cast<omp_lock_t*>(&lock));
#endif
double result=0.f;
try {
*x = X.x;
*y = X.y;
*z = X.z;
return expr->Evaluate();
result = expr->Evaluate();
} catch(...) {
std::cerr << "Error evaluating function" << std::endl;
return 0;
}
#ifdef USE_OPENMP
omp_unset_lock(const_cast<omp_lock_t*>(&lock));
#endif
return result;
}
template<>

View File

@ -19,6 +19,10 @@
#include <string>
#include <vector>
#ifdef USE_OPENMP
#include <omp.h>
#endif
namespace ExprEval {
class Expression;
class FunctionList;
@ -416,6 +420,9 @@ class EvalFunction : public RealFunc
real* x;
real* y;
real* z;
#ifdef USE_OPENMP
omp_lock_t lock;
#endif
};