• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "chre/util/intrusive_list_base.h"
18 
19 #include "chre/util/container_support.h"
20 
21 namespace chre {
22 namespace intrusive_list_internal {
23 
doLinkBack(Node * newNode)24 void IntrusiveListBase::doLinkBack(Node *newNode) {
25   Node *prevNode = mSentinelNode.prev;
26   prevNode->next = newNode;
27   newNode->prev = prevNode;
28   newNode->next = &mSentinelNode;
29   mSentinelNode.prev = newNode;
30   mSize++;
31 }
32 
doUnlinkNode(Node * node)33 void IntrusiveListBase::doUnlinkNode(Node *node) {
34   node->prev->next = node->next;
35   node->next->prev = node->prev;
36   node->next = nullptr;
37   node->prev = nullptr;
38   mSize--;
39 }
40 
doLinkAfter(Node * frontNode,Node * newNode)41 void IntrusiveListBase::doLinkAfter(Node *frontNode, Node *newNode) {
42   Node *backNode = frontNode->next;
43   frontNode->next = newNode;
44   newNode->prev = frontNode;
45   newNode->next = backNode;
46   backNode->prev = newNode;
47   mSize++;
48 }
49 
doUnlinkAll()50 void IntrusiveListBase::doUnlinkAll() {
51   Node *currentNodePtr, *nextNodePtr;
52   currentNodePtr = mSentinelNode.next;
53 
54   while (currentNodePtr != &mSentinelNode) {
55     nextNodePtr = currentNodePtr->next;
56     currentNodePtr->next = nullptr;
57     currentNodePtr->prev = nullptr;
58     currentNodePtr = nextNodePtr;
59   }
60 }
61 
62 }  // namespace intrusive_list_internal
63 }  // namespace chre