]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/sanitizer_common/sanitizer_list.h
1 //===-- sanitizer_list.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains implementation of a list class to be used by
11 // ThreadSanitizer, etc run-times.
13 //===----------------------------------------------------------------------===//
15 #ifndef SANITIZER_LIST_H
16 #define SANITIZER_LIST_H
18 #include "sanitizer_internal_defs.h"
20 namespace __sanitizer
{
22 // Intrusive singly-linked list with size(), push_back(), push_front()
23 // pop_front(), append_front() and append_back().
24 // This class should be a POD (so that it can be put into TLS)
25 // and an object with all zero fields should represent a valid empty list.
26 // This class does not have a CTOR, so clear() should be called on all
27 // non-zero-initialized objects before using.
29 struct IntrusiveList
{
30 friend class Iterator
;
33 first_
= last_
= nullptr;
37 bool empty() const { return size_
== 0; }
38 uptr
size() const { return size_
; }
40 void push_back(Item
*x
) {
53 void push_front(Item
*x
) {
67 first_
= first_
->next
;
73 Item
*front() { return first_
; }
74 Item
*back() { return last_
; }
76 void append_front(IntrusiveList
<Item
> *l
) {
82 } else if (!l
->empty()) {
83 l
->last_
->next
= first_
;
90 void append_back(IntrusiveList
<Item
> *l
) {
97 last_
->next
= l
->first_
;
104 void CheckConsistency() {
110 for (Item
*i
= first_
; ; i
= i
->next
) {
112 if (i
== last_
) break;
114 CHECK_EQ(size(), count
);
115 CHECK_EQ(last_
->next
, 0);
119 template<class ListTy
, class ItemTy
>
122 explicit IteratorBase(ListTy
*list
)
123 : list_(list
), current_(list
->first_
) { }
125 ItemTy
*ret
= current_
;
126 if (current_
) current_
= current_
->next
;
129 bool hasNext() const { return current_
!= nullptr; }
135 typedef IteratorBase
<IntrusiveList
<Item
>, Item
> Iterator
;
136 typedef IteratorBase
<const IntrusiveList
<Item
>, const Item
> ConstIterator
;
138 // private, don't use directly.
144 } // namespace __sanitizer
146 #endif // SANITIZER_LIST_H