Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
scoped_lock.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_core/scoped_lock.h
10 //! @brief RAII mutex lock.
11 
12 #ifndef ROC_CORE_SCOPED_LOCK_H_
13 #define ROC_CORE_SCOPED_LOCK_H_
14 
15 #include "roc_core/noncopyable.h"
16 
17 namespace roc {
18 namespace core {
19 
20 //! RAII mutex lock.
21 template <class Mutex> class ScopedLock : NonCopyable<> {
22 public:
23  //! Lock.
24  explicit ScopedLock(const Mutex& mutex)
25  : mutex_(mutex) {
26  mutex_.lock();
27  }
28 
29  //! Unlock.
31  mutex_.unlock();
32  }
33 
34 private:
35  const Mutex& mutex_;
36 };
37 
38 } // namespace core
39 } // namespace roc
40 
41 #endif // ROC_CORE_SCOPED_LOCK_H_
Mutex.
Definition: mutex.h:31
void unlock() const
Unlock mutex.
Definition: mutex.h:61
void lock() const
Lock mutex.
Definition: mutex.h:54
Base class for non-copyable objects.
Definition: noncopyable.h:23
RAII mutex lock.
Definition: scoped_lock.h:21
ScopedLock(const Mutex &mutex)
Lock.
Definition: scoped_lock.h:24
Root namespace.
Non-copyable object.