*
* @author Wolfgang Bangerth, 2002, 2003, 2009
*/
- class Mutex
+ class Mutex : public std::mutex
{
public:
/**
* 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<std::mutex>;
/**
* Default constructor.
* is copied from the object given as argument.
*/
Mutex(const Mutex &)
- : mutex()
+ : std::mutex()
{}
inline void
acquire()
{
- mutex.lock();
+ this->lock();
}
/**
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;
};
inline void
wait(Mutex &mutex)
{
- std::unique_lock<std::mutex> lock(mutex.mutex, std::adopt_lock);
+ std::unique_lock<std::mutex> lock(mutex, std::adopt_lock);
condition_variable.wait(lock);
}