5 #ifndef V8_BASE_THREADED_LIST_H_ 6 #define V8_BASE_THREADED_LIST_H_ 10 #include "src/base/compiler-specific.h" 11 #include "src/base/macros.h" 18 static T** next(
T* t) {
return t->next(); }
19 static T** start(
T** t) {
return t; }
20 static T*
const* start(
T*
const* t) {
return t; }
27 template <
typename T,
typename BaseClass,
34 DCHECK_NULL(*TLTraits::next(v));
36 tail_ = TLTraits::next(v);
40 DCHECK_NULL(*TLTraits::next(v));
42 T**
const next = TLTraits::next(v);
45 if (head_ ==
nullptr) tail_ = next;
50 DCHECK_NOT_NULL(head_);
53 head_ = *TLTraits::next(head_);
54 if (head_ ==
nullptr) tail_ = &head_;
55 *TLTraits::next(old_head) =
nullptr;
59 for (
Iterator it = begin(); it != end(); ++it) {
60 if (*it == v)
return true;
66 if (list.is_empty())
return;
74 if (list.head_ ==
nullptr)
return;
76 T* new_head = list.head_;
78 if (head_ ==
nullptr) {
92 tail_ = other.head_ ? other.tail_ : &head_;
100 : head_(other.head_),
101 tail_(other.head_ ? other.tail_ : &head_) {
108 T* current = first();
114 while (current !=
nullptr) {
115 T* next = *TLTraits::next(current);
117 *TLTraits::next(current) = *TLTraits::next(next);
118 *TLTraits::next(next) =
nullptr;
120 if (TLTraits::next(next) == tail_) {
121 tail_ = TLTraits::next(current);
132 using iterator_category = std::forward_iterator_tag;
133 using difference_type = std::ptrdiff_t;
134 using value_type = T*;
135 using reference = value_type;
136 using pointer = value_type*;
140 entry_ = TLTraits::next(*entry_);
143 bool operator==(
const Iterator& other)
const {
144 return entry_ == other.entry_;
146 bool operator!=(
const Iterator& other)
const {
147 return entry_ != other.entry_;
149 T*& operator*() {
return *entry_; }
150 T* operator->() {
return *entry_; }
152 T* next = *TLTraits::next(*entry_);
153 *TLTraits::next(entry) = next;
161 explicit Iterator(T** entry) : entry_(entry) {}
170 using iterator_category = std::forward_iterator_tag;
171 using difference_type = std::ptrdiff_t;
178 entry_ = TLTraits::next(*entry_);
182 return entry_ == other.entry_;
185 return entry_ != other.entry_;
187 const T* operator*()
const {
return *entry_; }
198 Iterator end() {
return Iterator(tail_); }
200 ConstIterator begin()
const {
return ConstIterator(TLTraits::start(&head_)); }
201 ConstIterator end()
const {
return ConstIterator(tail_); }
205 void Rewind(Iterator reset_point) {
206 tail_ = reset_point.entry_;
212 void MoveTail(ThreadedListBase* from_list, Iterator from_location) {
213 if (from_list->end() != from_location) {
215 *tail_ = *from_location;
216 tail_ = from_list->tail_;
217 from_list->Rewind(from_location);
221 bool is_empty()
const {
return head_ ==
nullptr; }
223 T* first()
const {
return head_; }
226 int LengthForTest() {
228 for (Iterator t = begin(); t != end(); ++t) ++result;
232 T* AtForTest(
int i) {
233 Iterator t = begin();
239 T* last = this->first();
240 if (last ==
nullptr) {
241 CHECK_EQ(&head_, tail_);
243 while (*TLTraits::next(last) !=
nullptr) {
244 last = *TLTraits::next(last);
246 CHECK_EQ(TLTraits::next(last), tail_);
254 DISALLOW_COPY_AND_ASSIGN(ThreadedListBase);
259 template <
typename T,
typename TLTraits = ThreadedListTraits<T>>
265 #endif // V8_BASE_THREADED_LIST_H_