6#include <userver/engine/condition_variable.hpp>
7#include <userver/engine/mutex.hpp>
8#include <userver/engine/semaphore.hpp>
10USERVER_NAMESPACE_BEGIN
29class SharedMutex
final {
32 ~SharedMutex() =
default;
34 SharedMutex(
const SharedMutex&) =
delete;
35 SharedMutex(SharedMutex&&) =
delete;
36 SharedMutex& operator=(
const SharedMutex&) =
delete;
37 SharedMutex& operator=(SharedMutex&&) =
delete;
62 template <
typename Rep,
typename Period>
63 [[nodiscard]]
bool try_lock_for(
const std::chrono::duration<Rep, Period>&);
70 template <
typename Clock,
typename Duration>
72 const std::chrono::time_point<Clock, Duration>&);
100 template <
typename Rep,
typename Period>
102 const std::chrono::duration<Rep, Period>&);
109 template <
typename Clock,
typename Duration>
111 const std::chrono::time_point<Clock, Duration>&);
117 bool HasWaitingWriter()
const noexcept;
119 bool WaitForNoWaitingWriters(Deadline deadline);
121 void DecWaitingWriters();
124
125
126
127
128
129
130
131 Semaphore semaphore_;
134
135
136 std::atomic_size_t waiting_writers_count_;
137 Mutex waiting_writers_count_mutex_;
138 ConditionVariable waiting_writers_count_cv_;
141template <
typename Rep,
typename Period>
143 const std::chrono::duration<Rep, Period>& duration) {
144 return try_lock_until(Deadline::FromDuration(duration));
147template <
typename Rep,
typename Period>
149 const std::chrono::duration<Rep, Period>& duration) {
150 return try_lock_shared_until(Deadline::FromDuration(duration));
153template <
typename Clock,
typename Duration>
155 const std::chrono::time_point<Clock, Duration>& until) {
156 return try_lock_until(Deadline::FromTimePoint(until));
159template <
typename Clock,
typename Duration>
161 const std::chrono::time_point<Clock, Duration>& until) {
162 return try_lock_shared_until(Deadline::FromTimePoint(until));