1#ifndef BOOST_SMART_PTR_DETAIL_LWM_STD_MUTEX_HPP_INCLUDED
2#define BOOST_SMART_PTR_DETAIL_LWM_STD_MUTEX_HPP_INCLUDED
3
4// Copyright 2020 Peter Dimov
5// Distributed under the Boost Software License, Version 1.0.
6// https://www.boost.org/LICENSE_1_0.txt)
7
8#include <boost/assert.hpp>
9#include <mutex>
10
11namespace boost
12{
13
14namespace detail
15{
16
17class lightweight_mutex
18{
19private:
20
21 std::mutex m_;
22
23 lightweight_mutex(lightweight_mutex const &);
24 lightweight_mutex & operator=(lightweight_mutex const &);
25
26public:
27
28 lightweight_mutex()
29 {
30 }
31
32 class scoped_lock;
33 friend class scoped_lock;
34
35 class scoped_lock
36 {
37 private:
38
39 std::mutex & m_;
40
41 scoped_lock(scoped_lock const &);
42 scoped_lock & operator=(scoped_lock const &);
43
44 public:
45
46 scoped_lock( lightweight_mutex & m ): m_( m.m_ )
47 {
48 m_.lock();
49 }
50
51 ~scoped_lock()
52 {
53 m_.unlock();
54 }
55 };
56};
57
58} // namespace detail
59
60} // namespace boost
61
62#endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_STD_MUTEX_HPP_INCLUDED
63

source code of include/boost/smart_ptr/detail/lwm_std_mutex.hpp