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
{
32 bool empty() const { return size_
== 0; }
33 uptr
size() const { return size_
; }
35 void push_back(Item
*x
) {
48 void push_front(Item
*x
) {
62 first_
= first_
->next
;
68 Item
*front() { return first_
; }
69 Item
*back() { return last_
; }
71 void append_front(IntrusiveList
<Item
> *l
) {
75 } else if (!l
->empty()) {
76 l
->last_
->next
= first_
;
83 void append_back(IntrusiveList
<Item
> *l
) {
88 last_
->next
= l
->first_
;
95 void CheckConsistency() {
101 for (Item
*i
= first_
; ; i
= i
->next
) {
103 if (i
== last_
) break;
105 CHECK_EQ(size(), count
);
106 CHECK_EQ(last_
->next
, 0);
110 // private, don't use directly.
116 } // namespace __sanitizer
118 #endif // SANITIZER_LIST_H