Seastar
High performance C++ framework for concurrent servers
Classes | Public Member Functions | Related Functions | List of all members
seastar::shared_mutex Class Reference

Detailed Description

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.

See also
semaphore simpler mutual exclusion

#include <seastar/core/shared_mutex.hh>

Public Member Functions

 shared_mutex (shared_mutex &&)=default
 
shared_mutexoperator= (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
 

Member Function Documentation

◆ lock()

future seastar::shared_mutex::lock ( )
inlinenoexcept

Lock the shared_mutex for exclusive access

Returns
a future that becomes ready when no access, shared or exclusive is granted to anyone.

◆ lock_shared()

future seastar::shared_mutex::lock_shared ( )
inlinenoexcept

Lock the shared_mutex for shared access

Returns
a future that becomes ready when no exclusive access is granted to anyone.

◆ try_lock()

bool seastar::shared_mutex::try_lock ( )
inlinenoexcept

Try to lock the shared_mutex for exclusive access

Returns
true iff could acquire the lock for exclusive access.

◆ try_lock_shared()

bool seastar::shared_mutex::try_lock_shared ( )
inlinenoexcept

Try to lock the shared_mutex for shared access

Returns
true iff could acquire the lock for shared access.

The documentation for this class was generated from the following file: