24 #ifndef SEASTAR_MODULE
25 #include <seastar/core/future.hh>
26 #include <seastar/core/chunked_fifo.hh>
27 #include <seastar/util/modules.hh>
34 SEASTAR_MODULE_EXPORT_BEGIN
57 unsigned _readers = 0;
60 waiter(
promise<>&& pr,
bool for_write) : pr(std::move(pr)), for_write(for_write) {}
77 return make_ready_future<>();
80 _waiters.emplace_back(
promise<>(),
false);
81 return _waiters.back().pr.get_future();
90 if (!_writer && _waiters.empty()) {
108 return make_ready_future<>();
111 _waiters.emplace_back(
promise<>(),
true);
112 return _waiters.back().pr.get_future();
121 if (!_readers && !_writer) {
134 void wake() noexcept {
135 while (!_waiters.empty()) {
136 auto& w = _waiters.front();
142 _waiters.pop_front();
148 _waiters.pop_front();
164 template <
typename Func>
166 requires (std::invocable<Func> && std::is_nothrow_move_constructible_v<Func>)
168 futurize_t<std::invoke_result_t<Func>>
172 std::enable_if_t<std::is_nothrow_move_constructible_v<Func>, futurize_t<std::result_of_t<Func ()>>>
175 return sm.lock_shared().then([&sm, func = std::forward<Func>(func)] ()
mutable {
176 return futurize_invoke(func).finally([&sm] {
182 template <
typename Func>
184 requires (std::invocable<Func> && !std::is_nothrow_move_constructible_v<Func>)
186 futurize_t<std::invoke_result_t<Func>>
190 std::enable_if_t<!std::is_nothrow_move_constructible_v<Func>, futurize_t<std::result_of_t<Func ()>>>
195 return do_with(std::forward<Func>(func), [&sm] (Func& func) {
196 return sm.lock_shared().then([&func] {
217 template <
typename Func>
219 requires (std::invocable<Func> && std::is_nothrow_move_constructible_v<Func>)
221 futurize_t<std::invoke_result_t<Func>>
225 std::enable_if_t<std::is_nothrow_move_constructible_v<Func>, futurize_t<std::result_of_t<Func ()>>>
228 return sm.lock().then([&sm, func = std::forward<Func>(func)] ()
mutable {
229 return futurize_invoke(func).finally([&sm] {
236 template <
typename Func>
238 requires (std::invocable<Func> && !std::is_nothrow_move_constructible_v<Func>)
240 futurize_t<std::invoke_result_t<Func>>
244 std::enable_if_t<!std::is_nothrow_move_constructible_v<Func>, futurize_t<std::result_of_t<Func ()>>>
249 return do_with(std::forward<Func>(func), [&sm] (Func& func) {
250 return sm.lock().then([&func] {
262 SEASTAR_MODULE_EXPORT_END
Shared/exclusive mutual exclusion.
Definition: shared_mutex.hh:56
void unlock_shared() noexcept
Unlocks a shared_mutex after a previous call to lock_shared().
Definition: shared_mutex.hh:97
future lock() noexcept
Definition: shared_mutex.hh:106
bool try_lock() noexcept
Definition: shared_mutex.hh:120
void unlock() noexcept
Unlocks a shared_mutex after a previous call to lock().
Definition: shared_mutex.hh:128
bool try_lock_shared() noexcept
Definition: shared_mutex.hh:89
future lock_shared() noexcept
Definition: shared_mutex.hh:75
future< T > current_exception_as_future() noexcept
Returns std::current_exception() wrapped in a future.
Definition: future.hh:1953
auto do_with(T1 &&rv1, T2 &&rv2, More &&... more) noexcept
Definition: do_with.hh:135
auto with_lock(Lock &lock, Func &&func)
Definition: do_with.hh:149
Seastar API namespace.
Definition: abort_on_ebadf.hh:26