From 12963113ba5566ba97183c05b21b69362270e423 Mon Sep 17 00:00:00 2001 From: Tobias Leibner <l_tobi01@CORRAN.uni-muenster.de> Date: Wed, 7 Oct 2015 15:36:03 +0200 Subject: [PATCH] [functions.expression] use lock_guard and fix merge error --- dune/stuff/functions/expression.hh | 2 +- dune/stuff/functions/expression/base.hh | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/dune/stuff/functions/expression.hh b/dune/stuff/functions/expression.hh index 8194f0d0b..46febc12f 100644 --- a/dune/stuff/functions/expression.hh +++ b/dune/stuff/functions/expression.hh @@ -237,7 +237,7 @@ public: << function_->variable() << "\n" << "The expression of this functional is: " - << expression().at(rr * dimRangeCols + cc) + << function_->expression().at(rr * dimRangeCols + cc) << "\n" << "You tried to evaluate it with: xx = " << xx diff --git a/dune/stuff/functions/expression/base.hh b/dune/stuff/functions/expression/base.hh index c0abd21b2..d945e10da 100644 --- a/dune/stuff/functions/expression/base.hh +++ b/dune/stuff/functions/expression/base.hh @@ -86,14 +86,13 @@ public: void evaluate(const Dune::FieldVector<DomainFieldType, dimDomain>& arg, Dune::FieldVector<RangeFieldType, dimRange>& ret) const { - mutex_.lock(); + std::lock_guard<std::mutex> guard(mutex_); // copy arg for (typename Dune::FieldVector<DomainFieldType, dimDomain>::size_type ii = 0; ii < dimDomain; ++ii) *(arg_[ii]) = arg[ii]; // copy ret for (typename Dune::FieldVector<RangeFieldType, dimRange>::size_type ii = 0; ii < dimRange; ++ii) ret[ii] = op_[ii]->Val(); - mutex_.unlock(); } /** @@ -101,7 +100,7 @@ public: */ void evaluate(const Dune::DynamicVector<DomainFieldType>& arg, Dune::DynamicVector<RangeFieldType>& ret) const { - mutex_.lock(); + std::lock_guard<std::mutex> guard(mutex_); // check for sizes assert(arg.size() > 0); if (ret.size() != dimRange) @@ -112,13 +111,12 @@ public: // copy ret for (typename Dune::DynamicVector<RangeFieldType>::size_type ii = 0; ii < dimRange; ++ii) ret[ii] = op_[ii]->Val(); - mutex_.unlock(); } void evaluate(const Dune::FieldVector<DomainFieldType, dimDomain>& arg, Dune::DynamicVector<RangeFieldType>& ret) const { - mutex_.lock(); + std::lock_guard<std::mutex> guard(mutex_); // check for sizes if (ret.size() != dimRange) ret = Dune::DynamicVector<RangeFieldType>(dimRange); @@ -128,7 +126,6 @@ public: // copy ret for (typename Dune::DynamicVector<RangeFieldType>::size_type ii = 0; ii < dimRange; ++ii) ret[ii] = op_[ii]->Val(); - mutex_.unlock(); } /** @@ -136,7 +133,7 @@ public: */ void evaluate(const Dune::DynamicVector<DomainFieldType>& arg, Dune::FieldVector<RangeFieldType, dimRange>& ret) const { - mutex_.lock(); + std::lock_guard<std::mutex> guard(mutex_); assert(arg.size() > 0); // copy arg for (size_t ii = 0; ii < std::min(dimDomain, arg.size()); ++ii) @@ -144,7 +141,6 @@ public: // copy ret for (size_t ii = 0; ii < dimRange; ++ii) ret[ii] = op_[ii]->Val(); - mutex_.unlock(); } void report(const std::string _name = "dune.stuff.function.mathexpressionbase", std::ostream& stream = std::cout, -- GitLab