diff options
author | Max Kellermann <max@musicpd.org> | 2016-12-29 11:51:25 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2016-12-29 11:51:25 +0100 |
commit | 9c11184238842257ad5bed5d7928a55b3418ff98 (patch) | |
tree | 15a8a32ec566647e7d29ade9a51e0cfcac4eb932 /src/thread | |
parent | a421c1dbfbf42701e20be7ce1041329bdd12d8d5 (diff) |
thread/Mutex: use std::unique_lock to implement ScopeLock
Diffstat (limited to 'src/thread')
-rw-r--r-- | src/thread/Mutex.hxx | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/thread/Mutex.hxx b/src/thread/Mutex.hxx index 7e4e0fd2e..2f507f65d 100644 --- a/src/thread/Mutex.hxx +++ b/src/thread/Mutex.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 Max Kellermann <max@duempel.org> + * Copyright (C) 2009-2016 Max Kellermann <max@duempel.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,6 +30,8 @@ #ifndef THREAD_MUTEX_HXX #define THREAD_MUTEX_HXX +#include <mutex> + #ifdef WIN32 #include "CriticalSection.hxx" @@ -43,26 +45,13 @@ class Mutex : public PosixMutex {}; #endif class ScopeLock { - Mutex &mutex; - - bool active = true; + std::unique_lock<Mutex> lock; public: - ScopeLock(Mutex &_mutex):mutex(_mutex) { - mutex.lock(); - }; - - ~ScopeLock() { - if (active) - mutex.unlock(); - }; - - ScopeLock(const ScopeLock &other) = delete; - ScopeLock &operator=(const ScopeLock &other) = delete; + ScopeLock(Mutex &_mutex):lock(_mutex) {} void Unlock() { - mutex.unlock(); - active = false; + lock.unlock(); } }; |