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.

136 lines
3.1 KiB

  1. // Copyright (C) 2000, Microsoft Corporation
  2. //
  3. // File: shashiter.c
  4. //
  5. // Contents: Generic hashtable iterator
  6. // Classes:
  7. //
  8. // History: April. 9 2001, Author: Rohanp
  9. //
  10. //-----------------------------------------------------------------------------
  11. #ifdef KERNEL_MODE
  12. #include <ntos.h>
  13. #include <string.h>
  14. #include <fsrtl.h>
  15. #include <zwapi.h>
  16. #include <windef.h>
  17. #else
  18. #include <nt.h>
  19. #include <ntrtl.h>
  20. #include <nturtl.h>
  21. #endif
  22. #include <windows.h>
  23. #include <shash.h>
  24. PSHASH_HEADER
  25. SHashNextEnumerate(
  26. IN PSHASH_ITERATOR pIterator,
  27. IN PSHASH_TABLE pTable)
  28. {
  29. DWORD dwHashVar = 0;
  30. NTSTATUS Status = STATUS_SUCCESS;
  31. void * pData = NULL;
  32. LIST_ENTRY * ple = NULL;
  33. LIST_ENTRY * pListHead = NULL;
  34. PSHASH_HEADER pEntry = NULL;
  35. PSHASH_HEADER pOldEntry = NULL;
  36. BOOLEAN LockAquired = TRUE;
  37. BOOLEAN Found = FALSE;
  38. LockAquired = pTable->ReadLockFunc(pTable);
  39. if(!LockAquired)
  40. {
  41. // dfsdev: why are we not returning status??
  42. Status = STATUS_LOCK_NOT_GRANTED;
  43. return NULL;
  44. }
  45. pOldEntry = pIterator->pEntry;
  46. ple = pIterator->ple->Flink;
  47. for (dwHashVar = pIterator->index; (dwHashVar < pTable->NumBuckets) && (!Found); dwHashVar++)
  48. {
  49. pListHead = &pTable->HashBuckets[dwHashVar].ListHead;
  50. ple = (dwHashVar == pIterator->index) ? pIterator->ple->Flink : pListHead->Flink;
  51. while (ple != pListHead)
  52. {
  53. pEntry = CONTAINING_RECORD(ple, SHASH_HEADER, ListEntry);
  54. if((pEntry->Flags & SHASH_FLAG_DELETE_PENDING) == 0)
  55. {
  56. InterlockedIncrement(&pEntry->RefCount);
  57. pIterator->index = dwHashVar;
  58. pIterator->ple = ple;
  59. pIterator->pEntry = pEntry;
  60. pIterator->pListHead = pListHead;
  61. Found = TRUE;
  62. break;
  63. }
  64. pEntry = NULL;
  65. ple = ple->Flink;
  66. }
  67. }
  68. pTable->ReleaseReadLockFunc(pTable);
  69. if(pOldEntry)
  70. {
  71. Status = SHashReleaseReference( pTable, pOldEntry);
  72. }
  73. if(pEntry == NULL)
  74. {
  75. pIterator->index = 0;
  76. pIterator->ple = NULL;
  77. pIterator->pListHead = NULL;
  78. pIterator->pEntry = NULL;
  79. }
  80. return pEntry;
  81. }
  82. PSHASH_HEADER
  83. SHashStartEnumerate(
  84. IN PSHASH_ITERATOR pIterator,
  85. IN PSHASH_TABLE pTable
  86. )
  87. {
  88. PSHASH_HEADER pEntry = NULL;
  89. pIterator->index = 0;
  90. pIterator->pListHead = &pTable->HashBuckets[0].ListHead;
  91. pIterator->ple = pIterator->pListHead;
  92. pIterator->pEntry = NULL;
  93. pEntry = SHashNextEnumerate( pIterator, pTable);
  94. return pEntry;
  95. }
  96. VOID
  97. SHashFinishEnumerate(
  98. IN PSHASH_ITERATOR pIterator,
  99. IN PSHASH_TABLE pTable
  100. )
  101. {
  102. NTSTATUS Status = STATUS_SUCCESS;
  103. if(pIterator->pEntry)
  104. {
  105. Status = SHashReleaseReference( pTable, pIterator->pEntry);
  106. }
  107. return;
  108. }