OLD | NEW |
(Empty) | |
| 1 //------------------------------------------------------------------------------ |
| 2 // <copyright file="dl_list.h" company="Atheros"> |
| 3 // Copyright (c) 2004-2008 Atheros Corporation. All rights reserved. |
| 4 // |
| 5 // This program is free software; you can redistribute it and/or modify |
| 6 // it under the terms of the GNU General Public License version 2 as |
| 7 // published by the Free Software Foundation; |
| 8 // |
| 9 // Software distributed under the License is distributed on an "AS |
| 10 // IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
| 11 // implied. See the License for the specific language governing |
| 12 // rights and limitations under the License. |
| 13 // |
| 14 // |
| 15 //------------------------------------------------------------------------------ |
| 16 //============================================================================== |
| 17 // Double-link list definitions (adapted from Atheros SDIO stack) |
| 18 // |
| 19 // Author(s): ="Atheros" |
| 20 //============================================================================== |
| 21 #ifndef __DL_LIST_H___ |
| 22 #define __DL_LIST_H___ |
| 23 |
| 24 #include "a_osapi.h" |
| 25 |
| 26 #define A_CONTAINING_STRUCT(address, struct_type, field_name)\ |
| 27 ((struct_type *)((A_UINT32)(address) - (A_UINT32)(&((struct_type *)0
)->field_name))) |
| 28 |
| 29 /* list functions */ |
| 30 /* pointers for the list */ |
| 31 typedef struct _DL_LIST { |
| 32 struct _DL_LIST *pPrev; |
| 33 struct _DL_LIST *pNext; |
| 34 }DL_LIST, *PDL_LIST; |
| 35 /* |
| 36 * DL_LIST_INIT , initialize doubly linked list |
| 37 */ |
| 38 #define DL_LIST_INIT(pList)\ |
| 39 {(pList)->pPrev = pList; (pList)->pNext = pList;} |
| 40 |
| 41 /* faster macro to init list and add a single item */ |
| 42 #define DL_LIST_INIT_AND_ADD(pList,pItem) \ |
| 43 { (pList)->pPrev = (pItem); \ |
| 44 (pList)->pNext = (pItem); \ |
| 45 (pItem)->pNext = (pList); \ |
| 46 (pItem)->pPrev = (pList); \ |
| 47 } |
| 48 |
| 49 #define DL_LIST_IS_EMPTY(pList) (((pList)->pPrev == (pList)) && ((pList)->pNext
== (pList))) |
| 50 #define DL_LIST_GET_ITEM_AT_HEAD(pList) (pList)->pNext |
| 51 #define DL_LIST_GET_ITEM_AT_TAIL(pList) (pList)->pPrev |
| 52 /* |
| 53 * ITERATE_OVER_LIST pStart is the list, pTemp is a temp list member |
| 54 * NOT: do not use this function if the items in the list are deleted inside the |
| 55 * iteration loop |
| 56 */ |
| 57 #define ITERATE_OVER_LIST(pStart, pTemp) \ |
| 58 for((pTemp) =(pStart)->pNext; pTemp != (pStart); (pTemp) = (pTemp)->pNext) |
| 59 |
| 60 |
| 61 /* safe iterate macro that allows the item to be removed from the list |
| 62 * the iteration continues to the next item in the list |
| 63 */ |
| 64 #define ITERATE_OVER_LIST_ALLOW_REMOVE(pStart,pItem,st,offset) \ |
| 65 { \ |
| 66 PDL_LIST pTemp; \ |
| 67 pTemp = (pStart)->pNext; \ |
| 68 while (pTemp != (pStart)) { \ |
| 69 (pItem) = A_CONTAINING_STRUCT(pTemp,st,offset); \ |
| 70 pTemp = pTemp->pNext; \ |
| 71 |
| 72 #define ITERATE_END }} |
| 73 |
| 74 /* |
| 75 * DL_ListInsertTail - insert pAdd to the end of the list |
| 76 */ |
| 77 static INLINE PDL_LIST DL_ListInsertTail(PDL_LIST pList, PDL_LIST pAdd) { |
| 78 /* insert at tail */ |
| 79 pAdd->pPrev = pList->pPrev; |
| 80 pAdd->pNext = pList; |
| 81 pList->pPrev->pNext = pAdd; |
| 82 pList->pPrev = pAdd; |
| 83 return pAdd; |
| 84 } |
| 85 |
| 86 /* |
| 87 * DL_ListInsertHead - insert pAdd into the head of the list |
| 88 */ |
| 89 static INLINE PDL_LIST DL_ListInsertHead(PDL_LIST pList, PDL_LIST pAdd) { |
| 90 /* insert at head */ |
| 91 pAdd->pPrev = pList; |
| 92 pAdd->pNext = pList->pNext; |
| 93 pList->pNext->pPrev = pAdd; |
| 94 pList->pNext = pAdd; |
| 95 return pAdd; |
| 96 } |
| 97 |
| 98 #define DL_ListAdd(pList,pItem) DL_ListInsertHead((pList),(pItem)) |
| 99 /* |
| 100 * DL_ListRemove - remove pDel from list |
| 101 */ |
| 102 static INLINE PDL_LIST DL_ListRemove(PDL_LIST pDel) { |
| 103 pDel->pNext->pPrev = pDel->pPrev; |
| 104 pDel->pPrev->pNext = pDel->pNext; |
| 105 /* point back to itself just to be safe, incase remove is called again *
/ |
| 106 pDel->pNext = pDel; |
| 107 pDel->pPrev = pDel; |
| 108 return pDel; |
| 109 } |
| 110 |
| 111 /* |
| 112 * DL_ListRemoveItemFromHead - get a list item from the head |
| 113 */ |
| 114 static INLINE PDL_LIST DL_ListRemoveItemFromHead(PDL_LIST pList) { |
| 115 PDL_LIST pItem = NULL; |
| 116 if (pList->pNext != pList) { |
| 117 pItem = pList->pNext; |
| 118 /* remove the first item from head */ |
| 119 DL_ListRemove(pItem); |
| 120 } |
| 121 return pItem; |
| 122 } |
| 123 |
| 124 static INLINE PDL_LIST DL_ListRemoveItemFromTail(PDL_LIST pList) { |
| 125 PDL_LIST pItem = NULL; |
| 126 if (pList->pPrev != pList) { |
| 127 pItem = pList->pPrev; |
| 128 /* remove the item from tail */ |
| 129 DL_ListRemove(pItem); |
| 130 } |
| 131 return pItem; |
| 132 } |
| 133 |
| 134 /* transfer src list items to the tail of the destination list */ |
| 135 static INLINE void DL_ListTransferItemsToTail(PDL_LIST pDest, PDL_LIST pSrc) { |
| 136 /* only concatenate if src is not empty */ |
| 137 if (!DL_LIST_IS_EMPTY(pSrc)) { |
| 138 /* cut out circular list in src and re-attach to end of dest */ |
| 139 pSrc->pPrev->pNext = pDest; |
| 140 pSrc->pNext->pPrev = pDest->pPrev; |
| 141 pDest->pPrev->pNext = pSrc->pNext; |
| 142 pDest->pPrev = pSrc->pPrev; |
| 143 /* terminate src list, it is now empty */ |
| 144 pSrc->pPrev = pSrc; |
| 145 pSrc->pNext = pSrc; |
| 146 } |
| 147 } |
| 148 |
| 149 #endif /* __DL_LIST_H___ */ |
OLD | NEW |