24 #include <seastar/core/semaphore.hh>
30 template<
typename Clock>
33 template<typename Clock = typename timer<>::clock>
34 class rwlock_for_read {
37 return static_cast<basic_rwlock<Clock>*
>(
this)->read_lock();
40 static_cast<basic_rwlock<Clock>*
>(
this)->read_unlock();
42 friend class basic_rwlock<Clock>;
45 template<typename Clock = typename timer<>::clock>
46 class rwlock_for_write {
49 return static_cast<basic_rwlock<Clock>*
>(
this)->write_lock();
52 static_cast<basic_rwlock<Clock>*
>(
this)->write_unlock();
54 friend class basic_rwlock<Clock>;
68 template<typename Clock = typename timer<>::clock>
69 class basic_rwlock :
private rwlock_for_read<Clock>, rwlock_for_write<Clock> {
97 future<> read_lock(
typename semaphore_type::time_point timeout = semaphore_type::time_point::max()) {
98 return _sem.
wait(timeout);
102 return _sem.
wait(as);
109 assert(_sem.
current() < max_ops);
117 future<> write_lock(
typename semaphore_type::time_point timeout = semaphore_type::time_point::max()) {
118 return _sem.
wait(timeout, max_ops);
122 return _sem.
wait(as, max_ops);
157 return get_units(_sem, 1, timeout);
161 return get_units(_sem, 1, as);
176 return get_units(_sem, max_ops, timeout);
180 return get_units(_sem, max_ops, as);
188 friend class rwlock_for_read<Clock>;
189 friend class rwlock_for_write<Clock>;
192 using rwlock = basic_rwlock<>;
Definition: abort_source.hh:51
future read_lock(typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
Definition: rwlock.hh:97
void read_unlock()
Definition: rwlock.hh:108
rwlock_for_read< Clock > & for_read()
Definition: rwlock.hh:83
future< holder > hold_write_lock(typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
Definition: rwlock.hh:175
future write_lock(typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
Definition: rwlock.hh:117
bool try_read_lock()
Tries to acquire the lock in read mode iff this can be done without waiting.
Definition: rwlock.hh:134
bool try_write_lock()
Tries to acquire the lock in write mode iff this can be done without waiting.
Definition: rwlock.hh:139
bool locked() const
Checks if any read or write locks are currently held.
Definition: rwlock.hh:184
future< holder > hold_read_lock(typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
Definition: rwlock.hh:156
rwlock_for_write< Clock > & for_write()
Definition: rwlock.hh:90
void write_unlock()
Definition: rwlock.hh:128
Counted resource guard.
Definition: semaphore.hh:148
static constexpr size_t max_counter() noexcept
Returns the maximum number of units the semaphore counter can hold.
Definition: semaphore.hh:196
size_t current() const noexcept
Definition: semaphore.hh:370
future wait(size_t nr=1) noexcept
Definition: semaphore.hh:227
ssize_t available_units() const noexcept
Definition: semaphore.hh:376
bool try_wait(size_t nr=1) noexcept
Definition: semaphore.hh:359
void signal(size_t nr=1) noexcept
Definition: semaphore.hh:322
Definition: semaphore.hh:432
Seastar API namespace.
Definition: abort_on_ebadf.hh:24