From 023b52e3822e6c7deab405740a61d5465c7bed96 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 13 Jan 2017 22:09:48 -0700 Subject: [PATCH] Guard access to mutable variables with a mutex. --- include/deal.II/fe/fe_poly_tensor.h | 8 ++++++++ source/fe/fe_poly_tensor.cc | 6 ++++++ 2 files changed, 14 insertions(+) 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; -- 2.39.5