Coverage Report

Created: 2026-03-09 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boost/boost/system/detail/mutex.hpp
Line
Count
Source
1
#ifndef BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED
2
#define BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED
3
4
// Copyright 2023 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/config.hpp>
9
10
#if defined(BOOST_SYSTEM_DISABLE_THREADS)
11
12
namespace boost
13
{
14
namespace system
15
{
16
namespace detail
17
{
18
19
struct mutex
20
{
21
    void lock()
22
    {
23
    }
24
25
    void unlock()
26
    {
27
    }
28
};
29
30
} // namespace detail
31
} // namespace system
32
} // namespace boost
33
34
#else // defined(BOOST_SYSTEM_DISABLE_THREADS)
35
36
#if defined(BOOST_MSSTL_VERSION) && BOOST_MSSTL_VERSION >= 140
37
38
// Under the MS STL, std::mutex::mutex() is not constexpr, as is
39
// required by the standard, which leads to initialization order
40
// issues. However, shared_mutex is based on SRWLock and its
41
// default constructor is constexpr, so we use that instead.
42
43
#include <boost/winapi/config.hpp>
44
45
// SRWLOCK is not available when targeting Windows XP
46
#if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
47
48
#include <shared_mutex>
49
50
#if BOOST_MSSTL_VERSION >= 142 || _HAS_SHARED_MUTEX
51
# define BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX
52
#endif
53
54
#endif // BOOST_MSSTL_VERSION >= 142 || _HAS_SHARED_MUTEX
55
56
#endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
57
58
#if defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
59
60
namespace boost
61
{
62
namespace system
63
{
64
namespace detail
65
{
66
67
typedef std::shared_mutex mutex;
68
69
} // namespace detail
70
} // namespace system
71
} // namespace boost
72
73
#else // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
74
75
#include <mutex>
76
77
namespace boost
78
{
79
namespace system
80
{
81
namespace detail
82
{
83
84
using std::mutex;
85
86
} // namespace detail
87
} // namespace system
88
} // namespace boost
89
90
#endif // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
91
#endif // defined(BOOST_SYSTEM_DISABLE_THREADS)
92
93
namespace boost
94
{
95
namespace system
96
{
97
namespace detail
98
{
99
100
template<class Mtx> class lock_guard
101
{
102
private:
103
104
    Mtx& mtx_;
105
106
private:
107
108
    lock_guard( lock_guard const& );
109
    lock_guard& operator=( lock_guard const& );
110
111
public:
112
113
0
    explicit lock_guard( Mtx& mtx ): mtx_( mtx )
114
0
    {
115
0
        mtx_.lock();
116
0
    }
117
118
    ~lock_guard()
119
0
    {
120
0
        mtx_.unlock();
121
0
    }
122
};
123
124
} // namespace detail
125
} // namespace system
126
} // namespace boost
127
128
#endif // #ifndef BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED