3 * Double-link list definitions (adapted from Atheros SDIO stack)
5 * Copyright (c) 2007 Atheros Communications Inc.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation;
13 * Software distributed under the License is distributed on an "AS
14 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15 * implied. See the License for the specific language governing
16 * rights and limitations under the License.
21 #ifndef __DL_LIST_H___
22 #define __DL_LIST_H___
24 #define A_CONTAINING_STRUCT(address, struct_type, field_name)\
25 ((struct_type *)((A_UINT32)(address) - (A_UINT32)(&((struct_type *)0)->field_name)))
28 /* pointers for the list */
29 typedef struct _DL_LIST
{
30 struct _DL_LIST
*pPrev
;
31 struct _DL_LIST
*pNext
;
34 * DL_LIST_INIT , initialize doubly linked list
36 #define DL_LIST_INIT(pList)\
37 {(pList)->pPrev = pList; (pList)->pNext = pList;}
39 #define DL_LIST_IS_EMPTY(pList) (((pList)->pPrev == (pList)) && ((pList)->pNext == (pList)))
40 #define DL_LIST_GET_ITEM_AT_HEAD(pList) (pList)->pNext
41 #define DL_LIST_GET_ITEM_AT_TAIL(pList) (pList)->pPrev
43 * ITERATE_OVER_LIST pStart is the list, pTemp is a temp list member
44 * NOT: do not use this function if the items in the list are deleted inside the
47 #define ITERATE_OVER_LIST(pStart, pTemp) \
48 for((pTemp) =(pStart)->pNext; pTemp != (pStart); (pTemp) = (pTemp)->pNext)
51 /* safe iterate macro that allows the item to be removed from the list
52 * the iteration continues to the next item in the list
54 #define ITERATE_OVER_LIST_ALLOW_REMOVE(pStart,pItem,st,offset) \
57 pTemp = (pStart)->pNext; \
58 while (pTemp != (pStart)) { \
59 (pItem) = A_CONTAINING_STRUCT(pTemp,st,offset); \
60 pTemp = pTemp->pNext; \
62 #define ITERATE_END }}
65 * DL_ListInsertTail - insert pAdd to the end of the list
67 static INLINE PDL_LIST
DL_ListInsertTail(PDL_LIST pList
, PDL_LIST pAdd
) {
69 pAdd
->pPrev
= pList
->pPrev
;
71 pList
->pPrev
->pNext
= pAdd
;
77 * DL_ListInsertHead - insert pAdd into the head of the list
79 static INLINE PDL_LIST
DL_ListInsertHead(PDL_LIST pList
, PDL_LIST pAdd
) {
82 pAdd
->pNext
= pList
->pNext
;
83 pList
->pNext
->pPrev
= pAdd
;
88 #define DL_ListAdd(pList,pItem) DL_ListInsertHead((pList),(pItem))
90 * DL_ListRemove - remove pDel from list
92 static INLINE PDL_LIST
DL_ListRemove(PDL_LIST pDel
) {
93 pDel
->pNext
->pPrev
= pDel
->pPrev
;
94 pDel
->pPrev
->pNext
= pDel
->pNext
;
95 /* point back to itself just to be safe, incase remove is called again */
102 * DL_ListRemoveItemFromHead - get a list item from the head
104 static INLINE PDL_LIST
DL_ListRemoveItemFromHead(PDL_LIST pList
) {
105 PDL_LIST pItem
= NULL
;
106 if (pList
->pNext
!= pList
) {
107 pItem
= pList
->pNext
;
108 /* remove the first item from head */
109 DL_ListRemove(pItem
);
114 #endif /* __DL_LIST_H___ */
This page took 0.04965 seconds and 5 git commands to generate.