libfoedus-core
FOEDUS Core Library
|
An MCS reader-writer lock data structure. More...
An MCS reader-writer lock data structure.
This implements a fair reader-writer lock by the original authors of MCS lock [PPoPP 1991]. The version implemented here includes a bug fix due to Keir Fraser (University of Cambridge). See https://www.cs.rochester.edu/research/synchronization/pseudocode/rw.html#s_f for the original pseudocode with the fix.
The major use case so far is row-level locking for 2PL.
The assumption is that a thread at any instant can be waiting for only one MCS lock, so knowing the thread ID suffices to locate the block index as well.
TODO(tzwang): add the ownerless variant.
Definition at line 795 of file xct_id.hpp.
#include <xct_id.hpp>
Public Member Functions | |
McsRwLock () | |
McsRwLock (const McsRwLock &other)=delete | |
McsRwLock & | operator= (const McsRwLock &other)=delete |
void | reset () |
void | increment_nreaders () |
uint16_t | decrement_nreaders () |
uint16_t | nreaders () |
McsBlockIndex | get_tail_waiter_block () const |
thread::ThreadId | get_tail_waiter () const |
bool | has_next_writer () const |
void | set_next_writer (thread::ThreadId thread_id) |
thread::ThreadId | get_next_writer () |
thread::ThreadId | xchg_next_writer (thread::ThreadId id) |
bool | cas_next_writer_weak (thread::ThreadId expected, thread::ThreadId desired) |
bool | cas_next_writer_strong (thread::ThreadId expected, thread::ThreadId desired) |
uint32_t | xchg_tail (uint32_t new_tail) |
bool | cas_tail_strong (uint32_t expected, uint32_t desired) |
bool | cas_tail_weak (uint32_t expected, uint32_t desired) |
uint32_t | get_tail_int () |
bool | is_locked () const |
Static Public Member Functions | |
static uint32_t | to_tail_int (thread::ThreadId tail_waiter, McsBlockIndex tail_waiter_block) |
Public Attributes | |
uint32_t | tail_ |
thread::ThreadId | next_writer_ |
uint16_t | nreaders_ |
Static Public Attributes | |
static const thread::ThreadId | kNextWriterNone = 0xFFFFU |
Friends | |
std::ostream & | operator<< (std::ostream &o, const McsRwLock &v) |
|
inline |
Definition at line 798 of file xct_id.hpp.
References reset().
|
delete |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 811 of file xct_id.hpp.
References nreaders_.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader().
|
inline |
Definition at line 825 of file xct_id.hpp.
References next_writer_.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_writer().
|
inline |
|
inline |
Definition at line 818 of file xct_id.hpp.
References tail_.
Referenced by foedus::xct::McsMockAdaptor< RW_BLOCK >::dereference_rw_tail_block(), foedus::thread::ThreadPimplMcsAdaptor< RW_BLOCK >::dereference_rw_tail_block(), foedus::xct::operator<<(), and foedus::storage::array::ArrayStoragePimpl::verify_single_thread().
|
inline |
Definition at line 817 of file xct_id.hpp.
References tail_.
Referenced by foedus::xct::McsMockAdaptor< RW_BLOCK >::dereference_rw_tail_block(), foedus::thread::ThreadPimplMcsAdaptor< RW_BLOCK >::dereference_rw_tail_block(), foedus::xct::operator<<(), and foedus::storage::array::ArrayStoragePimpl::verify_single_thread().
|
inline |
Definition at line 819 of file xct_id.hpp.
References next_writer_.
|
inline |
Definition at line 808 of file xct_id.hpp.
References nreaders_.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_writer(), and foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::retry_async_rw_reader().
|
inline |
Definition at line 857 of file xct_id.hpp.
References nreaders_, and tail_.
Referenced by foedus::xct::RwLockableXctId::is_keylocked(), foedus::xct::operator<<(), and foedus::storage::masstree::MasstreeStoragePimpl::verify_single_thread_border().
|
inline |
Definition at line 814 of file xct_id.hpp.
References nreaders_.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_writer(), and foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader().
|
inline |
Definition at line 803 of file xct_id.hpp.
References foedus::assorted::memory_fence_release(), nreaders_, set_next_writer(), and tail_.
Referenced by foedus::storage::sequential::SequentialPage::append_record_nosync(), foedus::storage::masstree::MasstreeBorderPage::initialize_layer_root(), McsRwLock(), foedus::storage::masstree::MasstreeBorderPage::reserve_initially_next_layer(), foedus::storage::masstree::MasstreeBorderPage::reserve_record_space(), foedus::xct::RwLockableXctId::reset(), and foedus::storage::masstree::SplitBorder::run().
|
inline |
Definition at line 822 of file xct_id.hpp.
References xchg_next_writer().
Referenced by reset().
|
inlinestatic |
Definition at line 848 of file xct_id.hpp.
References ASSERT_ND.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwExtendedBlock >::acquire_try_rw_writer(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_writer(), foedus::xct::McsImpl< ADAPTOR, McsRwExtendedBlock >::cancel_async_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwExtendedBlock >::cancel_async_rw_writer(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_writer(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::retry_async_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwExtendedBlock >::retry_async_rw_reader(), and foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::retry_async_rw_writer().
|
inline |
Definition at line 828 of file xct_id.hpp.
References next_writer_.
Referenced by set_next_writer().
|
inline |
|
friend |
Definition at line 195 of file xct_id.cpp.
|
static |
Definition at line 796 of file xct_id.hpp.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_writer(), and foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader().
thread::ThreadId foedus::xct::McsRwLock::next_writer_ |
Definition at line 867 of file xct_id.hpp.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_writer(), cas_next_writer_strong(), cas_next_writer_weak(), get_next_writer(), has_next_writer(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader(), and xchg_next_writer().
uint16_t foedus::xct::McsRwLock::nreaders_ |
Definition at line 868 of file xct_id.hpp.
Referenced by decrement_nreaders(), increment_nreaders(), is_locked(), nreaders(), and reset().
uint32_t foedus::xct::McsRwLock::tail_ |
Definition at line 861 of file xct_id.hpp.
Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwExtendedBlock >::acquire_try_rw_writer(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::acquire_unconditional_rw_writer(), cas_tail_strong(), cas_tail_weak(), foedus::xct::McsMockAdaptor< RW_BLOCK >::dereference_rw_tail_block(), foedus::thread::ThreadPimplMcsAdaptor< RW_BLOCK >::dereference_rw_tail_block(), get_tail_int(), get_tail_waiter(), get_tail_waiter_block(), is_locked(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_writer(), reset(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::retry_async_rw_reader(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::retry_async_rw_writer(), and xchg_tail().