proxygen
AtomicLinkedList.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
20 #include <folly/Memory.h>
21 
22 namespace folly {
23 
34 template <class T>
36  public:
38  AtomicLinkedList(const AtomicLinkedList&) = delete;
40  AtomicLinkedList(AtomicLinkedList&& other) noexcept = default;
41  AtomicLinkedList& operator=(AtomicLinkedList&& other) = default;
42 
44  sweep([](T&&) {});
45  }
46 
47  bool empty() const {
48  return list_.empty();
49  }
50 
56  bool insertHead(T t) {
57  auto wrapper = std::make_unique<Wrapper>(std::move(t));
58 
59  return list_.insertHead(wrapper.release());
60  }
61 
67  template <typename F>
68  void sweep(F&& func) {
69  list_.sweep([&](Wrapper* wrapperPtr) mutable {
70  std::unique_ptr<Wrapper> wrapper(wrapperPtr);
71 
72  func(std::move(wrapper->data));
73  });
74  }
75 
89  template <typename F>
90  void reverseSweep(F&& func) {
91  list_.reverseSweep([&](Wrapper* wrapperPtr) mutable {
92  std::unique_ptr<Wrapper> wrapper(wrapperPtr);
93 
94  func(std::move(wrapper->data));
95  });
96  }
97 
98  private:
99  struct Wrapper {
100  explicit Wrapper(T&& t) : data(std::move(t)) {}
101 
104  };
106 };
107 
108 } // namespace folly
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
AtomicIntrusiveLinkedListHook< Wrapper > hook
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
void reverseSweep(F &&func)
AtomicLinkedList & operator=(const AtomicLinkedList &)=delete
AtomicIntrusiveLinkedList< Wrapper,&Wrapper::hook > list_