proxygen
folly::detail::ThreadCachedLists< Tag > Class Template Reference

#include <ThreadCachedLists.h>

Inheritance diagram for folly::detail::ThreadCachedLists< Tag >:
folly::detail::ThreadCachedListsBase

Classes

struct  AtomicListHead
 
struct  ListHead
 
struct  TLHead
 

Public Member Functions

void push (Node *node)
 
void collect (ListHead &list)
 

Private Member Functions

void pushGlobal (ListHead &list)
 

Private Attributes

folly::Synchronized< ListHeadghead_
 
folly::ThreadLocalPtr< TLHead, Taglhead_
 

Detailed Description

template<typename Tag>
class folly::detail::ThreadCachedLists< Tag >

Definition at line 42 of file ThreadCachedLists.h.

Member Function Documentation

template<typename Tag >
void folly::detail::ThreadCachedLists< Tag >::collect ( ListHead list)

Definition at line 143 of file ThreadCachedLists.h.

References folly::detail::ThreadCachedLists< Tag >::ListHead::splice().

Referenced by TEST().

143  {
144  auto acc = lhead_.accessAllThreads();
145 
146  for (auto& thr : acc) {
147  list.splice(thr);
148  }
149 
150  list.splice(*ghead_.wlock());
151 }
folly::ThreadLocalPtr< TLHead, Tag > lhead_
folly::Synchronized< ListHead > ghead_
Encoder::MutableCompressedList list
template<typename Tag >
void folly::detail::ThreadCachedLists< Tag >::push ( Node node)

Definition at line 108 of file ThreadCachedLists.h.

References folly::detail::ThreadCachedListsBase::Node::next_.

Referenced by TEST().

108  {
109  DCHECK(node->next_ == nullptr);
110  static thread_local TLHead* cache_{nullptr};
111 
112  if (!cache_) {
113  auto l = lhead_.get();
114  if (!l) {
115  lhead_.reset(new TLHead(this));
116  l = lhead_.get();
117  DCHECK(l);
118  }
119  cache_ = l;
120  }
121 
122  while (true) {
123  auto head = cache_->head_.load(std::memory_order_relaxed);
124  if (!head) {
125  node->next_ = nullptr;
126  if (cache_->head_.compare_exchange_weak(head, node)) {
127  cache_->tail_.store(node);
128  break;
129  }
130  } else {
131  auto tail = cache_->tail_.load(std::memory_order_relaxed);
132  if (tail) {
133  node->next_ = tail;
134  if (cache_->tail_.compare_exchange_weak(node->next_, node)) {
135  break;
136  }
137  }
138  }
139  }
140 }
folly::ThreadLocalPtr< TLHead, Tag > lhead_
Atom< Node< Atom > * > next_
Definition: HazptrTest.cpp:100
template<typename Tag>
void folly::detail::ThreadCachedLists< Tag >::pushGlobal ( ListHead list)
private

Member Data Documentation

template<typename Tag>
folly::Synchronized<ListHead> folly::detail::ThreadCachedLists< Tag >::ghead_
private
template<typename Tag>
folly::ThreadLocalPtr<TLHead, Tag> folly::detail::ThreadCachedLists< Tag >::lhead_
private

Definition at line 98 of file ThreadCachedLists.h.


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