/kern_oII/drivers/staging/rt2860/link_list.h

http://omnia2droid.googlecode.com/ · C++ Header · 134 lines · 88 code · 20 blank · 26 comment · 17 complexity · b7e2d4f99952c5da23c596744551b2df MD5 · raw file

  1. /*
  2. *************************************************************************
  3. * Ralink Tech Inc.
  4. * 5F., No.36, Taiyuan St., Jhubei City,
  5. * Hsinchu County 302,
  6. * Taiwan, R.O.C.
  7. *
  8. * (c) Copyright 2002-2007, Ralink Technology, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. * This program is distributed in the hope that it will be useful, *
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  18. * GNU General Public License for more details. *
  19. * *
  20. * You should have received a copy of the GNU General Public License *
  21. * along with this program; if not, write to the *
  22. * Free Software Foundation, Inc., *
  23. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  24. * *
  25. *************************************************************************
  26. */
  27. #ifndef __LINK_LIST_H__
  28. #define __LINK_LIST_H__
  29. typedef struct _LIST_ENTRY
  30. {
  31. struct _LIST_ENTRY *pNext;
  32. } LIST_ENTRY, *PLIST_ENTRY;
  33. typedef struct _LIST_HEADR
  34. {
  35. PLIST_ENTRY pHead;
  36. PLIST_ENTRY pTail;
  37. UCHAR size;
  38. } LIST_HEADER, *PLIST_HEADER;
  39. static inline VOID initList(
  40. IN PLIST_HEADER pList)
  41. {
  42. pList->pHead = pList->pTail = NULL;
  43. pList->size = 0;
  44. return;
  45. }
  46. static inline VOID insertTailList(
  47. IN PLIST_HEADER pList,
  48. IN PLIST_ENTRY pEntry)
  49. {
  50. pEntry->pNext = NULL;
  51. if (pList->pTail)
  52. pList->pTail->pNext = pEntry;
  53. else
  54. pList->pHead = pEntry;
  55. pList->pTail = pEntry;
  56. pList->size++;
  57. return;
  58. }
  59. static inline PLIST_ENTRY removeHeadList(
  60. IN PLIST_HEADER pList)
  61. {
  62. PLIST_ENTRY pNext;
  63. PLIST_ENTRY pEntry;
  64. pEntry = pList->pHead;
  65. if (pList->pHead != NULL)
  66. {
  67. pNext = pList->pHead->pNext;
  68. pList->pHead = pNext;
  69. if (pNext == NULL)
  70. pList->pTail = NULL;
  71. pList->size--;
  72. }
  73. return pEntry;
  74. }
  75. static inline int getListSize(
  76. IN PLIST_HEADER pList)
  77. {
  78. return pList->size;
  79. }
  80. static inline PLIST_ENTRY delEntryList(
  81. IN PLIST_HEADER pList,
  82. IN PLIST_ENTRY pEntry)
  83. {
  84. PLIST_ENTRY pCurEntry;
  85. PLIST_ENTRY pPrvEntry;
  86. if(pList->pHead == NULL)
  87. return NULL;
  88. if(pEntry == pList->pHead)
  89. {
  90. pCurEntry = pList->pHead;
  91. pList->pHead = pCurEntry->pNext;
  92. if(pList->pHead == NULL)
  93. pList->pTail = NULL;
  94. pList->size--;
  95. return pCurEntry;
  96. }
  97. pPrvEntry = pList->pHead;
  98. pCurEntry = pPrvEntry->pNext;
  99. while(pCurEntry != NULL)
  100. {
  101. if (pEntry == pCurEntry)
  102. {
  103. pPrvEntry->pNext = pCurEntry->pNext;
  104. if(pEntry == pList->pTail)
  105. pList->pTail = pPrvEntry;
  106. pList->size--;
  107. break;
  108. }
  109. pPrvEntry = pCurEntry;
  110. pCurEntry = pPrvEntry->pNext;
  111. }
  112. return pCurEntry;
  113. }
  114. #endif // ___LINK_LIST_H__ //