proxygen
folly::AtomicLinkedList< T > Class Template Reference

#include <AtomicLinkedList.h>

Classes

struct  Wrapper
 

Public Member Functions

 AtomicLinkedList ()
 
 AtomicLinkedList (const AtomicLinkedList &)=delete
 
AtomicLinkedListoperator= (const AtomicLinkedList &)=delete
 
 AtomicLinkedList (AtomicLinkedList &&other) noexcept=default
 
AtomicLinkedListoperator= (AtomicLinkedList &&other)=default
 
 ~AtomicLinkedList ()
 
bool empty () const
 
bool insertHead (T t)
 
template<typename F >
void sweep (F &&func)
 
template<typename F >
void reverseSweep (F &&func)
 

Private Attributes

AtomicIntrusiveLinkedList< Wrapper,&Wrapper::hooklist_
 

Detailed Description

template<class T>
class folly::AtomicLinkedList< T >

A very simple atomic single-linked list primitive.

Usage:

AtomicLinkedList<MyClass> list; list.insert(a); list.sweep([] (MyClass& c) { doSomething(c); }

Definition at line 35 of file AtomicLinkedList.h.

Constructor & Destructor Documentation

template<class T >
folly::AtomicLinkedList< T >::AtomicLinkedList ( )
inline
template<class T >
folly::AtomicLinkedList< T >::AtomicLinkedList ( const AtomicLinkedList< T > &  )
delete
template<class T >
folly::AtomicLinkedList< T >::AtomicLinkedList ( AtomicLinkedList< T > &&  other)
defaultnoexcept
template<class T >
folly::AtomicLinkedList< T >::~AtomicLinkedList ( )
inline

Definition at line 43 of file AtomicLinkedList.h.

References folly::AtomicLinkedList< T >::sweep(), and folly::T.

43  {
44  sweep([](T&&) {});
45  }
folly::std T

Member Function Documentation

template<class T >
bool folly::AtomicLinkedList< T >::empty ( ) const
inline

Definition at line 47 of file AtomicLinkedList.h.

References folly::AtomicLinkedList< T >::list_.

47  {
48  return list_.empty();
49  }
AtomicIntrusiveLinkedList< Wrapper,&Wrapper::hook > list_
template<class T >
bool folly::AtomicLinkedList< T >::insertHead ( T  t)
inline

Atomically insert t at the head of the list.

Returns
True if the inserted element is the only one in the list after the call.

Definition at line 56 of file AtomicLinkedList.h.

References folly::AtomicLinkedList< T >::list_, and folly::gen::move.

56  {
57  auto wrapper = std::make_unique<Wrapper>(std::move(t));
58 
59  return list_.insertHead(wrapper.release());
60  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AtomicIntrusiveLinkedList< Wrapper,&Wrapper::hook > list_
template<class T >
AtomicLinkedList& folly::AtomicLinkedList< T >::operator= ( const AtomicLinkedList< T > &  )
delete
template<class T >
AtomicLinkedList& folly::AtomicLinkedList< T >::operator= ( AtomicLinkedList< T > &&  other)
default
template<class T >
template<typename F >
void folly::AtomicLinkedList< T >::reverseSweep ( F &&  func)
inline

Similar to sweep() but calls func() on elements in LIFO order.

func() is called for all elements in the list at the moment reverseSweep() is called. Unlike sweep() it does not loop to ensure the list is empty at some point after the last invocation. This way callers can reason about the ordering: elements inserted since the last call to reverseSweep() will be provided in LIFO order.

Example: if elements are inserted in the order 1-2-3, the callback is invoked 3-2-1. If the callback moves elements onto a stack, popping off the stack will produce the original insertion order 1-2-3.

Definition at line 90 of file AtomicLinkedList.h.

References folly::AtomicLinkedList< T >::Wrapper::data, folly::AtomicLinkedList< T >::list_, and folly::gen::move.

90  {
91  list_.reverseSweep([&](Wrapper* wrapperPtr) mutable {
92  std::unique_ptr<Wrapper> wrapper(wrapperPtr);
93 
94  func(std::move(wrapper->data));
95  });
96  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AtomicIntrusiveLinkedList< Wrapper,&Wrapper::hook > list_
template<class T >
template<typename F >
void folly::AtomicLinkedList< T >::sweep ( F &&  func)
inline

Repeatedly pops element from head, and calls func() on the removed elements in the order from tail to head. Stops when the list is empty.

Definition at line 68 of file AtomicLinkedList.h.

References folly::AtomicLinkedList< T >::Wrapper::data, folly::AtomicLinkedList< T >::list_, and folly::gen::move.

Referenced by folly::AtomicLinkedList< T >::~AtomicLinkedList().

68  {
69  list_.sweep([&](Wrapper* wrapperPtr) mutable {
70  std::unique_ptr<Wrapper> wrapper(wrapperPtr);
71 
72  func(std::move(wrapper->data));
73  });
74  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AtomicIntrusiveLinkedList< Wrapper,&Wrapper::hook > list_

Member Data Documentation


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