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 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_LIST_H
15 #define SANITIZER_LIST_H
17 #include "sanitizer_internal_defs.h"
19 namespace __sanitizer
{
21 // Intrusive singly-linked list with size(), push_back(), push_front()
22 // pop_front(), append_front() and append_back().
23 // This class should be a POD (so that it can be put into TLS)
24 // and an object with all zero fields should represent a valid empty list.
25 // This class does not have a CTOR, so clear() should be called on all
26 // non-zero-initialized objects before using.
28 struct IntrusiveList
{
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);
116 // private, don't use directly.
122 } // namespace __sanitizer
124 #endif // SANITIZER_LIST_H