From: Wolfgang Bangerth Date: Thu, 27 Sep 2018 13:30:22 +0000 (-0600) Subject: Replace uses of Threads::Mutex::ScopedLock by std::lock_guard. X-Git-Tag: v9.1.0-rc1~678^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0d815cf4f6df9b7b8bb2b33ef22b7e5f892d395;p=dealii.git Replace uses of Threads::Mutex::ScopedLock by std::lock_guard. --- diff --git a/include/deal.II/base/logstream.h b/include/deal.II/base/logstream.h index ed62db3590..bdff40fa32 100644 --- a/include/deal.II/base/logstream.h +++ b/include/deal.II/base/logstream.h @@ -97,7 +97,7 @@ public: * throw, or by simply reaching the closing brace. In all of * these cases, it is not necessary to remember to pop the prefix manually * using LogStream::pop(). In this, it works just like the better known - * std::unique_ptr and Threads::Mutex::ScopedLock classes. + * std::unique_ptr and std::lock_guard classes. */ class Prefix { diff --git a/include/deal.II/fe/fe_tools.templates.h b/include/deal.II/fe/fe_tools.templates.h index fd3c7a0bc7..c741bc0c24 100644 --- a/include/deal.II/fe/fe_tools.templates.h +++ b/include/deal.II/fe/fe_tools.templates.h @@ -2409,7 +2409,7 @@ namespace FETools // operation of this function; // for this, acquire the lock // until we quit this function - Threads::Mutex::ScopedLock lock( + std::lock_guard lock( internal::FEToolsAddFENameHelper::fe_name_map_lock); Assert( @@ -2566,7 +2566,7 @@ namespace FETools { // Make sure no other thread // is just adding an element - Threads::Mutex::ScopedLock lock( + std::lock_guard lock( internal::FEToolsAddFENameHelper::fe_name_map_lock); AssertThrow(fe_name_map.find(name_part) != fe_name_map.end(), FETools::ExcInvalidFEName(name)); diff --git a/include/deal.II/lac/block_matrix_base.h b/include/deal.II/lac/block_matrix_base.h index a12cec0ddc..13c9b4a335 100644 --- a/include/deal.II/lac/block_matrix_base.h +++ b/include/deal.II/lac/block_matrix_base.h @@ -1724,7 +1724,7 @@ BlockMatrixBase::set(const size_type row, // lock access to the temporary data structure to // allow multiple threads to call this function concurrently - Threads::Mutex::ScopedLock lock(temporary_data.mutex); + std::lock_guard lock(temporary_data.mutex); // Resize scratch arrays if (temporary_data.column_indices.size() < this->n_block_cols()) @@ -1981,7 +1981,7 @@ BlockMatrixBase::add(const size_type row, } // Lock scratch arrays, then resize them - Threads::Mutex::ScopedLock lock(temporary_data.mutex); + std::lock_guard lock(temporary_data.mutex); if (temporary_data.column_indices.size() < this->n_block_cols()) { diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index 6b297418e2..f008b8ce53 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -875,7 +875,7 @@ namespace LinearAlgebra #ifdef DEAL_II_WITH_MPI // make this function thread safe - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); // allocate import_data in case it is not set up yet if (import_data == nullptr && partitioner->n_import_indices() > 0) @@ -928,7 +928,7 @@ namespace LinearAlgebra // compress_requests.size() == 0 // make this function thread safe - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); Assert(partitioner->n_import_indices() == 0 || import_data != nullptr, ExcNotInitialized()); @@ -975,7 +975,7 @@ namespace LinearAlgebra return; // make this function thread safe - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); // allocate import_data in case it is not set up yet if (import_data == nullptr && partitioner->n_import_indices() > 0) @@ -1033,7 +1033,7 @@ namespace LinearAlgebra if (update_ghost_values_requests.size() > 0) { // make this function thread safe - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); partitioner->export_to_ghosted_array_finish( ArrayView(data.values.get() + partitioner->local_size(), diff --git a/include/deal.II/lac/precondition.h b/include/deal.II/lac/precondition.h index 96f2e06aef..45bdb20c13 100644 --- a/include/deal.II/lac/precondition.h +++ b/include/deal.II/lac/precondition.h @@ -2308,7 +2308,7 @@ PreconditionChebyshev::vmult( VectorType & dst, const VectorType &src) const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (eigenvalues_are_initialized == false) estimate_eigenvalues(src); @@ -2334,7 +2334,7 @@ PreconditionChebyshev::Tvmult( VectorType & dst, const VectorType &src) const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (eigenvalues_are_initialized == false) estimate_eigenvalues(src); @@ -2360,7 +2360,7 @@ PreconditionChebyshev::step( VectorType & dst, const VectorType &src) const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (eigenvalues_are_initialized == false) estimate_eigenvalues(src); @@ -2387,7 +2387,7 @@ PreconditionChebyshev::Tstep( VectorType & dst, const VectorType &src) const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (eigenvalues_are_initialized == false) estimate_eigenvalues(src); diff --git a/include/deal.II/lac/swappable_vector.templates.h b/include/deal.II/lac/swappable_vector.templates.h index 5b109df84a..bd0bed8414 100644 --- a/include/deal.II/lac/swappable_vector.templates.h +++ b/include/deal.II/lac/swappable_vector.templates.h @@ -78,7 +78,7 @@ SwappableVector::operator=(const SwappableVector &v) // if in MT mode, block all other // operations. if not in MT mode, // this is a no-op - Threads::Mutex::ScopedLock lock(this->lock); + std::lock_guard lock(this->lock); Vector::operator=(v); data_is_preloaded = false; @@ -107,7 +107,7 @@ SwappableVector::swap_out(const std::string &name) // if in MT mode, block all other // operations. if not in MT mode, // this is a no-op - Threads::Mutex::ScopedLock lock(this->lock); + std::lock_guard lock(this->lock); // check that we have not called // @p alert without the respective @@ -225,7 +225,7 @@ SwappableVector::kill_file() // (there should be none, but who // knows). if not in MT mode, // this is a no-op - Threads::Mutex::ScopedLock lock(this->lock); + std::lock_guard lock(this->lock); // this is too bad: someone // requested the vector in advance, diff --git a/include/deal.II/lac/tensor_product_matrix.h b/include/deal.II/lac/tensor_product_matrix.h index 3a86de7c08..53fcb039f1 100644 --- a/include/deal.II/lac/tensor_product_matrix.h +++ b/include/deal.II/lac/tensor_product_matrix.h @@ -477,8 +477,8 @@ TensorProductMatrixSymmetricSumBase::vmult( { AssertDimension(dst_view.size(), this->m()); AssertDimension(src_view.size(), this->n()); - Threads::Mutex::ScopedLock lock(this->mutex); - const unsigned int n = + std::lock_guard lock(this->mutex); + const unsigned int n = Utilities::fixed_power(size > 0 ? size : eigenvalues[0].size()); tmp_array.resize_fast(n * 2); constexpr int kernel_size = size > 0 ? size : 0; @@ -545,8 +545,8 @@ TensorProductMatrixSymmetricSumBase::apply_inverse( { AssertDimension(dst_view.size(), this->n()); AssertDimension(src_view.size(), this->m()); - Threads::Mutex::ScopedLock lock(this->mutex); - const unsigned int n = size > 0 ? size : eigenvalues[0].size(); + std::lock_guard lock(this->mutex); + const unsigned int n = size > 0 ? size : eigenvalues[0].size(); tmp_array.resize_fast(Utilities::fixed_power(n)); constexpr int kernel_size = size > 0 ? size : 0; internal::EvaluatorTensorProduct::GrowingVectorMemory( , current_alloc(0) , log_statistics(log_statistics) { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); pool.initialize(initial_size); } @@ -106,7 +106,7 @@ template inline VectorType * GrowingVectorMemory::alloc() { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); ++total_alloc; ++current_alloc; @@ -136,7 +136,7 @@ template inline void GrowingVectorMemory::free(const VectorType *const v) { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (typename std::vector::iterator i = pool.data->begin(); i != pool.data->end(); @@ -158,7 +158,7 @@ template inline void GrowingVectorMemory::release_unused_memory() { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (pool.data != nullptr) pool.data->clear(); @@ -170,7 +170,7 @@ template inline std::size_t GrowingVectorMemory::memory_consumption() const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); std::size_t result = sizeof(*this); const typename std::vector::const_iterator end = pool.data->end(); diff --git a/include/deal.II/matrix_free/dof_info.templates.h b/include/deal.II/matrix_free/dof_info.templates.h index b46c0e91e4..a3400b2b50 100644 --- a/include/deal.II/matrix_free/dof_info.templates.h +++ b/include/deal.II/matrix_free/dof_info.templates.h @@ -1313,7 +1313,7 @@ namespace internal // that are within the range of one lock at once const unsigned int next_bucket = (*it / bucket_size_threading + 1) * bucket_size_threading; - Threads::Mutex::ScopedLock lock( + std::lock_guard lock( mutexes[*it / bucket_size_threading]); for (; it != end_unique && *it < next_bucket; ++it) { @@ -1351,7 +1351,7 @@ namespace internal { const unsigned int next_bucket = (*it / bucket_size_threading + 1) * bucket_size_threading; - Threads::Mutex::ScopedLock lock( + std::lock_guard lock( mutexes[*it / bucket_size_threading]); for (; it != end_unique && *it < next_bucket; ++it) if (row_lengths[*it] > 0) diff --git a/source/base/flow_function.cc b/source/base/flow_function.cc index 0e192f005d..8dae6dc072 100644 --- a/source/base/flow_function.cc +++ b/source/base/flow_function.cc @@ -57,7 +57,7 @@ namespace Functions // guard access to the aux_* // variables in multithread mode - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int d = 0; d < dim + 1; ++d) aux_values[d].resize(n_points); @@ -87,7 +87,7 @@ namespace Functions // guard access to the aux_* // variables in multithread mode - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int d = 0; d < dim + 1; ++d) aux_values[d].resize(n_points); @@ -110,7 +110,7 @@ namespace Functions // guard access to the aux_* // variables in multithread mode - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int d = 0; d < dim + 1; ++d) aux_values[d].resize(n_points); @@ -132,7 +132,7 @@ namespace Functions // guard access to the aux_* // variables in multithread mode - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int d = 0; d < dim + 1; ++d) aux_gradients[d].resize(n_points); @@ -160,7 +160,7 @@ namespace Functions // guard access to the aux_* // variables in multithread mode - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int d = 0; d < dim + 1; ++d) aux_values[d].resize(n_points); diff --git a/source/base/function_cspline.cc b/source/base/function_cspline.cc index 3391d9b2d2..cdc9972c49 100644 --- a/source/base/function_cspline.cc +++ b/source/base/function_cspline.cc @@ -73,7 +73,7 @@ namespace Functions // 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); + std::lock_guard lock(acc_mutex); const double x = p[0]; Assert(x >= interpolation_points.front() && @@ -94,7 +94,7 @@ namespace Functions // 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); + std::lock_guard lock(acc_mutex); const double x = p[0]; Assert(x >= interpolation_points.front() && @@ -118,7 +118,7 @@ namespace Functions // 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); + std::lock_guard lock(acc_mutex); const double x = p[0]; Assert(x >= interpolation_points.front() && diff --git a/source/base/function_parser.cc b/source/base/function_parser.cc index 24a63b19d5..769c681851 100644 --- a/source/base/function_parser.cc +++ b/source/base/function_parser.cc @@ -241,8 +241,8 @@ namespace internal double mu_rand_seed(double seed) { - static Threads::Mutex rand_mutex; - Threads::Mutex::ScopedLock lock(rand_mutex); + static Threads::Mutex rand_mutex; + std::lock_guard lock(rand_mutex); static boost::random::uniform_real_distribution<> uniform_distribution(0, 1); @@ -262,7 +262,7 @@ namespace internal mu_rand() { static Threads::Mutex rand_mutex; - Threads::Mutex::ScopedLock lock(rand_mutex); + std::lock_guard lock(rand_mutex); static boost::random::uniform_real_distribution<> uniform_distribution(0, 1); static boost::random::mt19937 rng( diff --git a/source/base/index_set.cc b/source/base/index_set.cc index 9b5fa12d27..5a491e5f7a 100644 --- a/source/base/index_set.cc +++ b/source/base/index_set.cc @@ -129,7 +129,7 @@ IndexSet::do_compress() const // via a mutex, so that users can call 'const' functions from threads // in parallel (and these 'const' functions can then call compress() // which itself calls the current function) - Threads::Mutex::ScopedLock lock(compress_mutex); + std::lock_guard lock(compress_mutex); // see if any of the contiguous ranges can be merged. do not use // std::vector::erase in-place as it is quadratic in the number of diff --git a/source/base/logstream.cc b/source/base/logstream.cc index ccdb9a4ab0..c1c97a3379 100644 --- a/source/base/logstream.cc +++ b/source/base/logstream.cc @@ -191,7 +191,7 @@ LogStream::operator<<(std::ostream &(*p)(std::ostream &)) if (query_streambuf.flushed()) { - Threads::Mutex::ScopedLock lock(write_lock); + std::lock_guard lock(write_lock); // Print the line head in case of a previous newline: if (at_newline) @@ -218,7 +218,7 @@ LogStream::attach(std::ostream & o, const bool print_job_id, const std::ios_base::fmtflags flags) { - Threads::Mutex::ScopedLock lock(log_lock); + std::lock_guard lock(log_lock); file = &o; o.setf(flags); if (print_job_id) @@ -229,7 +229,7 @@ LogStream::attach(std::ostream & o, void LogStream::detach() { - Threads::Mutex::ScopedLock lock(log_lock); + std::lock_guard lock(log_lock); file = nullptr; } @@ -347,9 +347,9 @@ LogStream::width(const std::streamsize wide) unsigned int LogStream::depth_console(const unsigned int n) { - Threads::Mutex::ScopedLock lock(log_lock); - const unsigned int h = std_depth; - std_depth = n; + std::lock_guard lock(log_lock); + const unsigned int h = std_depth; + std_depth = n; return h; } @@ -358,9 +358,9 @@ LogStream::depth_console(const unsigned int n) unsigned int LogStream::depth_file(const unsigned int n) { - Threads::Mutex::ScopedLock lock(log_lock); - const unsigned int h = file_depth; - file_depth = n; + std::lock_guard lock(log_lock); + const unsigned int h = file_depth; + file_depth = n; return h; } @@ -369,9 +369,9 @@ LogStream::depth_file(const unsigned int n) bool LogStream::log_thread_id(const bool flag) { - Threads::Mutex::ScopedLock lock(log_lock); - const bool h = print_thread_id; - print_thread_id = flag; + std::lock_guard lock(log_lock); + const bool h = print_thread_id; + print_thread_id = flag; return h; } diff --git a/source/base/parallel.cc b/source/base/parallel.cc index e448c07b6a..da998a6fe6 100644 --- a/source/base/parallel.cc +++ b/source/base/parallel.cc @@ -74,7 +74,7 @@ namespace parallel std::shared_ptr TBBPartitioner::acquire_one_partitioner() { - dealii::Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (in_use) return std::make_shared(); @@ -90,7 +90,7 @@ namespace parallel { if (p.get() == my_partitioner.get()) { - dealii::Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); in_use = false; } } diff --git a/source/base/polynomial.cc b/source/base/polynomial.cc index eca63433ca..8a9cbc1131 100644 --- a/source/base/polynomial.cc +++ b/source/base/polynomial.cc @@ -1006,7 +1006,7 @@ namespace Polynomials // of this function // for this, acquire the lock // until we quit this function - Threads::Mutex::ScopedLock lock(coefficients_lock); + std::lock_guard lock(coefficients_lock); // The first 2 coefficients // are hard-coded @@ -1140,7 +1140,7 @@ namespace Polynomials // then get a pointer to the array // of coefficients. do that in a MT // safe way - Threads::Mutex::ScopedLock lock(coefficients_lock); + std::lock_guard lock(coefficients_lock); return *recursive_coefficients[k]; } diff --git a/source/base/polynomials_abf.cc b/source/base/polynomials_abf.cc index e52d5001b6..b8ca149a93 100644 --- a/source/base/polynomials_abf.cc +++ b/source/base/polynomials_abf.cc @@ -86,7 +86,7 @@ PolynomialsABF::compute( // using a mutex to make sure they // are not used by multiple threads // at once - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); p_values.resize((values.size() == 0) ? 0 : n_sub); p_grads.resize((grads.size() == 0) ? 0 : n_sub); diff --git a/source/base/polynomials_bdm.cc b/source/base/polynomials_bdm.cc index bb14979d3b..51491c0a0b 100644 --- a/source/base/polynomials_bdm.cc +++ b/source/base/polynomials_bdm.cc @@ -85,7 +85,7 @@ PolynomialsBDM::compute( // are not used by multiple threads // at once { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); p_values.resize((values.size() == 0) ? 0 : n_sub); p_grads.resize((grads.size() == 0) ? 0 : n_sub); diff --git a/source/base/polynomials_raviart_thomas.cc b/source/base/polynomials_raviart_thomas.cc index 6b4bd50a82..8bf74e9881 100644 --- a/source/base/polynomials_raviart_thomas.cc +++ b/source/base/polynomials_raviart_thomas.cc @@ -93,8 +93,8 @@ PolynomialsRaviartThomas::compute( // deal.II/create_mass_matrix_05) // will start to produce random // results in multithread mode - static Threads::Mutex mutex; - Threads::Mutex::ScopedLock lock(mutex); + static Threads::Mutex mutex; + std::lock_guard lock(mutex); static std::vector p_values; static std::vector> p_grads; diff --git a/source/base/polynomials_rt_bubbles.cc b/source/base/polynomials_rt_bubbles.cc index b79ef3ee3e..117d244723 100644 --- a/source/base/polynomials_rt_bubbles.cc +++ b/source/base/polynomials_rt_bubbles.cc @@ -73,8 +73,8 @@ PolynomialsRT_Bubbles::compute( // using a mutex to make sure they are not used by multiple threads // at once { - static Threads::Mutex mutex; - Threads::Mutex::ScopedLock lock(mutex); + static Threads::Mutex mutex; + std::lock_guard lock(mutex); static std::vector> p_values; static std::vector> p_grads; diff --git a/source/base/timer.cc b/source/base/timer.cc index 007f9dd017..e2a1fba761 100644 --- a/source/base/timer.cc +++ b/source/base/timer.cc @@ -412,7 +412,7 @@ TimerOutput::~TimerOutput() void TimerOutput::enter_subsection(const std::string §ion_name) { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); Assert(section_name.empty() == false, ExcMessage("Section string is empty.")); @@ -457,7 +457,7 @@ TimerOutput::leave_subsection(const std::string §ion_name) Assert(!active_sections.empty(), ExcMessage("Cannot exit any section because none has been entered!")); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (section_name != "") { @@ -873,7 +873,7 @@ TimerOutput::enable_output() void TimerOutput::reset() { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); sections.clear(); active_sections.clear(); timer_all.restart(); diff --git a/source/fe/fe_dgq.cc b/source/fe/fe_dgq.cc index 65bbd6f8d3..439fb5d7b5 100644 --- a/source/fe/fe_dgq.cc +++ b/source/fe/fe_dgq.cc @@ -408,7 +408,7 @@ FE_DGQ::get_prolongation_matrix( // initialization upon first request if (this->prolongation[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); // if matrix got updated while waiting for the lock if (this->prolongation[refinement_case - 1][child].n() == @@ -488,7 +488,7 @@ FE_DGQ::get_restriction_matrix( // initialization upon first request if (this->restriction[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); // if matrix got updated while waiting for the lock... if (this->restriction[refinement_case - 1][child].n() == diff --git a/source/fe/fe_nedelec.cc b/source/fe/fe_nedelec.cc index 06139b146b..51f5fe7515 100644 --- a/source/fe/fe_nedelec.cc +++ b/source/fe/fe_nedelec.cc @@ -2985,7 +2985,7 @@ FE_Nedelec::get_prolongation_matrix( // initialization upon first request if (this->prolongation[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); // if matrix got updated while waiting for the lock if (this->prolongation[refinement_case - 1][child].n() == @@ -3047,7 +3047,7 @@ FE_Nedelec::get_restriction_matrix( // initialization upon first request if (this->restriction[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); // if matrix got updated while waiting for the lock... if (this->restriction[refinement_case - 1][child].n() == diff --git a/source/fe/fe_poly_tensor.cc b/source/fe/fe_poly_tensor.cc index ae9506d861..2dc68bc749 100644 --- a/source/fe/fe_poly_tensor.cc +++ b/source/fe/fe_poly_tensor.cc @@ -201,7 +201,7 @@ FE_PolyTensor::shape_value_component( Assert(i < this->dofs_per_cell, ExcIndexRange(i, 0, this->dofs_per_cell)); Assert(component < dim, ExcIndexRange(component, 0, dim)); - Threads::Mutex::ScopedLock lock(cache_mutex); + std::lock_guard lock(cache_mutex); if (cached_point != p || cached_values.size() == 0) { @@ -247,7 +247,7 @@ FE_PolyTensor::shape_grad_component( Assert(i < this->dofs_per_cell, ExcIndexRange(i, 0, this->dofs_per_cell)); Assert(component < dim, ExcIndexRange(component, 0, dim)); - Threads::Mutex::ScopedLock lock(cache_mutex); + std::lock_guard lock(cache_mutex); if (cached_point != p || cached_grads.size() == 0) { @@ -294,7 +294,7 @@ FE_PolyTensor::shape_grad_grad_component( Assert(i < this->dofs_per_cell, ExcIndexRange(i, 0, this->dofs_per_cell)); Assert(component < dim, ExcIndexRange(component, 0, dim)); - Threads::Mutex::ScopedLock lock(cache_mutex); + std::lock_guard lock(cache_mutex); if (cached_point != p || cached_grad_grads.size() == 0) { diff --git a/source/fe/fe_q_base.cc b/source/fe/fe_q_base.cc index 93590f38f0..fd4f429c22 100644 --- a/source/fe/fe_q_base.cc +++ b/source/fe/fe_q_base.cc @@ -1232,7 +1232,7 @@ FE_Q_Base::get_prolongation_matrix( // initialization upon first request if (this->prolongation[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); // if matrix got updated while waiting for the lock if (this->prolongation[refinement_case - 1][child].n() == @@ -1434,7 +1434,7 @@ FE_Q_Base::get_restriction_matrix( // initialization upon first request if (this->restriction[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); // if matrix got updated while waiting for the lock... if (this->restriction[refinement_case - 1][child].n() == diff --git a/source/fe/fe_system.cc b/source/fe/fe_system.cc index ee31a18fdd..89f88c634f 100644 --- a/source/fe/fe_system.cc +++ b/source/fe/fe_system.cc @@ -718,7 +718,7 @@ FESystem::get_restriction_matrix( // initialization upon first request if (this->restriction[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); // check if updated while waiting for lock if (this->restriction[refinement_case - 1][child].n() == @@ -815,7 +815,7 @@ FESystem::get_prolongation_matrix( // restriction matrix if (this->prolongation[refinement_case - 1][child].n() == 0) { - Threads::Mutex::ScopedLock lock(this->mutex); + std::lock_guard lock(this->mutex); if (this->prolongation[refinement_case - 1][child].n() == this->dofs_per_cell) diff --git a/source/fe/mapping_fe_field.cc b/source/fe/mapping_fe_field.cc index a342cd06c9..5289c9d1e7 100644 --- a/source/fe/mapping_fe_field.cc +++ b/source/fe/mapping_fe_field.cc @@ -321,7 +321,7 @@ MappingFEField::get_vertices( euler_dof_handler->get_fe().n_components())); { - Threads::Mutex::ScopedLock lock(fe_values_mutex); + std::lock_guard lock(fe_values_mutex); fe_values.reinit(dof_cell); fe_values.get_function_values(*euler_vector, values); } diff --git a/source/fe/mapping_q_eulerian.cc b/source/fe/mapping_q_eulerian.cc index c95ebb6981..e4bd088f83 100644 --- a/source/fe/mapping_q_eulerian.cc +++ b/source/fe/mapping_q_eulerian.cc @@ -221,7 +221,7 @@ MappingQEulerian::MappingQEulerianGeneric:: // fill shift vector for each support point using an fe_values object. make // sure that the fe_values variable isn't used simultaneously from different // threads - Threads::Mutex::ScopedLock lock(fe_values_mutex); + std::lock_guard lock(fe_values_mutex); fe_values.reinit(dof_cell); if (mg_vector) { diff --git a/source/lac/lapack_full_matrix.cc b/source/lac/lapack_full_matrix.cc index a516bddb57..e075424f79 100644 --- a/source/lac/lapack_full_matrix.cc +++ b/source/lac/lapack_full_matrix.cc @@ -670,7 +670,7 @@ LAPACKFullMatrix::vmult(Vector & w, } case svd: { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); AssertDimension(v.size(), this->n()); AssertDimension(w.size(), this->m()); // Compute V^T v @@ -705,7 +705,7 @@ LAPACKFullMatrix::vmult(Vector & w, } case inverse_svd: { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); AssertDimension(w.size(), this->n()); AssertDimension(v.size(), this->m()); // Compute U^T v @@ -805,7 +805,7 @@ LAPACKFullMatrix::Tvmult(Vector & w, } case svd: { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); AssertDimension(w.size(), this->n()); AssertDimension(v.size(), this->m()); @@ -841,7 +841,7 @@ LAPACKFullMatrix::Tvmult(Vector & w, } case inverse_svd: { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); AssertDimension(v.size(), this->n()); AssertDimension(w.size(), this->m()); @@ -996,7 +996,7 @@ LAPACKFullMatrix::Tmmult(LAPACKFullMatrix & C, // https://stackoverflow.com/questions/3548069/multiplying-three-matrices-in-blas-with-the-middle-one-being-diagonal // http://mathforum.org/kb/message.jspa?messageID=3546564 - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); // First, get V*B into "work" array work.resize(kk * nn); // following http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=2&t=768#p2577 @@ -1369,7 +1369,7 @@ template number LAPACKFullMatrix::norm(const char type) const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); Assert(state == LAPACKSupport::matrix || state == LAPACKSupport::inverse_matrix, @@ -1447,7 +1447,7 @@ template number LAPACKFullMatrix::reciprocal_condition_number(const number a_norm) const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); Assert(state == cholesky, ExcState(state)); number rcond = 0.; @@ -1480,7 +1480,7 @@ template number LAPACKFullMatrix::reciprocal_condition_number() const { - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); Assert(property == upper_triangular || property == lower_triangular, ExcProperty(property)); number rcond = 0.; diff --git a/source/lac/scalapack.cc b/source/lac/scalapack.cc index 4923436c53..8067646a20 100644 --- a/source/lac/scalapack.cc +++ b/source/lac/scalapack.cc @@ -1388,7 +1388,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric( Assert(property == LAPACKSupport::symmetric, ExcMessage("Matrix has to be symmetric for this operation.")); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); const bool use_values = (std::isnan(eigenvalue_limits.first) || std::isnan(eigenvalue_limits.second)) ? @@ -1719,7 +1719,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric_MRRR( Assert(property == LAPACKSupport::symmetric, ExcMessage("Matrix has to be symmetric for this operation.")); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); const bool use_values = (std::isnan(eigenvalue_limits.first) || std::isnan(eigenvalue_limits.second)) ? @@ -1956,7 +1956,7 @@ ScaLAPACKMatrix::compute_SVD(ScaLAPACKMatrix *U, ExcDimensionMismatch(grid->blacs_context, VT->grid->blacs_context)); } - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); std::vector sv(std::min(n_rows, n_columns)); @@ -2071,7 +2071,7 @@ ScaLAPACKMatrix::least_squares(ScaLAPACKMatrix &B, ExcMessage( "Use identical block-cyclic distribution for matrices A and B")); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); if (grid->mpi_process_is_active) { @@ -2223,8 +2223,8 @@ ScaLAPACKMatrix::reciprocal_condition_number( Assert(state == LAPACKSupport::cholesky, ExcMessage( "Matrix has to be in Cholesky state before calling this function.")); - Threads::Mutex::ScopedLock lock(mutex); - NumberType rcond = 0.; + std::lock_guard lock(mutex); + NumberType rcond = 0.; if (grid->mpi_process_is_active) { @@ -2326,8 +2326,8 @@ ScaLAPACKMatrix::norm_general(const char type) const Assert(state == LAPACKSupport::matrix || state == LAPACKSupport::inverse_matrix, ExcMessage("norms can be called in matrix state only.")); - Threads::Mutex::ScopedLock lock(mutex); - NumberType res = 0.; + std::lock_guard lock(mutex); + NumberType res = 0.; if (grid->mpi_process_is_active) { @@ -2387,8 +2387,8 @@ ScaLAPACKMatrix::norm_symmetric(const char type) const ExcMessage("norms can be called in matrix state only.")); Assert(property == LAPACKSupport::symmetric, ExcMessage("Matrix has to be symmetric for this operation.")); - Threads::Mutex::ScopedLock lock(mutex); - NumberType res = 0.; + std::lock_guard lock(mutex); + NumberType res = 0.; if (grid->mpi_process_is_active) { diff --git a/tests/base/thread_local_storage_01.cc b/tests/base/thread_local_storage_01.cc index 706dad4d6a..a02ca2250b 100644 --- a/tests/base/thread_local_storage_01.cc +++ b/tests/base/thread_local_storage_01.cc @@ -50,7 +50,7 @@ execute(int i) // accessed static Threads::Mutex m; { - Threads::Mutex::ScopedLock l(m); + std::lock_guard l(m); ++counter; } diff --git a/tests/base/thread_local_storage_02.cc b/tests/base/thread_local_storage_02.cc index d0c6b02115..c8e15e42c7 100644 --- a/tests/base/thread_local_storage_02.cc +++ b/tests/base/thread_local_storage_02.cc @@ -60,7 +60,7 @@ execute(int i) // accessed static Threads::Mutex m; { - Threads::Mutex::ScopedLock l(m); + std::lock_guard l(m); ++counter; } diff --git a/tests/bits/step-13.cc b/tests/bits/step-13.cc index 530325a04b..13ec25e21f 100644 --- a/tests/bits/step-13.cc +++ b/tests/bits/step-13.cc @@ -430,7 +430,7 @@ namespace LaplaceSolver cell->get_dof_indices(local_dof_indices); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int i = 0; i < dofs_per_cell; ++i) for (unsigned int j = 0; j < dofs_per_cell; ++j) linear_system.matrix.add(local_dof_indices[i], diff --git a/tests/bits/step-14.cc b/tests/bits/step-14.cc index 4c623a2858..e203697ea8 100644 --- a/tests/bits/step-14.cc +++ b/tests/bits/step-14.cc @@ -512,7 +512,7 @@ namespace LaplaceSolver cell->get_dof_indices(local_dof_indices); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int i = 0; i < dofs_per_cell; ++i) for (unsigned int j = 0; j < dofs_per_cell; ++j) linear_system.matrix.add(local_dof_indices[i], diff --git a/tests/fail/hp-step-14.cc b/tests/fail/hp-step-14.cc index d630eedaf8..dc11a422be 100644 --- a/tests/fail/hp-step-14.cc +++ b/tests/fail/hp-step-14.cc @@ -517,7 +517,7 @@ namespace LaplaceSolver cell->get_dof_indices(local_dof_indices); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int i = 0; i < dofs_per_cell; ++i) for (unsigned int j = 0; j < dofs_per_cell; ++j) linear_system.matrix.add(local_dof_indices[i], diff --git a/tests/hp/step-13.cc b/tests/hp/step-13.cc index 1528c835ec..6204be258e 100644 --- a/tests/hp/step-13.cc +++ b/tests/hp/step-13.cc @@ -429,7 +429,7 @@ namespace LaplaceSolver cell->get_dof_indices(local_dof_indices); - Threads::Mutex::ScopedLock lock(mutex); + std::lock_guard lock(mutex); for (unsigned int i = 0; i < dofs_per_cell; ++i) for (unsigned int j = 0; j < dofs_per_cell; ++j) linear_system.matrix.add(local_dof_indices[i], diff --git a/tests/numerics/time_dependent_01.cc b/tests/numerics/time_dependent_01.cc index 2c2903e6a4..e5c8f6ab8f 100644 --- a/tests/numerics/time_dependent_01.cc +++ b/tests/numerics/time_dependent_01.cc @@ -39,8 +39,8 @@ public: virtual void end_sweep() { - static Threads::Mutex mutex; - Threads::Mutex::ScopedLock lock(mutex); + static Threads::Mutex mutex; + std::lock_guard lock(mutex); end_sweep_flags[time_step_number] = true; }