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 #ifndef CHRE_UTIL_INTRUSIVE_LIST_IMPL_H_ 18 #define CHRE_UTIL_INTRUSIVE_LIST_IMPL_H_ 19 20 // IWYU pragma: private 21 #include "chre/util/intrusive_list.h" 22 23 #include "chre/util/container_support.h" 24 25 namespace chre { 26 27 template <typename ElementType> ~IntrusiveList()28IntrusiveList<ElementType>::~IntrusiveList() { 29 IntrusiveListBase::doUnlinkAll(); 30 } 31 32 template <typename ElementType> link_front(ListNode<ElementType> * newNode)33void IntrusiveList<ElementType>::link_front(ListNode<ElementType> *newNode) { 34 return IntrusiveListBase::doLinkFront(&newNode->node); 35 } 36 37 template <typename ElementType> link_back(ListNode<ElementType> * newNode)38void IntrusiveList<ElementType>::link_back(ListNode<ElementType> *newNode) { 39 return IntrusiveListBase::doLinkBack(&newNode->node); 40 } 41 42 template <typename ElementType> front()43ListNode<ElementType> &IntrusiveList<ElementType>::front() { 44 CHRE_ASSERT(mSize > 0); 45 return *reinterpret_cast<ListNode<ElementType> *>(mSentinelNode.next); 46 } 47 48 template <typename ElementType> front()49const ListNode<ElementType> &IntrusiveList<ElementType>::front() const { 50 CHRE_ASSERT(mSize > 0); 51 return *reinterpret_cast<const ListNode<ElementType> *>(mSentinelNode.next); 52 } 53 54 template <typename ElementType> unlink_front()55void IntrusiveList<ElementType>::unlink_front() { 56 CHRE_ASSERT(mSize > 0); 57 IntrusiveListBase::doUnlinkNode(mSentinelNode.next); 58 } 59 60 template <typename ElementType> back()61ListNode<ElementType> &IntrusiveList<ElementType>::back() { 62 CHRE_ASSERT(mSize > 0); 63 return *reinterpret_cast<ListNode<ElementType> *>(mSentinelNode.prev); 64 } 65 66 template <typename ElementType> back()67const ListNode<ElementType> &IntrusiveList<ElementType>::back() const { 68 CHRE_ASSERT(mSize > 0); 69 return *reinterpret_cast<const ListNode<ElementType> *>(mSentinelNode.prev); 70 } 71 72 template <typename ElementType> unlink_back()73void IntrusiveList<ElementType>::unlink_back() { 74 CHRE_ASSERT(mSize > 0); 75 IntrusiveListBase::doUnlinkNode(mSentinelNode.prev); 76 } 77 78 template <typename ElementType> unlink_node(ListNode<ElementType> * node)79void IntrusiveList<ElementType>::unlink_node(ListNode<ElementType> *node) { 80 CHRE_ASSERT(mSize > 0); 81 IntrusiveListBase::doUnlinkNode(&node->node); 82 } 83 84 template <typename ElementType> link_after(ListNode<ElementType> * frontNode,ListNode<ElementType> * newNode)85void IntrusiveList<ElementType>::link_after(ListNode<ElementType> *frontNode, 86 ListNode<ElementType> *newNode) { 87 IntrusiveListBase::doLinkAfter(&frontNode->node, &newNode->node); 88 } 89 90 } // namespace chre 91 92 #endif // CHRE_UTIL_INTRUSIVE_LIST_IMPL_H_ 93