libfoedus-core
FOEDUS Core Library
foedus::xct::McsWwOwnerlessImpl Class Reference

A ownerless (contextless) interface for McsWwImpl. More...

Detailed Description

A ownerless (contextless) interface for McsWwImpl.

Conceptually this is part of McsWwImpl, but this doesn't depend on Adaptor because guests don't need any context in MCSg. We separate the methods to this class for easier use.

Definition at line 218 of file xct_mcs_impl.hpp.

#include <xct_mcs_impl.hpp>

Public Member Functions

 McsWwOwnerlessImpl ()=delete
 
 ~McsWwOwnerlessImpl ()=delete
 

Static Public Member Functions

static void ownerless_acquire_unconditional (McsWwLock *lock)
 [WW-Guest] Unconditionally takes exclusive-only guest lock on the given MCSg lock. More...
 
static bool ownerless_acquire_try (McsWwLock *lock)
 [WW-Guest] Try to take an exclusive guest lock on the given MCSg lock. More...
 
static void ownerless_release (McsWwLock *lock)
 
static void ownerless_initial (McsWwLock *lock)
 

Constructor & Destructor Documentation

foedus::xct::McsWwOwnerlessImpl::McsWwOwnerlessImpl ( )
delete
foedus::xct::McsWwOwnerlessImpl::~McsWwOwnerlessImpl ( )
delete

Member Function Documentation

bool foedus::xct::McsWwOwnerlessImpl::ownerless_acquire_try ( McsWwLock lock)
static

[WW-Guest] Try to take an exclusive guest lock on the given MCSg lock.

Returns
whether we got the lock. If you receive true, you are responsible to call ownerless_release()

Definition at line 292 of file xct_mcs_impl.cpp.

References foedus::xct::assert_mcs_aligned(), ASSERT_ND, foedus::xct::McsWwLock::is_locked(), foedus::xct::McsWwBlockData::is_valid_relaxed(), foedus::xct::kMcsGuestId, foedus::xct::McsWwLock::tail_, and foedus::xct::McsWwBlockData::word_.

292  {
293  // Similar to acquire_try()
294  assert_mcs_aligned(mcs_lock);
295  auto* int_address = &(mcs_lock->tail_.word_);
296  assert_mcs_aligned(int_address);
297  McsWwBlockData pred; // purely local copy. okay to be always relaxed.
298  ASSERT_ND(!pred.is_valid_relaxed());
299  bool swapped = assorted::raw_atomic_compare_exchange_weak<uint64_t>(
300  &(mcs_lock->tail_.word_),
301  &pred.word_,
302  kMcsGuestId);
303 
304  if (swapped) {
305  ASSERT_ND(mcs_lock->is_locked());
306  DVLOG(2) << "Okay, got a guest lock uncontended.";
307  // We can't test is_guest here because we might now have a successor swapping it.
308  ASSERT_ND(!pred.is_valid_relaxed());
309  return true;
310  } else {
311  return true;
312  }
313 }
const uint64_t kMcsGuestId
A special value meaning the lock is held by a non-regular guest that doesn't have a context...
Definition: xct_id.hpp:158
void assert_mcs_aligned(const void *address)
#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::McsWwOwnerlessImpl::ownerless_acquire_unconditional ( McsWwLock lock)
static

[WW-Guest] Unconditionally takes exclusive-only guest lock on the given MCSg lock.

Ownerless interface for WW-lock implementations.

Definition at line 272 of file xct_mcs_impl.cpp.

References foedus::xct::assert_mcs_aligned(), ASSERT_ND, foedus::xct::McsWwLock::is_locked(), foedus::xct::McsWwBlockData::is_valid_relaxed(), foedus::xct::kMcsGuestId, foedus::xct::spin_until(), foedus::xct::McsWwLock::tail_, and foedus::xct::McsWwBlockData::word_.

Referenced by foedus::xct::McsWwLock::ownerless_acquire_lock().

272  {
273  // Basically _all_ writes in this function must come with some memory barrier. Be careful!
274  // Also, the performance of this method really matters, especially that of common path.
275  // Check objdump -d. Everything in common path should be inlined.
276  // Also, check minimal sufficient mfences (note, xchg implies lock prefix. not a compiler's bug!).
277  assert_mcs_aligned(mcs_lock);
278  auto* int_address = &(mcs_lock->tail_.word_);
279  assert_mcs_aligned(int_address);
280  spin_until([mcs_lock, int_address]{
281  McsWwBlockData old;
282  ASSERT_ND(!old.is_valid_relaxed());
283  return assorted::raw_atomic_compare_exchange_weak<uint64_t>(
284  int_address,
285  &old.word_,
286  kMcsGuestId);
287  });
288  DVLOG(1) << "Okay, now I hold the lock. me=guest";
289  ASSERT_ND(mcs_lock->is_locked());
290 }
const uint64_t kMcsGuestId
A special value meaning the lock is held by a non-regular guest that doesn't have a context...
Definition: xct_id.hpp:158
void spin_until(COND spin_until_cond)
void assert_mcs_aligned(const void *address)
#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:

void foedus::xct::McsWwOwnerlessImpl::ownerless_initial ( McsWwLock lock)
static

Definition at line 315 of file xct_mcs_impl.cpp.

References foedus::xct::assert_mcs_aligned(), ASSERT_ND, foedus::xct::McsWwLock::is_locked(), and foedus::xct::McsWwLock::reset_guest_id_release().

Referenced by foedus::xct::McsWwLock::ownerless_initial_lock().

315  {
316  assert_mcs_aligned(mcs_lock);
317  ASSERT_ND(!mcs_lock->is_locked());
318  mcs_lock->reset_guest_id_release();
319 }
void assert_mcs_aligned(const void *address)
#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:

void foedus::xct::McsWwOwnerlessImpl::ownerless_release ( McsWwLock lock)
static

Definition at line 321 of file xct_mcs_impl.cpp.

References foedus::xct::assert_mcs_aligned(), ASSERT_ND, foedus::xct::McsWwBlockData::is_guest_relaxed(), foedus::xct::McsWwLock::is_locked(), foedus::xct::McsWwBlockData::is_valid_relaxed(), foedus::xct::kMcsGuestId, foedus::xct::spin_until(), foedus::xct::McsWwLock::tail_, and foedus::xct::McsWwBlockData::word_.

Referenced by foedus::xct::McsWwLock::ownerless_release_lock().

321  {
322  // Basically _all_ writes in this function must come with some memory barrier. Be careful!
323  // Also, the performance of this method really matters, especially that of common path.
324  // Check objdump -d. Everything in common path should be inlined.
325  // Also, check minimal sufficient mfences (note, xchg implies lock prefix. not a compiler's bug!).
326  assert_mcs_aligned(mcs_lock);
327  auto* int_address = &(mcs_lock->tail_.word_);
328  assert_mcs_aligned(int_address);
329  ASSERT_ND(mcs_lock->is_locked());
330  spin_until([int_address]{
331  McsWwBlockData old(kMcsGuestId);
332  ASSERT_ND(old.is_valid_relaxed());
333  ASSERT_ND(old.is_guest_relaxed());
334  return assorted::raw_atomic_compare_exchange_weak<uint64_t>(int_address, &old.word_, 0);
335  });
336  DVLOG(1) << "Okay, guest released the lock.";
337 }
const uint64_t kMcsGuestId
A special value meaning the lock is held by a non-regular guest that doesn't have a context...
Definition: xct_id.hpp:158
void spin_until(COND spin_until_cond)
void assert_mcs_aligned(const void *address)
#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:


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