Seastar
High performance C++ framework for concurrent servers
Public Types | Public Member Functions | List of all members
seastar::basic_rwlock< Clock > Class Template Reference

Detailed Description

template<typename Clock = typename timer<>::clock>
class seastar::basic_rwlock< Clock >

Implements a read-write lock mechanism. Beware: this is not a cross-CPU lock, due to seastar's sharded architecture. Instead, it can be used to achieve rwlock semantics between two (or more) fibers running in the same CPU that may use the same resource. Acquiring the write lock will effectively cause all readers not to be executed until the write part is done.

#include <seastar/core/rwlock.hh>

Inheritance diagram for seastar::basic_rwlock< Clock >:

Public Types

using holder = semaphore_units< semaphore_default_exception_factory, Clock >
 

Public Member Functions

rwlock_for_read< Clock > & for_read ()
 
rwlock_for_write< Clock > & for_write ()
 
future read_lock (typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
 
future read_lock (abort_source &as)
 
void read_unlock ()
 
future write_lock (typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
 
future write_lock (abort_source &as)
 
void write_unlock ()
 
bool try_read_lock ()
 Tries to acquire the lock in read mode iff this can be done without waiting.
 
bool try_write_lock ()
 Tries to acquire the lock in write mode iff this can be done without waiting.
 
future< holderhold_read_lock (typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
 
future< holderhold_read_lock (abort_source &as)
 
future< holderhold_write_lock (typename semaphore_type::time_point timeout=semaphore_type::time_point::max())
 
future< holderhold_write_lock (abort_source &as)
 
bool locked () const
 Checks if any read or write locks are currently held.
 

Member Function Documentation

◆ for_read()

template<typename Clock = typename timer<>::clock>
rwlock_for_read<Clock>& seastar::basic_rwlock< Clock >::for_read ( )
inline

Cast this rwlock into read lock object with lock semantics appropriate to be used by "with_lock". The resulting object will have lock / unlock calls that, when called, will acquire / release the lock in read mode.

◆ for_write()

template<typename Clock = typename timer<>::clock>
rwlock_for_write<Clock>& seastar::basic_rwlock< Clock >::for_write ( )
inline

Cast this rwlock into write lock object with lock semantics appropriate to be used by "with_lock". The resulting object will have lock / unlock calls that, when called, will acquire / release the lock in write mode.

◆ hold_read_lock()

template<typename Clock = typename timer<>::clock>
future<holder> seastar::basic_rwlock< Clock >::hold_read_lock ( typename semaphore_type::time_point  timeout = semaphore_type::time_point::max())
inline

hold_read_lock() waits for a read lock and returns an object which, when destroyed, releases the lock. This makes it easy to ensure that the lock is eventually undone, at any circumstance (even including exceptions). The release() method can be used on the returned object to release its ownership of the lock and avoid the automatic unlock. Note that both hold_read_lock() and hold_write_lock() return an object of the same type, rwlock::holder.

hold_read_lock() may throw an exception (or, in other implementations, return an exceptional future) when it failed to obtain the lock - e.g., on allocation failure.

◆ hold_write_lock()

template<typename Clock = typename timer<>::clock>
future<holder> seastar::basic_rwlock< Clock >::hold_write_lock ( typename semaphore_type::time_point  timeout = semaphore_type::time_point::max())
inline

hold_write_lock() waits for a write lock and returns an object which, when destroyed, releases the lock. This makes it easy to ensure that the lock is eventually undone, at any circumstance (even including exceptions). The release() method can be used on the returned object to release its ownership of the lock and avoid the automatic unlock. Note that both hold_read_lock() and hold_write_lock() return an object of the same type, rwlock::holder.

hold_read_lock() may throw an exception (or, in other implementations, return an exceptional future) when it failed to obtain the lock - e.g., on allocation failure.

◆ read_lock()

template<typename Clock = typename timer<>::clock>
future seastar::basic_rwlock< Clock >::read_lock ( typename semaphore_type::time_point  timeout = semaphore_type::time_point::max())
inline

Acquires this lock in read mode. Many readers are allowed, but when this future returns, and until read_unlock is called, all fibers waiting on write_lock are guaranteed not to execute.

◆ read_unlock()

template<typename Clock = typename timer<>::clock>
void seastar::basic_rwlock< Clock >::read_unlock ( )
inline

Releases the lock, which must have been taken in read mode. After this is called, one of the fibers waiting on write_lock will be allowed to proceed.

◆ write_lock()

template<typename Clock = typename timer<>::clock>
future seastar::basic_rwlock< Clock >::write_lock ( typename semaphore_type::time_point  timeout = semaphore_type::time_point::max())
inline

Acquires this lock in write mode. Only one writer is allowed. When this future returns, and until write_unlock is called, all other fibers waiting on either read_lock or write_lock are guaranteed not to execute.

◆ write_unlock()

template<typename Clock = typename timer<>::clock>
void seastar::basic_rwlock< Clock >::write_unlock ( )
inline

Releases the lock, which must have been taken in write mode. After this is called, one of the other fibers waiting on write_lock or the fibers waiting on read_lock will be allowed to proceed.


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