queue.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/include/queue.h#1
  3. */
  4. /*! \file queue.h
  5. \brief Definition for singly queue operations.
  6. In this file we define the singly queue data structure and its
  7. queue operation MACROs.
  8. */
  9. #ifndef _QUEUE_H
  10. #define _QUEUE_H
  11. /*******************************************************************************
  12. * C O M P I L E R F L A G S
  13. ********************************************************************************
  14. */
  15. /*******************************************************************************
  16. * E X T E R N A L R E F E R E N C E S
  17. ********************************************************************************
  18. */
  19. #include "gl_typedef.h"
  20. /*******************************************************************************
  21. * C O N S T A N T S
  22. ********************************************************************************
  23. */
  24. /*******************************************************************************
  25. * D A T A T Y P E S
  26. ********************************************************************************
  27. */
  28. /* Singly Queue Structures - Entry Part */
  29. typedef struct _QUE_ENTRY_T {
  30. struct _QUE_ENTRY_T *prNext;
  31. struct _QUE_ENTRY_T *prPrev; /* For Rx buffer reordering used only */
  32. } QUE_ENTRY_T, *P_QUE_ENTRY_T;
  33. /* Singly Queue Structures - Queue Part */
  34. typedef struct _QUE_T {
  35. P_QUE_ENTRY_T prHead;
  36. P_QUE_ENTRY_T prTail;
  37. UINT_32 u4NumElem;
  38. } QUE_T, *P_QUE_T;
  39. /*******************************************************************************
  40. * P U B L I C D A T A
  41. ********************************************************************************
  42. */
  43. /*******************************************************************************
  44. * P R I V A T E D A T A
  45. ********************************************************************************
  46. */
  47. /*******************************************************************************
  48. * M A C R O S
  49. ********************************************************************************
  50. */
  51. #define MAXNUM_TDLS_PEER 4
  52. #define QUEUE_INITIALIZE(prQueue) \
  53. { \
  54. (prQueue)->prHead = (P_QUE_ENTRY_T)NULL; \
  55. (prQueue)->prTail = (P_QUE_ENTRY_T)NULL; \
  56. (prQueue)->u4NumElem = 0; \
  57. }
  58. #define QUEUE_IS_EMPTY(prQueue) (((P_QUE_T)(prQueue))->prHead == (P_QUE_ENTRY_T)NULL)
  59. #define QUEUE_IS_NOT_EMPTY(prQueue) ((prQueue)->u4NumElem > 0)
  60. #define QUEUE_GET_HEAD(prQueue) ((prQueue)->prHead)
  61. #define QUEUE_GET_TAIL(prQueue) ((prQueue)->prTail)
  62. #define QUEUE_GET_NEXT_ENTRY(prQueueEntry) ((prQueueEntry)->prNext)
  63. #define QUEUE_INSERT_HEAD(prQueue, prQueueEntry) \
  64. { \
  65. ASSERT(prQueue); \
  66. ASSERT(prQueueEntry); \
  67. (prQueueEntry)->prNext = (prQueue)->prHead; \
  68. (prQueue)->prHead = (prQueueEntry); \
  69. if ((prQueue)->prTail == (P_QUE_ENTRY_T)NULL) { \
  70. (prQueue)->prTail = (prQueueEntry); \
  71. } \
  72. ((prQueue)->u4NumElem)++; \
  73. }
  74. #define QUEUE_INSERT_TAIL(prQueue, prQueueEntry) \
  75. { \
  76. ASSERT(prQueue); \
  77. ASSERT(prQueueEntry); \
  78. (prQueueEntry)->prNext = (P_QUE_ENTRY_T)NULL; \
  79. if ((prQueue)->prTail) { \
  80. ((prQueue)->prTail)->prNext = (prQueueEntry); \
  81. } else { \
  82. (prQueue)->prHead = (prQueueEntry); \
  83. } \
  84. (prQueue)->prTail = (prQueueEntry); \
  85. ((prQueue)->u4NumElem)++; \
  86. }
  87. /* NOTE: We assume the queue entry located at the beginning of "prQueueEntry Type",
  88. * so that we can cast the queue entry to other data type without doubts.
  89. * And this macro also decrease the total entry count at the same time.
  90. */
  91. #define QUEUE_REMOVE_HEAD(prQueue, prQueueEntry, _P_TYPE) \
  92. { \
  93. ASSERT(prQueue); \
  94. prQueueEntry = (_P_TYPE)((prQueue)->prHead); \
  95. if (prQueueEntry) { \
  96. (prQueue)->prHead = ((P_QUE_ENTRY_T)(prQueueEntry))->prNext; \
  97. if ((prQueue)->prHead == (P_QUE_ENTRY_T)NULL) { \
  98. (prQueue)->prTail = (P_QUE_ENTRY_T)NULL; \
  99. } \
  100. ((P_QUE_ENTRY_T)(prQueueEntry))->prNext = (P_QUE_ENTRY_T)NULL; \
  101. ((prQueue)->u4NumElem)--; \
  102. } \
  103. }
  104. #define QUEUE_MOVE_ALL(prDestQueue, prSrcQueue) \
  105. { \
  106. ASSERT(prDestQueue); \
  107. ASSERT(prSrcQueue); \
  108. *(P_QUE_T)prDestQueue = *(P_QUE_T)prSrcQueue; \
  109. QUEUE_INITIALIZE(prSrcQueue); \
  110. }
  111. #define QUEUE_CONCATENATE_QUEUES(prDestQueue, prSrcQueue) \
  112. { \
  113. ASSERT(prDestQueue); \
  114. ASSERT(prSrcQueue); \
  115. if (prSrcQueue->u4NumElem > 0) { \
  116. if ((prDestQueue)->prTail) { \
  117. ((prDestQueue)->prTail)->prNext = (prSrcQueue)->prHead; \
  118. } else { \
  119. (prDestQueue)->prHead = (prSrcQueue)->prHead; \
  120. } \
  121. (prDestQueue)->prTail = (prSrcQueue)->prTail; \
  122. ((prDestQueue)->u4NumElem) += ((prSrcQueue)->u4NumElem); \
  123. QUEUE_INITIALIZE(prSrcQueue); \
  124. } \
  125. }
  126. #define QUEUE_CONCATENATE_QUEUES_HEAD(prDestQueue, prSrcQueue) \
  127. { \
  128. ASSERT(prDestQueue); \
  129. ASSERT(prSrcQueue); \
  130. if (prSrcQueue->u4NumElem > 0) { \
  131. ((prSrcQueue)->prTail)->prNext = (prDestQueue)->prHead; \
  132. (prDestQueue)->prHead = (prSrcQueue)->prHead; \
  133. ((prDestQueue)->u4NumElem) += ((prSrcQueue)->u4NumElem); \
  134. if ((prDestQueue)->prTail == NULL) { \
  135. (prDestQueue)->prTail = (prSrcQueue)->prTail; \
  136. } \
  137. QUEUE_INITIALIZE(prSrcQueue); \
  138. } \
  139. }
  140. /*******************************************************************************
  141. * E X T E R N A L D A T A
  142. ********************************************************************************
  143. */
  144. extern UINT_8 g_arTdlsLink[MAXNUM_TDLS_PEER];
  145. /*******************************************************************************
  146. * F U N C T I O N D E C L A R A T I O N S
  147. ********************************************************************************
  148. */
  149. /*******************************************************************************
  150. * F U N C T I O N S
  151. ********************************************************************************
  152. */
  153. #endif /* _QUEUE_H */