-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathintrusive_list.cpp
87 lines (51 loc) · 1.67 KB
/
intrusive_list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
///////////////////////////////////////////////////////////////////////////////
#include <eastl/intrusive_list.h>
namespace eastl
{
EASTL_API void intrusive_list_base::reverse() EASTL_NOEXCEPT
{
intrusive_list_node* pNode = &mAnchor;
do {
intrusive_list_node* const pTemp = pNode->mpNext;
pNode->mpNext = pNode->mpPrev;
pNode->mpPrev = pTemp;
pNode = pNode->mpPrev;
}
while(pNode != &mAnchor);
}
EASTL_API bool intrusive_list_base::validate() const
{
const intrusive_list_node *p = &mAnchor;
const intrusive_list_node *q = p;
// We do two tests below:
//
// 1) Prev and next pointers are symmetric. We check (p->next->prev == p)
// for each node, which is enough to verify all links.
//
// 2) Loop check. We bump the q pointer at one-half rate compared to the
// p pointer; (p == q) if and only if we are at the start (which we
// don't check) or if there is a loop somewhere in the list.
do {
// validate node (even phase)
if (p->mpNext->mpPrev != p)
return false; // broken linkage detected
// bump only fast pointer
p = p->mpNext;
if (p == &mAnchor)
break;
if (p == q)
return false; // loop detected
// validate node (odd phase)
if (p->mpNext->mpPrev != p)
return false; // broken linkage detected
// bump both pointers
p = p->mpNext;
q = q->mpNext;
if (p == q)
return false; // loop detected
} while(p != &mAnchor);
return true;
}
} // namespace eastl