From: Denis Davydov Date: Tue, 31 Jan 2017 08:17:52 +0000 (+0100) Subject: CSpline: add thread mutex X-Git-Tag: v8.5.0-rc1~180^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f268d17864db0e9bb31d4f6bb8e907e5935a1be4;p=dealii.git CSpline: add thread mutex --- diff --git a/include/deal.II/base/function_cspline.h b/include/deal.II/base/function_cspline.h index 1653ba0fd2..0338d8f268 100644 --- a/include/deal.II/base/function_cspline.h +++ b/include/deal.II/base/function_cspline.h @@ -21,6 +21,7 @@ #ifdef DEAL_II_WITH_GSL #include #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -115,6 +116,11 @@ namespace Functions * GSL cubic spline interpolator */ gsl_spline *cspline; + + /** + * A mutex for accelerator object. + */ + mutable Threads::Mutex acc_mutex; }; } diff --git a/source/base/function_cspline.cc b/source/base/function_cspline.cc index abb8d87afc..ee8bb54fee 100644 --- a/source/base/function_cspline.cc +++ b/source/base/function_cspline.cc @@ -67,6 +67,11 @@ namespace Functions CSpline::value (const Point &p, const unsigned int) const { + // GSL functions may modify gsl_interp_accel *acc object (last argument). + // This can only work in multithreaded applications if we lock the data + // structures via a mutex. + Threads::Mutex::ScopedLock lock (acc_mutex); + const double &x = p[0]; Assert (x >= interpolation_points.front() && x <= interpolation_points.back(), ExcCSplineRange(x,interpolation_points.front(),interpolation_points.back())); @@ -81,6 +86,11 @@ namespace Functions CSpline::gradient (const Point &p, const unsigned int) const { + // GSL functions may modify gsl_interp_accel *acc object (last argument). + // This can only work in multithreaded applications if we lock the data + // structures via a mutex. + Threads::Mutex::ScopedLock lock (acc_mutex); + const double &x = p[0]; Assert (x >= interpolation_points.front() && x <= interpolation_points.back(), ExcCSplineRange(x,interpolation_points.front(),interpolation_points.back())); @@ -98,6 +108,11 @@ namespace Functions CSpline::laplacian (const Point &p, const unsigned int) const { + // GSL functions may modify gsl_interp_accel *acc object (last argument). + // This can only work in multithreaded applications if we lock the data + // structures via a mutex. + Threads::Mutex::ScopedLock lock (acc_mutex); + const double &x = p[0]; Assert (x >= interpolation_points.front() && x <= interpolation_points.back(), ExcCSplineRange(x,interpolation_points.front(),interpolation_points.back()));