Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dlistlck.inl
  6. Abstract:
  7. Double linked list with lock template class.
  8. Author:
  9. Weihai Chen (WeihaiC) 06/29/98
  10. Revision History:
  11. --*/
  12. template <class T, class KEYTYPE>
  13. TDoubleListLock<T, KEYTYPE>::TDoubleListLock<T, KEYTYPE>(void):
  14. m_bValid (FALSE)
  15. {
  16. if (m_pList = new TDoubleList<T, KEYTYPE>) {
  17. if (m_pList->bValid ())
  18. m_bValid = TRUE;
  19. }
  20. }
  21. template <class T, class KEYTYPE>
  22. TDoubleListLock<T, KEYTYPE>::~TDoubleListLock<T, KEYTYPE>(void)
  23. {
  24. TAutoCriticalSection CritSec (m_CritSec);
  25. if (CritSec.bValid ()) {
  26. delete m_pList;
  27. m_pList = NULL;
  28. }
  29. }
  30. template <class T, class KEYTYPE>
  31. BOOL TDoubleListLock<T, KEYTYPE>::InsertItem (T item)
  32. {
  33. BOOL bRet = FALSE;
  34. if (m_bValid) {
  35. TAutoCriticalSection CritSec (m_CritSec);
  36. if (CritSec.bValid ())
  37. bRet = m_pList->InsertItem (item);
  38. }
  39. return bRet;
  40. }
  41. template <class T, class KEYTYPE>
  42. BOOL TDoubleListLock<T, KEYTYPE>::AppendItem (T item)
  43. {
  44. BOOL bRet = FALSE;
  45. if (m_bValid) {
  46. TAutoCriticalSection CritSec (m_CritSec);
  47. if (CritSec.bValid ())
  48. bRet = m_pList->AppendItem (item);
  49. }
  50. return bRet;
  51. }
  52. template <class T, class KEYTYPE>
  53. BOOL TDoubleListLock<T, KEYTYPE>::DeleteItem (T item)
  54. {
  55. BOOL bRet = FALSE;
  56. if (m_bValid) {
  57. Lock();
  58. bRet = m_pList->DeleteItem (item);
  59. Unlock();
  60. }
  61. return FALSE;
  62. }
  63. template <class T, class KEYTYPE>
  64. BOOL TDoubleListLock<T, KEYTYPE>::InsertNode (TDoubleNode<T, KEYTYPE> *pNewNode)
  65. {
  66. BOOL bRet = FALSE;
  67. if (m_bValid) {
  68. TAutoCriticalSection CritSec (m_CritSec);
  69. if (CritSec.bValid ())
  70. bRet = m_pList->InsertNode (pNewNode);
  71. }
  72. return bRet;
  73. }
  74. template <class T, class KEYTYPE>
  75. BOOL TDoubleListLock<T, KEYTYPE>::AppendNode (TDoubleNode<T, KEYTYPE> *pNewNode)
  76. {
  77. BOOL bRet = FALSE;
  78. if (m_bValid) {
  79. TAutoCriticalSection CritSec (m_CritSec);
  80. if (CritSec.bValid ())
  81. bRet = m_pList->AppendNode (pNewNode);
  82. }
  83. return bRet;
  84. }
  85. template <class T, class KEYTYPE>
  86. BOOL TDoubleListLock<T, KEYTYPE>::DeleteNode (TDoubleNode<T, KEYTYPE> *pNode)
  87. {
  88. BOOL bRet = FALSE;
  89. if (pNode && m_bValid) {
  90. TAutoCriticalSection CritSec (m_CritSec);
  91. if (CritSec.bValid ())
  92. bRet = m_pList->DeleteNode (pNode);
  93. }
  94. return bRet;
  95. }
  96. template <class T, class KEYTYPE>
  97. TDoubleNode<T, KEYTYPE> *
  98. TDoubleListLock<T, KEYTYPE>::GetHead (void)
  99. {
  100. TDoubleNode<T, KEYTYPE> * pHead = NULL;
  101. if (m_bValid) {
  102. TAutoCriticalSection CritSec (m_CritSec);
  103. if (CritSec.bValid ())
  104. pHead = m_pList->GetHead ();
  105. }
  106. return pHead;
  107. }
  108. template <class T, class KEYTYPE>
  109. BOOL
  110. TDoubleListLock<T, KEYTYPE>::GetTotalNode (PDWORD pdwCount)
  111. {
  112. BOOL bRet = FALSE;
  113. if (m_bValid) {
  114. TAutoCriticalSection CritSec (m_CritSec);
  115. if (CritSec.bValid ()) {
  116. bRet = m_pList->GetTotalNode (pdwCount);
  117. }
  118. }
  119. return bRet;
  120. }
  121. template <class T, class KEYTYPE>
  122. T TSrchDoubleListLock<T, KEYTYPE>::FindItemFromKey (KEYTYPE key)
  123. {
  124. T pItem = NULL;
  125. if (m_bValid) {
  126. TAutoCriticalSection CritSec (m_CritSec);
  127. if (CritSec.bValid ())
  128. pItem = m_pList->FindItemFromKey (key);
  129. }
  130. return pItem;
  131. }
  132. template <class T, class KEYTYPE>
  133. TDoubleNode<T, KEYTYPE> *
  134. TSrchDoubleListLock<T, KEYTYPE>::FindNodeFromItem (T item)
  135. {
  136. TDoubleNode<T, KEYTYPE> * pNode = NULL;
  137. if (m_bValid) {
  138. TAutoCriticalSection CritSec (m_CritSec);
  139. if (CritSec.bValid ())
  140. pNode = m_pList->FindNodeFromItem (item);
  141. }
  142. return pNode;
  143. }
  144. template <class T, class KEYTYPE>
  145. TDoubleNode<T, KEYTYPE> *
  146. TSrchDoubleListLock<T, KEYTYPE>::FindNodeFromKey (KEYTYPE key)
  147. {
  148. TDoubleNode<T, KEYTYPE> * pNode = NULL;
  149. if (m_bValid) {
  150. TAutoCriticalSection CritSec (m_CritSec);
  151. if (CritSec.bValid ())
  152. pNode = m_pList->FindNodeFromKey (key);
  153. }
  154. return pNode;
  155. }
  156. template <class T, class KEYTYPE>
  157. T TSrchDoubleListLock<T, KEYTYPE>::FindItemFromItem (T item)
  158. {
  159. T pItem = NULL;
  160. if (m_bValid) {
  161. TAutoCriticalSection CritSec (m_CritSec);
  162. if (CritSec.bValid ())
  163. pItem = m_pList->FindItemFromItem (item);
  164. }
  165. return pItem;
  166. }