1 //===-- sanitizer_list.h ----------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file contains implementation of a list class to be used by
9 // ThreadSanitizer, etc run-times.
11 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_LIST_H
13 #define SANITIZER_LIST_H
15 #include "sanitizer_internal_defs.h"
17 namespace __sanitizer
{
19 // Intrusive singly-linked list with size(), push_back(), push_front()
20 // pop_front(), append_front() and append_back().
21 // This class should be a POD (so that it can be put into TLS)
22 // and an object with all zero fields should represent a valid empty list.
23 // This class does not have a CTOR, so clear() should be called on all
24 // non-zero-initialized objects before using.
26 struct IntrusiveList
{
27 friend class Iterator
;
34 bool empty() const { return size_
== 0; }
35 uptr
size() const { return size_
; }
37 void push_back(Item
*x
) {
50 void push_front(Item
*x
) {
64 first_
= first_
->next
;
70 Item
*front() { return first_
; }
71 Item
*back() { return last_
; }
73 void append_front(IntrusiveList
<Item
> *l
) {
79 } else if (!l
->empty()) {
80 l
->last_
->next
= first_
;
87 void append_back(IntrusiveList
<Item
> *l
) {
94 last_
->next
= l
->first_
;
101 void CheckConsistency() {
107 for (Item
*i
= first_
; ; i
= i
->next
) {
109 if (i
== last_
) break;
111 CHECK_EQ(size(), count
);
112 CHECK_EQ(last_
->next
, 0);
118 explicit Iterator(IntrusiveList
<Item
> *list
)
119 : list_(list
), current_(list
->first_
) { }
121 Item
*ret
= current_
;
122 if (current_
) current_
= current_
->next
;
125 bool hasNext() const { return current_
!= 0; }
127 IntrusiveList
<Item
> *list_
;
131 // private, don't use directly.
137 } // namespace __sanitizer
139 #endif // SANITIZER_LIST_H