From: Wolfgang Bangerth Date: Wed, 26 Sep 2018 20:46:05 +0000 (-0600) Subject: Make derivation of Threads::Mutex from std::mutex more obvious. X-Git-Tag: v9.1.0-rc1~686^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f8f8c1461050936070c630e6f050547252ad0b6;p=dealii.git Make derivation of Threads::Mutex from std::mutex more obvious. --- diff --git a/include/deal.II/base/thread_management.h b/include/deal.II/base/thread_management.h index 597bc5cdfe..9d7bf1bf0a 100644 --- a/include/deal.II/base/thread_management.h +++ b/include/deal.II/base/thread_management.h @@ -263,7 +263,7 @@ namespace Threads * * @author Wolfgang Bangerth, 2002, 2003, 2009 */ - class Mutex + class Mutex : public std::mutex { public: /** @@ -280,33 +280,7 @@ namespace Threads * case when you lock and unlock the mutex "by hand", i.e. using * Mutex::acquire() and Mutex::release(). */ - class ScopedLock - { - public: - /** - * Constructor. Lock the mutex. - */ - ScopedLock(Mutex &m) - : mutex(m) - { - mutex.acquire(); - } - - /** - * Destructor. Unlock the mutex. Since this is a dummy mutex class, this - * of course does nothing. - */ - ~ScopedLock() - { - mutex.release(); - } - - private: - /** - * Store the address of the mutex object. - */ - Mutex &mutex; - }; + using ScopedLock = std::lock_guard; /** * Default constructor. @@ -318,7 +292,7 @@ namespace Threads * is copied from the object given as argument. */ Mutex(const Mutex &) - : mutex() + : std::mutex() {} @@ -339,7 +313,7 @@ namespace Threads inline void acquire() { - mutex.lock(); + this->lock(); } /** @@ -348,20 +322,8 @@ namespace Threads inline void release() { - mutex.unlock(); + this->unlock(); } - - private: - /** - * Data object storing the mutex data - */ - std::mutex mutex; - - /** - * Make the class implementing condition variables a friend, since it - * needs to access the mutex. - */ - friend class ConditionVariable; }; @@ -406,7 +368,7 @@ namespace Threads inline void wait(Mutex &mutex) { - std::unique_lock lock(mutex.mutex, std::adopt_lock); + std::unique_lock lock(mutex, std::adopt_lock); condition_variable.wait(lock); }