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