proxygen
folly::MicroSpinLock Struct Reference

#include <MicroSpinLock.h>

Inheritance diagram for folly::MicroSpinLock:
folly::futures::detail::SpinLock

Public Types

enum  { FREE = 0, LOCKED = 1 }
 

Public Member Functions

void init () noexcept
 
bool try_lock () noexcept
 
void lock () noexcept
 
void unlock () noexcept
 

Public Attributes

uint8_t lock_
 

Private Member Functions

std::atomic< uint8_t > * payload () noexcept
 
bool cas (uint8_t compare, uint8_t newVal) noexcept
 

Detailed Description

Definition at line 65 of file MicroSpinLock.h.

Member Enumeration Documentation

anonymous enum
Enumerator
FREE 
LOCKED 

Definition at line 66 of file MicroSpinLock.h.

Member Function Documentation

bool folly::MicroSpinLock::cas ( uint8_t  compare,
uint8_t  newVal 
)
inlineprivatenoexcept

Definition at line 100 of file MicroSpinLock.h.

References payload(), and value.

Referenced by try_lock().

100  {
101  return std::atomic_compare_exchange_strong_explicit(
102  payload(),
103  &compare,
104  newVal,
105  std::memory_order_acquire,
106  std::memory_order_relaxed);
107  }
std::atomic< uint8_t > * payload() noexcept
Definition: MicroSpinLock.h:96
void folly::MicroSpinLock::init ( )
inlinenoexcept

Definition at line 72 of file MicroSpinLock.h.

References FREE, and payload().

Referenced by folly::detail::SkipListNode< T >::SkipListNode(), and folly::SpinLock::SpinLock().

72  {
73  payload()->store(FREE);
74  }
std::atomic< uint8_t > * payload() noexcept
Definition: MicroSpinLock.h:96
void folly::MicroSpinLock::lock ( )
inlinenoexcept

Definition at line 80 of file MicroSpinLock.h.

References deadlock::load(), LOCKED, payload(), try_lock(), and folly::detail::Sleeper::wait().

Referenced by folly::SpinLock::lock(), folly::futures::detail::SpinLock::SpinLock(), and folly::SpinLockGuardImpl< LOCK >::SpinLockGuardImpl().

80  {
81  detail::Sleeper sleeper;
82  while (!try_lock()) {
83  do {
84  sleeper.wait();
85  } while (payload()->load(std::memory_order_relaxed) == LOCKED);
86  }
87  assert(payload()->load() == LOCKED);
88  }
std::atomic< uint8_t > * payload() noexcept
Definition: MicroSpinLock.h:96
def load()
Definition: deadlock.py:441
bool try_lock() noexcept
Definition: MicroSpinLock.h:76
std::atomic<uint8_t>* folly::MicroSpinLock::payload ( )
inlineprivatenoexcept

Definition at line 96 of file MicroSpinLock.h.

References lock_.

Referenced by cas(), init(), lock(), and unlock().

96  {
97  return reinterpret_cast<std::atomic<uint8_t>*>(&this->lock_);
98  }
bool folly::MicroSpinLock::try_lock ( )
inlinenoexcept

Definition at line 76 of file MicroSpinLock.h.

References cas(), FREE, and LOCKED.

Referenced by lock(), and folly::SpinLock::try_lock().

76  {
77  return cas(FREE, LOCKED);
78  }
bool cas(uint8_t compare, uint8_t newVal) noexcept
void folly::MicroSpinLock::unlock ( )
inlinenoexcept

Definition at line 90 of file MicroSpinLock.h.

References FREE, deadlock::load(), LOCKED, and payload().

Referenced by folly::futures::detail::SpinLock::SpinLock(), folly::SpinLock::unlock(), and folly::SpinLockGuardImpl< LOCK >::~SpinLockGuardImpl().

90  {
91  assert(payload()->load() == LOCKED);
92  payload()->store(FREE, std::memory_order_release);
93  }
std::atomic< uint8_t > * payload() noexcept
Definition: MicroSpinLock.h:96
def load()
Definition: deadlock.py:441

Member Data Documentation

uint8_t folly::MicroSpinLock::lock_

Definition at line 68 of file MicroSpinLock.h.

Referenced by payload().


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