From: Wolfgang Bangerth Date: Sat, 14 Jan 2017 05:09:48 +0000 (-0700) Subject: Guard access to mutable variables with a mutex. X-Git-Tag: v8.5.0-rc1~245^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=023b52e3822e6c7deab405740a61d5465c7bed96;p=dealii.git Guard access to mutable variables with a mutex. --- diff --git a/include/deal.II/fe/fe_poly_tensor.h b/include/deal.II/fe/fe_poly_tensor.h index a754a5980b..517ca38997 100644 --- a/include/deal.II/fe/fe_poly_tensor.h +++ b/include/deal.II/fe/fe_poly_tensor.h @@ -17,10 +17,13 @@ #define dealii__fe_poly_tensor_h +#include #include #include #include #include +#include + DEAL_II_NAMESPACE_OPEN @@ -408,6 +411,11 @@ protected: */ FullMatrix inverse_node_matrix; + /** + * A mutex to be used to guard access to the variables below. + */ + mutable Threads::Mutex cache_mutex; + /** * If a shape function is computed at a single point, we must compute all of * them to apply #inverse_node_matrix. In order to avoid too much overhead, diff --git a/source/fe/fe_poly_tensor.cc b/source/fe/fe_poly_tensor.cc index b2a6a0c904..212d9cdd93 100644 --- a/source/fe/fe_poly_tensor.cc +++ b/source/fe/fe_poly_tensor.cc @@ -180,6 +180,8 @@ FE_PolyTensor::shape_value_component Assert (idofs_per_cell, ExcIndexRange(i,0,this->dofs_per_cell)); Assert (component < dim, ExcIndexRange (component, 0, dim)); + Threads::Mutex::ScopedLock lock (cache_mutex); + if (cached_point != p || cached_values.size() == 0) { cached_point = p; @@ -223,6 +225,8 @@ FE_PolyTensor::shape_grad_component Assert (idofs_per_cell, ExcIndexRange(i,0,this->dofs_per_cell)); Assert (component < dim, ExcIndexRange (component, 0, dim)); + Threads::Mutex::ScopedLock lock (cache_mutex); + if (cached_point != p || cached_grads.size() == 0) { cached_point = p; @@ -268,6 +272,8 @@ FE_PolyTensor::shape_grad_grad_component Assert (idofs_per_cell, ExcIndexRange(i,0,this->dofs_per_cell)); Assert (component < dim, ExcIndexRange (component, 0, dim)); + Threads::Mutex::ScopedLock lock (cache_mutex); + if (cached_point != p || cached_grad_grads.size() == 0) { cached_point = p;