@@ -81,7 +81,31 @@ namespace mamba::util
81
81
return std::shared_lock{ mutex };
82
82
}
83
83
84
- /* * Locks a mutex object using an exclusive lock available for that mutex type.
84
+ /* * Locks multiple mutex objects using the most constrained sharing lock available for that
85
+ mutex type.
86
+ @returns A tuple of scoped locking objects, one for each mutex. The exact types depends on the
87
+ mutex types.
88
+ */
89
+ template <Mutex... M>
90
+ requires (sizeof ...(M) > 1 )
91
+ [[nodiscard]]
92
+ auto lock_as_readonly (M&... mutex)
93
+ {
94
+ return std::make_tuple (lock_as_readonly (mutex)...);
95
+ }
96
+
97
+ /* * Locks multiple non-shared mutex objects using the most constrained sharing lock available
98
+ for that mutex type.
99
+ @returns A scoped locking object.
100
+ */
101
+ template <Mutex... M>
102
+ requires (sizeof ...(M) > 1 ) and ((not SharedMutex<M>) and ...)
103
+ [[nodiscard]] auto lock_as_readonly (M&... mutex)
104
+ {
105
+ return std::scoped_lock{ mutex... };
106
+ }
107
+
108
+ /* * Locks a mutex object using an exclusive lock.
85
109
@returns A scoped locking object.
86
110
*/
87
111
template <Mutex M>
@@ -91,6 +115,9 @@ namespace mamba::util
91
115
return std::unique_lock{ mutex };
92
116
}
93
117
118
+ /* * Locks multiple mutex objects using an exclusive lock.
119
+ @returns A scoped locking object.
120
+ */
94
121
template <Mutex... M>
95
122
requires (sizeof ...(M) > 1 )
96
123
[[nodiscard]]
@@ -487,7 +514,7 @@ namespace mamba::util
487
514
template <std::default_initializable T, Mutex M>
488
515
synchronized_value<T, M>::synchronized_value(const synchronized_value& other)
489
516
{
490
- auto _ = lock_as_exclusive (other.m_mutex );
517
+ auto _ = lock_as_readonly (other.m_mutex );
491
518
m_value = other.m_value ;
492
519
}
493
520
@@ -573,9 +600,7 @@ namespace mamba::util
573
600
synchronized_value<T, M>::operator ==(const synchronized_value<U, OtherMutex>& other_value) const
574
601
-> bool
575
602
{
576
- auto this_lock [[maybe_unused]] = lock_as_readonly (m_mutex);
577
- auto other_lock [[maybe_unused]] = lock_as_readonly (other_value.m_mutex );
578
-
603
+ auto _ = lock_as_readonly (m_mutex, other_value.m_mutex );
579
604
return m_value == other_value.m_value ;
580
605
}
581
606
0 commit comments