File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed
includes/standard-library
rules/donotdestroyamutexwhileitislocked Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ constexpr try_to_lock_t try_to_lock{};
23
23
class mutex {
24
24
public:
25
25
constexpr mutex () noexcept ;
26
- ~mutex ();
26
+ ~mutex () = default ;
27
27
mutex (const mutex &) = delete ;
28
28
mutex &operator =(const mutex &) = delete ;
29
29
void lock ();
@@ -62,15 +62,19 @@ template <class Mutex>
62
62
void swap (unique_lock<Mutex> &x, unique_lock<Mutex> &y) noexcept ;
63
63
64
64
template <class _Lock0 , class _Lock1 , class ... _LockN>
65
- void lock (_Lock0 &_Lk0, _Lock1 &_Lk1, _LockN &..._LkN) { }
65
+ void lock (_Lock0 &_Lk0, _Lock1 &_Lk1, _LockN &..._LkN) {}
66
66
67
67
template <typename Mutex> class lock_guard {
68
68
public:
69
69
typedef Mutex mutex_type;
70
70
71
- explicit lock_guard (mutex_type &__m);
71
+ explicit lock_guard (mutex_type &__m) : _m(__m) { _m. lock (); }
72
72
lock_guard (const lock_guard &) = delete ;
73
73
lock_guard &operator =(const lock_guard &) = delete ;
74
+ ~lock_guard () { _m.unlock (); }
75
+
76
+ private:
77
+ mutex_type &_m;
74
78
};
75
79
76
80
} // namespace std
Original file line number Diff line number Diff line change 1
- | test.cpp:4:18:4:33 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:11:18:11:26 | call to ~mutex | destroyed |
2
1
| test.cpp:4:18:4:33 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:11:18:11:26 | delete | destroyed |
3
- | test.cpp:16:14:16:15 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:21:1:21:1 | call to ~mutex | destroyed |
4
2
| test.cpp:16:14:16:15 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:21:1:21:1 | return ... | destroyed |
5
- | test.cpp:94:8:94:23 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:10:34:10:42 | call to ~mutex | destroyed |
6
3
| test.cpp:94:8:94:23 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:10:34:10:42 | delete | destroyed |
You can’t perform that action at this time.
0 commit comments