libfoedus-core
FOEDUS Core Library
foedus::xct::McsRwSimpleBlock Struct Reference

Reader-writer (RW) MCS lock classes. More...

Detailed Description

Reader-writer (RW) MCS lock classes.

These are mainly used for record locks.Pre-allocated MCS block for simpler version of RW-locks.

Definition at line 387 of file xct_id.hpp.

#include <xct_id.hpp>

Collaboration diagram for foedus::xct::McsRwSimpleBlock:

Classes

union  Self
 

Public Member Functions

void init_reader ()
 
void init_writer ()
 
void init_common () __attribute__((always_inline))
 
bool is_reader () __attribute__((always_inline))
 
uint8_t read_state ()
 
void unblock () __attribute__((always_inline))
 
bool is_blocked () __attribute__((always_inline))
 
bool is_granted ()
 
void set_finalized ()
 
bool is_finalized ()
 
bool timeout_granted (int32_t timeout)
 MCS block classes. More...
 
void set_successor_class_writer ()
 
void set_successor_next_only (thread::ThreadId thread_id, McsBlockIndex block_index)
 
bool has_successor ()
 
bool successor_is_ready ()
 
bool has_reader_successor ()
 
bool has_writer_successor ()
 
uint16_t make_blocked_with_reader_successor_state ()
 
uint16_t make_blocked_with_no_successor_state ()
 

Public Attributes

union foedus::xct::McsRwSimpleBlock::Self self_
 
thread::ThreadId successor_thread_id_
 
McsBlockIndex successor_block_index_
 

Static Public Attributes

static const uint8_t kStateClassMask = 3U
 
static const uint8_t kStateClassReaderFlag = 1U
 
static const uint8_t kStateClassWriterFlag = 2U
 
static const uint8_t kStateBlockedFlag = 1U << 7U
 
static const uint8_t kStateBlockedMask = 1U << 7U
 
static const uint8_t kStateFinalizedMask = 4U
 
static const uint8_t kSuccessorClassReader = 1U
 
static const uint8_t kSuccessorClassWriter = 2U
 
static const uint8_t kSuccessorClassNone = 3U
 
static const int32_t kTimeoutNever = 0xFFFFFFFF
 

Class Documentation

union foedus::xct::McsRwSimpleBlock::Self

Definition at line 403 of file xct_id.hpp.

Collaboration diagram for foedus::xct::McsRwSimpleBlock::Self:
Class Members
struct Components components_
uint16_t data_

Member Function Documentation

bool foedus::xct::McsRwSimpleBlock::has_reader_successor ( )
inline

Definition at line 492 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, kSuccessorClassReader, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::successor_class_.

492  {
493  uint8_t s = assorted::atomic_load_acquire<uint8_t>(&self_.components_.successor_class_);
494  return s == kSuccessorClassReader;
495  }
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kSuccessorClassReader
Definition: xct_id.hpp:397
bool foedus::xct::McsRwSimpleBlock::has_successor ( )
inline

Definition at line 484 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::successor_class_.

484  {
485  return assorted::atomic_load_acquire<uint8_t>(
487  }
static const uint8_t kSuccessorClassNone
Definition: xct_id.hpp:399
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
bool foedus::xct::McsRwSimpleBlock::has_writer_successor ( )
inline

Definition at line 496 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, kSuccessorClassWriter, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::successor_class_.

496  {
497  uint8_t s = assorted::atomic_load_acquire<uint8_t>(&self_.components_.successor_class_);
498  return s == kSuccessorClassWriter;
499  }
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kSuccessorClassWriter
Definition: xct_id.hpp:398
void foedus::xct::McsRwSimpleBlock::init_common ( )
inline

Definition at line 428 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, kSuccessorClassNone, foedus::assorted::memory_fence_release(), self_, and foedus::xct::McsRwSimpleBlock::Self::Components::successor_class_.

Referenced by init_reader(), and init_writer().

428  {
433  }
static const uint8_t kSuccessorClassNone
Definition: xct_id.hpp:399
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
thread::ThreadId successor_thread_id_
Definition: xct_id.hpp:417
void memory_fence_release()
Equivalent to std::atomic_thread_fence(std::memory_order_release).
McsBlockIndex successor_block_index_
Definition: xct_id.hpp:418

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::xct::McsRwSimpleBlock::init_reader ( )
inline

Definition at line 420 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, init_common(), kStateBlockedFlag, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

420  {
422  init_common();
423  }
void init_common() __attribute__((always_inline))
Definition: xct_id.hpp:428
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kStateBlockedFlag
Definition: xct_id.hpp:392
static const uint8_t kStateClassReaderFlag
Definition: xct_id.hpp:389

Here is the call graph for this function:

void foedus::xct::McsRwSimpleBlock::init_writer ( )
inline

Definition at line 424 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, init_common(), kStateBlockedFlag, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

424  {
426  init_common();
427  }
static const uint8_t kStateClassWriterFlag
Definition: xct_id.hpp:390
void init_common() __attribute__((always_inline))
Definition: xct_id.hpp:428
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kStateBlockedFlag
Definition: xct_id.hpp:392

Here is the call graph for this function:

bool foedus::xct::McsRwSimpleBlock::is_blocked ( )
inline

Definition at line 447 of file xct_id.hpp.

References kStateBlockedMask, and read_state().

Referenced by is_granted(), and foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader().

447  {
448  return read_state() & kStateBlockedMask;
449  }
static const uint8_t kStateBlockedMask
Definition: xct_id.hpp:393

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::xct::McsRwSimpleBlock::is_finalized ( )
inline

Definition at line 460 of file xct_id.hpp.

References ASSERT_ND, is_reader(), kStateFinalizedMask, and read_state().

Referenced by set_finalized().

460  {
461  ASSERT_ND(is_reader());
462  return read_state() & kStateFinalizedMask;
463  }
static const uint8_t kStateFinalizedMask
Definition: xct_id.hpp:395
bool is_reader() __attribute__((always_inline))
Definition: xct_id.hpp:435
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::xct::McsRwSimpleBlock::is_granted ( )
inline

Definition at line 450 of file xct_id.hpp.

References is_blocked().

Referenced by timeout_granted().

450  {
451  return !is_blocked();
452  }
bool is_blocked() __attribute__((always_inline))
Definition: xct_id.hpp:447

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::xct::McsRwSimpleBlock::is_reader ( )
inline

Definition at line 435 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, kStateClassReaderFlag, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

Referenced by is_finalized(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader(), and set_finalized().

435  {
437  }
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kStateClassMask
Definition: xct_id.hpp:388
static const uint8_t kStateClassReaderFlag
Definition: xct_id.hpp:389

Here is the caller graph for this function:

uint16_t foedus::xct::McsRwSimpleBlock::make_blocked_with_no_successor_state ( )
inline

Definition at line 506 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, kStateBlockedFlag, kSuccessorClassNone, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

506  {
507  uint8_t state = self_.components_.state_ | kStateBlockedFlag;
508  return (uint16_t)state << 8 | kSuccessorClassNone;
509  }
static const uint8_t kSuccessorClassNone
Definition: xct_id.hpp:399
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kStateBlockedFlag
Definition: xct_id.hpp:392
uint16_t foedus::xct::McsRwSimpleBlock::make_blocked_with_reader_successor_state ( )
inline

Definition at line 501 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, kStateBlockedFlag, kSuccessorClassReader, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

501  {
502  // Only using the class bit, which doesn't change, so no need to use atomic ops.
503  uint8_t state = self_.components_.state_ | kStateBlockedFlag;
504  return (uint16_t)state << 8 | kSuccessorClassReader;
505  }
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kSuccessorClassReader
Definition: xct_id.hpp:397
static const uint8_t kStateBlockedFlag
Definition: xct_id.hpp:392
uint8_t foedus::xct::McsRwSimpleBlock::read_state ( )
inline

Definition at line 438 of file xct_id.hpp.

References foedus::xct::McsRwSimpleBlock::Self::components_, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

Referenced by is_blocked(), is_finalized(), and unblock().

438  {
439  return assorted::atomic_load_acquire<uint8_t>(&self_.components_.state_);
440  }
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_

Here is the caller graph for this function:

void foedus::xct::McsRwSimpleBlock::set_finalized ( )
inline

Definition at line 453 of file xct_id.hpp.

References ASSERT_ND, foedus::xct::McsRwSimpleBlock::Self::components_, is_finalized(), is_reader(), kStateFinalizedMask, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

453  {
454  ASSERT_ND(is_reader());
456  assorted::raw_atomic_fetch_and_bitwise_or<uint8_t>(
459  }
union foedus::xct::McsRwSimpleBlock::Self self_
static const uint8_t kStateFinalizedMask
Definition: xct_id.hpp:395
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
bool is_reader() __attribute__((always_inline))
Definition: xct_id.hpp:435
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the call graph for this function:

void foedus::xct::McsRwSimpleBlock::set_successor_class_writer ( )
inline

Definition at line 465 of file xct_id.hpp.

References ASSERT_ND, foedus::xct::McsRwSimpleBlock::Self::components_, kSuccessorClassWriter, self_, and foedus::xct::McsRwSimpleBlock::Self::Components::successor_class_.

465  {
466  // In case the caller is a reader appending after a writer or waiting reader,
467  // the requester should have already set the successor class to "reader" through by CASing
468  // self_.data_ from [no-successor, blocked] to [reader successor, blocked].
470  assorted::raw_atomic_fetch_and_bitwise_and<uint8_t>(
472  }
static const uint8_t kSuccessorClassNone
Definition: xct_id.hpp:399
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kSuccessorClassWriter
Definition: xct_id.hpp:398
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
void foedus::xct::McsRwSimpleBlock::set_successor_next_only ( thread::ThreadId  thread_id,
McsBlockIndex  block_index 
)
inline

Definition at line 473 of file xct_id.hpp.

References ASSERT_ND, foedus::xct::McsRwSimpleBlock::Self::data_, self_, successor_block_index_, and successor_thread_id_.

473  {
474  McsRwSimpleBlock tmp;
475  tmp.self_.data_ = 0;
476  tmp.successor_thread_id_ = thread_id;
477  tmp.successor_block_index_ = block_index;
480  uint64_t *address = reinterpret_cast<uint64_t*>(this);
481  uint64_t mask = *reinterpret_cast<uint64_t*>(&tmp);
482  assorted::raw_atomic_fetch_and_bitwise_or<uint64_t>(address, mask);
483  }
thread::ThreadId successor_thread_id_
Definition: xct_id.hpp:417
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
McsBlockIndex successor_block_index_
Definition: xct_id.hpp:418
bool foedus::xct::McsRwSimpleBlock::successor_is_ready ( )
inline

Definition at line 488 of file xct_id.hpp.

References successor_block_index_.

488  {
489  // Check block index only - thread ID could be 0
490  return assorted::atomic_load_acquire<McsBlockIndex>(&successor_block_index_) != 0;
491  }
McsBlockIndex successor_block_index_
Definition: xct_id.hpp:418
bool foedus::xct::McsRwSimpleBlock::timeout_granted ( int32_t  timeout)

MCS block classes.

Definition at line 133 of file xct_id.cpp.

References is_granted(), kTimeoutNever, foedus::assorted::spin_until(), and foedus::assorted::yield_if_valgrind().

133  {
134  if (timeout == kTimeoutNever) {
135  assorted::spin_until([this]{ return this->is_granted(); });
136  return true;
137  } else {
138  while (--timeout) {
139  if (is_granted()) {
140  return true;
141  }
143  }
144  return is_granted();
145  }
146 }
uint64_t spin_until(COND spin_until_cond)
Spin locally until the given condition returns true.
static const int32_t kTimeoutNever
Definition: xct_id.hpp:401
void yield_if_valgrind()
Use this in your while as a stop-gap before switching to spin_until().

Here is the call graph for this function:

void foedus::xct::McsRwSimpleBlock::unblock ( )
inline

Definition at line 441 of file xct_id.hpp.

References ASSERT_ND, foedus::xct::McsRwSimpleBlock::Self::components_, read_state(), self_, and foedus::xct::McsRwSimpleBlock::Self::Components::state_.

Referenced by foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_reader().

441  {
443  assorted::raw_atomic_fetch_and_bitwise_and<uint8_t>(
445  static_cast<uint8_t>(~kStateBlockedMask));
446  }
union foedus::xct::McsRwSimpleBlock::Self self_
struct foedus::xct::McsRwSimpleBlock::Self::Components components_
static const uint8_t kStateBlockedMask
Definition: xct_id.hpp:393
static const uint8_t kStateBlockedFlag
Definition: xct_id.hpp:392
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

const uint8_t foedus::xct::McsRwSimpleBlock::kStateBlockedFlag = 1U << 7U
static
const uint8_t foedus::xct::McsRwSimpleBlock::kStateBlockedMask = 1U << 7U
static

Definition at line 393 of file xct_id.hpp.

Referenced by is_blocked().

const uint8_t foedus::xct::McsRwSimpleBlock::kStateClassMask = 3U
static

Definition at line 388 of file xct_id.hpp.

const uint8_t foedus::xct::McsRwSimpleBlock::kStateClassReaderFlag = 1U
static

Definition at line 389 of file xct_id.hpp.

Referenced by is_reader().

const uint8_t foedus::xct::McsRwSimpleBlock::kStateClassWriterFlag = 2U
static

Definition at line 390 of file xct_id.hpp.

const uint8_t foedus::xct::McsRwSimpleBlock::kStateFinalizedMask = 4U
static

Definition at line 395 of file xct_id.hpp.

Referenced by is_finalized(), and set_finalized().

const uint8_t foedus::xct::McsRwSimpleBlock::kSuccessorClassNone = 3U
static

Definition at line 399 of file xct_id.hpp.

Referenced by init_common(), and make_blocked_with_no_successor_state().

const uint8_t foedus::xct::McsRwSimpleBlock::kSuccessorClassReader = 1U
static

Definition at line 397 of file xct_id.hpp.

Referenced by has_reader_successor(), and make_blocked_with_reader_successor_state().

const uint8_t foedus::xct::McsRwSimpleBlock::kSuccessorClassWriter = 2U
static

Definition at line 398 of file xct_id.hpp.

Referenced by has_writer_successor(), and set_successor_class_writer().

const int32_t foedus::xct::McsRwSimpleBlock::kTimeoutNever = 0xFFFFFFFF
static

Definition at line 401 of file xct_id.hpp.

Referenced by timeout_granted().

McsBlockIndex foedus::xct::McsRwSimpleBlock::successor_block_index_

Definition at line 418 of file xct_id.hpp.

Referenced by set_successor_next_only(), and successor_is_ready().

thread::ThreadId foedus::xct::McsRwSimpleBlock::successor_thread_id_

Definition at line 417 of file xct_id.hpp.

Referenced by set_successor_next_only().


The documentation for this struct was generated from the following files: