Seastar
High performance C++ framework for concurrent servers
|
Shared/exclusive mutual exclusion.
Similar to std::shared_mutex
, this class provides protection for a shared resource, with two levels of access protection: shared and exclusive. Shared access allows multiple tasks to access the shared resource concurrently, while exclusive access allows just one task to access the resource at a time.
Note that many seastar tasks do not require protection at all, since the seastar scheduler is not preemptive; however tasks that do (by waiting on a future) may require explicit locking.
The with_shared(shared_mutex&, Func&&) and with_lock(shared_mutex&, Func&&) provide exception-safe wrappers for use with shared_mutex
.
#include <seastar/core/shared_mutex.hh>
Public Member Functions | |
shared_mutex (shared_mutex &&)=default | |
shared_mutex & | operator= (shared_mutex &&)=default |
shared_mutex (const shared_mutex &)=delete | |
void | operator= (const shared_mutex &)=delete |
future | lock_shared () noexcept |
bool | try_lock_shared () noexcept |
void | unlock_shared () noexcept |
Unlocks a shared_mutex after a previous call to lock_shared(). | |
future | lock () noexcept |
bool | try_lock () noexcept |
void | unlock () noexcept |
Unlocks a shared_mutex after a previous call to lock(). | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename Func > | |
std::enable_if_t< std::is_nothrow_move_constructible_v< Func >, futurize_t< std::result_of_t< Func()> > > | with_shared (shared_mutex &sm, Func &&func) noexcept |
template<typename Func > | |
std::enable_if_t< std::is_nothrow_move_constructible_v< Func >, futurize_t< std::result_of_t< Func()> > > | with_lock (shared_mutex &sm, Func &&func) noexcept |
|
inlinenoexcept |
Lock the shared_mutex
for exclusive access
|
inlinenoexcept |
Lock the shared_mutex
for shared access
|
inlinenoexcept |
Try to lock the shared_mutex
for exclusive access
|
inlinenoexcept |
Try to lock the shared_mutex
for shared access