queue.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. /*
  10. ** Log: queue.h
  11. *
  12. * 07 16 2010 cp.wu
  13. *
  14. * [WPD00003833] [MT6620 and MT5931] Driver migration.
  15. * bugfix for SCN migration
  16. * 1) modify QUEUE_CONCATENATE_QUEUES() so it could be used to concatence with an empty queue
  17. * 2) before AIS issues scan request, network(BSS) needs to be activated first
  18. * 3) only invoke COPY_SSID when using specified SSID for scan
  19. *
  20. * 07 08 2010 cp.wu
  21. *
  22. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  23. *
  24. * 06 06 2010 kevin.huang
  25. * [WPD00003832][MT6620 5931] Create driver base
  26. * [MT6620 5931] Create driver base
  27. *
  28. * 04 20 2010 cp.wu
  29. * [WPD00001943]Create WiFi test driver framework on WinXP
  30. * .
  31. ** \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-03-10 20:11:46 GMT mtk01426
  32. ** Init for develop
  33. **
  34. */
  35. #ifndef _QUEUE_H
  36. #define _QUEUE_H
  37. /*******************************************************************************
  38. * C O M P I L E R F L A G S
  39. ********************************************************************************
  40. */
  41. /*******************************************************************************
  42. * E X T E R N A L R E F E R E N C E S
  43. ********************************************************************************
  44. */
  45. #include "gl_typedef.h"
  46. /*******************************************************************************
  47. * C O N S T A N T S
  48. ********************************************************************************
  49. */
  50. /*******************************************************************************
  51. * D A T A T Y P E S
  52. ********************************************************************************
  53. */
  54. /* Singly Queue Structures - Entry Part */
  55. typedef struct _QUE_ENTRY_T {
  56. struct _QUE_ENTRY_T *prNext;
  57. struct _QUE_ENTRY_T *prPrev; /* For Rx buffer reordering used only */
  58. } QUE_ENTRY_T, *P_QUE_ENTRY_T;
  59. /* Singly Queue Structures - Queue Part */
  60. typedef struct _QUE_T {
  61. P_QUE_ENTRY_T prHead;
  62. P_QUE_ENTRY_T prTail;
  63. UINT_32 u4NumElem;
  64. } QUE_T, *P_QUE_T;
  65. /*******************************************************************************
  66. * P U B L I C D A T A
  67. ********************************************************************************
  68. */
  69. /*******************************************************************************
  70. * P R I V A T E D A T A
  71. ********************************************************************************
  72. */
  73. /*******************************************************************************
  74. * M A C R O S
  75. ********************************************************************************
  76. */
  77. /*
  78. * To resolve compiler warning of address check -Waddress
  79. * Redefine a ASSERT dedicate for queue operation
  80. */
  81. #if DBG
  82. #define QUE_ASSERT ASSERT
  83. #else
  84. #define QUE_ASSERT(_exp)
  85. #endif
  86. #define QUEUE_INITIALIZE(prQueue) \
  87. { \
  88. (prQueue)->prHead = (P_QUE_ENTRY_T)NULL; \
  89. (prQueue)->prTail = (P_QUE_ENTRY_T)NULL; \
  90. (prQueue)->u4NumElem = 0; \
  91. }
  92. #define QUEUE_IS_EMPTY(prQueue) (((P_QUE_T)(prQueue))->prHead == (P_QUE_ENTRY_T)NULL)
  93. #define QUEUE_IS_NOT_EMPTY(prQueue) ((prQueue)->u4NumElem > 0)
  94. #define QUEUE_GET_HEAD(prQueue) ((prQueue)->prHead)
  95. #define QUEUE_GET_TAIL(prQueue) ((prQueue)->prTail)
  96. #define QUEUE_GET_NEXT_ENTRY(prQueueEntry) ((prQueueEntry)->prNext)
  97. #define QUEUE_INSERT_HEAD(prQueue, prQueueEntry) \
  98. { \
  99. QUE_ASSERT(prQueue); \
  100. QUE_ASSERT(prQueueEntry); \
  101. (prQueueEntry)->prNext = (prQueue)->prHead; \
  102. (prQueue)->prHead = (prQueueEntry); \
  103. if ((prQueue)->prTail == (P_QUE_ENTRY_T)NULL) { \
  104. (prQueue)->prTail = (prQueueEntry); \
  105. } \
  106. ((prQueue)->u4NumElem)++; \
  107. }
  108. #define QUEUE_INSERT_TAIL(prQueue, prQueueEntry) \
  109. { \
  110. QUE_ASSERT(prQueue); \
  111. QUE_ASSERT(prQueueEntry); \
  112. (prQueueEntry)->prNext = (P_QUE_ENTRY_T)NULL; \
  113. if ((prQueue)->prTail) { \
  114. ((prQueue)->prTail)->prNext = (prQueueEntry); \
  115. } else { \
  116. (prQueue)->prHead = (prQueueEntry); \
  117. } \
  118. (prQueue)->prTail = (prQueueEntry); \
  119. ((prQueue)->u4NumElem)++; \
  120. }
  121. /* NOTE: We assume the queue entry located at the beginning of "prQueueEntry Type",
  122. * so that we can cast the queue entry to other data type without doubts.
  123. * And this macro also decrease the total entry count at the same time.
  124. */
  125. #define QUEUE_REMOVE_HEAD(prQueue, prQueueEntry, _P_TYPE) \
  126. { \
  127. QUE_ASSERT(prQueue); \
  128. prQueueEntry = (_P_TYPE)((prQueue)->prHead); \
  129. if (prQueueEntry) { \
  130. (prQueue)->prHead = ((P_QUE_ENTRY_T)(prQueueEntry))->prNext; \
  131. if ((prQueue)->prHead == (P_QUE_ENTRY_T)NULL) { \
  132. (prQueue)->prTail = (P_QUE_ENTRY_T)NULL; \
  133. } \
  134. ((P_QUE_ENTRY_T)(prQueueEntry))->prNext = (P_QUE_ENTRY_T)NULL; \
  135. ((prQueue)->u4NumElem)--; \
  136. } \
  137. }
  138. #define QUEUE_MOVE_ALL(prDestQueue, prSrcQueue) \
  139. { \
  140. QUE_ASSERT(prDestQueue); \
  141. QUE_ASSERT(prSrcQueue); \
  142. *(P_QUE_T)prDestQueue = *(P_QUE_T)prSrcQueue; \
  143. QUEUE_INITIALIZE(prSrcQueue); \
  144. }
  145. #define QUEUE_CONCATENATE_QUEUES(prDestQueue, prSrcQueue) \
  146. { \
  147. QUE_ASSERT(prDestQueue); \
  148. QUE_ASSERT(prSrcQueue); \
  149. if (prSrcQueue->u4NumElem > 0) { \
  150. if ((prDestQueue)->prTail) { \
  151. ((prDestQueue)->prTail)->prNext = (prSrcQueue)->prHead; \
  152. } else { \
  153. (prDestQueue)->prHead = (prSrcQueue)->prHead; \
  154. } \
  155. (prDestQueue)->prTail = (prSrcQueue)->prTail; \
  156. ((prDestQueue)->u4NumElem) += ((prSrcQueue)->u4NumElem); \
  157. QUEUE_INITIALIZE(prSrcQueue); \
  158. } \
  159. }
  160. /*******************************************************************************
  161. * F U N C T I O N D E C L A R A T I O N S
  162. ********************************************************************************
  163. */
  164. /*******************************************************************************
  165. * F U N C T I O N S
  166. ********************************************************************************
  167. */
  168. #endif /* _QUEUE_H */