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 <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 ()
 
void unlock_shared ()
 Unlocks a shared_mutex after a previous call to lock_shared().
 
future lock ()
 
void unlock ()
 Unlocks a shared_mutex after a previous call to lock().
 

Related Functions

(Note that these are not member functions.)

template<typename Func >
futurize_t< std::result_of_t< Func()> > with_shared (shared_mutex &sm, Func &&func)
 
template<typename Func >
futurize_t< std::result_of_t< Func()> > with_lock (shared_mutex &sm, Func &&func)
 

Member Function Documentation

◆ lock()

future seastar::shared_mutex::lock ( )
inline

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 ( )
inline

Lock the shared_mutex for shared access

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

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