proxygen
folly::detail::SkipListNode< T > Class Template Reference

#include <ConcurrentSkipList-inl.h>

Inheritance diagram for folly::detail::SkipListNode< T >:

Classes

struct  DestroyIsNoOp
 

Public Types

typedef T value_type
 

Public Member Functions

SkipListNodecopyHead (SkipListNode *node)
 
SkipListNodeskip (int layer) const
 
SkipListNodenext ()
 
void setSkip (uint8_t h, SkipListNode *next)
 
value_typedata ()
 
const value_typedata () const
 
int maxLayer () const
 
int height () const
 
std::unique_lock< MicroSpinLockacquireGuard ()
 
bool fullyLinked () const
 
bool markedForRemoval () const
 
bool isHeadNode () const
 
void setIsHeadNode ()
 
void setFullyLinked ()
 
void setMarkedForRemoval ()
 

Static Public Member Functions

template<typename NodeAlloc , typename U , typename = typename std::enable_if<std::is_convertible<U, T>::value>::type>
static SkipListNodecreate (NodeAlloc &alloc, int height, U &&data, bool isHead=false)
 
template<typename NodeAlloc >
static void destroy (NodeAlloc &alloc, SkipListNode *node)
 

Private Types

enum  : uint16_t { IS_HEAD_NODE = 1, MARKED_FOR_REMOVAL = (1 << 1), FULLY_LINKED = (1 << 2) }
 

Private Member Functions

template<typename U >
 SkipListNode (uint8_t height, U &&data, bool isHead)
 
 ~SkipListNode ()
 
uint16_t getFlags () const
 
void setFlags (uint16_t flags)
 

Private Attributes

std::atomic< uint16_tflags_
 
const uint8_t height_
 
MicroSpinLock spinLock_
 
value_type data_
 
std::atomic< SkipListNode * > skip_ [0]
 

Detailed Description

template<typename T>
class folly::detail::SkipListNode< T >

Definition at line 46 of file ConcurrentSkipList-inl.h.

Member Typedef Documentation

template<typename T >
typedef T folly::detail::SkipListNode< T >::value_type

Definition at line 54 of file ConcurrentSkipList-inl.h.

Member Enumeration Documentation

template<typename T >
anonymous enum : uint16_t
private
Enumerator
IS_HEAD_NODE 
MARKED_FOR_REMOVAL 
FULLY_LINKED 

Definition at line 47 of file ConcurrentSkipList-inl.h.

Constructor & Destructor Documentation

template<typename T >
template<typename U >
folly::detail::SkipListNode< T >::SkipListNode ( uint8_t  height,
U &&  data,
bool  isHead 
)
inlineprivate

Definition at line 155 of file ConcurrentSkipList-inl.h.

References folly::detail::SkipListNode< T >::height_, i, folly::MicroSpinLock::init(), folly::detail::SkipListNode< T >::setFlags(), folly::detail::SkipListNode< T >::setIsHeadNode(), folly::detail::SkipListNode< T >::skip_, folly::detail::SkipListNode< T >::spinLock_, and uint8_t.

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

156  : height_(height), data_(std::forward<U>(data)) {
157  spinLock_.init();
158  setFlags(0);
159  if (isHead) {
160  setIsHeadNode();
161  }
162  // need to explicitly init the dynamic atomic pointer array
163  for (uint8_t i = 0; i < height_; ++i) {
164  new (&skip_[i]) std::atomic<SkipListNode*>(nullptr);
165  }
166  }
void init() noexcept
Definition: MicroSpinLock.h:72
std::atomic< SkipListNode * > skip_[0]
template<typename T >
folly::detail::SkipListNode< T >::~SkipListNode ( )
inlineprivate

Definition at line 168 of file ConcurrentSkipList-inl.h.

References folly::detail::SkipListNode< T >::height_, i, folly::detail::SkipListNode< T >::skip_, and uint8_t.

Referenced by folly::detail::SkipListNode< T >::destroy().

168  {
169  for (uint8_t i = 0; i < height_; ++i) {
170  skip_[i].~atomic();
171  }
172  }
std::atomic< SkipListNode * > skip_[0]

Member Function Documentation

template<typename T >
SkipListNode* folly::detail::SkipListNode< T >::copyHead ( SkipListNode< T > *  node)
inline

Definition at line 87 of file ConcurrentSkipList-inl.h.

References folly::detail::SkipListNode< T >::getFlags(), folly::detail::SkipListNode< T >::height_, i, folly::detail::SkipListNode< T >::setFlags(), folly::detail::SkipListNode< T >::setSkip(), folly::detail::SkipListNode< T >::skip(), and uint8_t.

Referenced by folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::growHeight().

87  {
88  DCHECK(node != nullptr && height_ > node->height_);
89  setFlags(node->getFlags());
90  for (uint8_t i = 0; i < node->height_; ++i) {
91  setSkip(i, node->skip(i));
92  }
93  return this;
94  }
void setSkip(uint8_t h, SkipListNode *next)
template<typename T >
template<typename NodeAlloc , typename U , typename = typename std::enable_if<std::is_convertible<U, T>::value>::type>
static SkipListNode* folly::detail::SkipListNode< T >::create ( NodeAlloc &  alloc,
int  height,
U &&  data,
bool  isHead = false 
)
inlinestatic

Definition at line 62 of file ConcurrentSkipList-inl.h.

References folly::detail::SkipListNode< T >::data(), folly::detail::SkipListNode< T >::height(), folly::size(), folly::detail::SkipListNode< T >::SkipListNode(), and uint8_t.

Referenced by folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::addOrGetData(), and folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::growHeight().

62  {
63  DCHECK(height >= 1 && height < 64) << height;
64 
65  size_t size =
66  sizeof(SkipListNode) + height * sizeof(std::atomic<SkipListNode*>);
67  auto storage = std::allocator_traits<NodeAlloc>::allocate(alloc, size);
68  // do placement new
69  return new (storage)
70  SkipListNode(uint8_t(height), std::forward<U>(data), isHead);
71  }
SkipListNode(uint8_t height, U &&data, bool isHead)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
template<typename T >
const value_type& folly::detail::SkipListNode< T >::data ( ) const
inline

Definition at line 118 of file ConcurrentSkipList-inl.h.

References folly::detail::SkipListNode< T >::data_.

118  {
119  return data_;
120  }
template<typename T >
template<typename NodeAlloc >
static void folly::detail::SkipListNode< T >::destroy ( NodeAlloc &  alloc,
SkipListNode< T > *  node 
)
inlinestatic

Definition at line 74 of file ConcurrentSkipList-inl.h.

References folly::detail::SkipListNode< T >::height_, folly::size(), folly::detail::SkipListNode< T >::SkipListNode(), and folly::detail::SkipListNode< T >::~SkipListNode().

Referenced by folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::growHeight(), and folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::~ConcurrentSkipList().

74  {
75  size_t size = sizeof(SkipListNode) +
76  node->height_ * sizeof(std::atomic<SkipListNode*>);
77  node->~SkipListNode();
78  std::allocator_traits<NodeAlloc>::deallocate(alloc, node, size);
79  }
SkipListNode(uint8_t height, U &&data, bool isHead)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
template<typename T >
int folly::detail::SkipListNode< T >::maxLayer ( ) const
inline
template<typename T >
SkipListNode* folly::detail::SkipListNode< T >::next ( )
inline

Definition at line 102 of file ConcurrentSkipList-inl.h.

References folly::detail::SkipListNode< T >::markedForRemoval(), and folly::detail::SkipListNode< T >::skip().

Referenced by folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::Accessor::begin().

102  {
103  SkipListNode* node;
104  for (node = skip(0); (node != nullptr && node->markedForRemoval());
105  node = node->skip(0)) {
106  }
107  return node;
108  }
SkipListNode(uint8_t height, U &&data, bool isHead)
SkipListNode * skip(int layer) const
template<typename T >
void folly::detail::SkipListNode< T >::setSkip ( uint8_t  h,
SkipListNode< T > *  next 
)
inline

Member Data Documentation

template<typename T >
value_type folly::detail::SkipListNode< T >::data_
private

Definition at line 189 of file ConcurrentSkipList-inl.h.

Referenced by folly::detail::SkipListNode< T >::data().

template<typename T >
std::atomic<uint16_t> folly::detail::SkipListNode< T >::flags_
private

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