Source code of Windows XP (NT5)
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.

113 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. pplasl.cxx
  5. Abstract:
  6. This file contains the implementation of a per-processor lookaside
  7. list manager.
  8. Author:
  9. Shaun Cox (shaunco) 25-Oct-1999
  10. --*/
  11. #include "precomp.h"
  12. HANDLE
  13. PplCreatePool(
  14. IN PALLOCATE_FUNCTION Allocate,
  15. IN PFREE_FUNCTION Free,
  16. IN ULONG Flags,
  17. IN SIZE_T Size,
  18. IN ULONG Tag,
  19. IN USHORT Depth
  20. )
  21. {
  22. HANDLE PoolHandle;
  23. SIZE_T PoolSize;
  24. CCHAR NumberProcessors;
  25. CCHAR NumberLookasideLists;
  26. CCHAR i;
  27. PNPAGED_LOOKASIDE_LIST Lookaside;
  28. NumberProcessors = KeNumberProcessors;
  29. // Allocate room for 1 lookaside list per processor plus 1 extra
  30. // lookaside list for overflow. Only allocate 1 lookaside list if
  31. // we're on a single processor machine.
  32. //
  33. NumberLookasideLists = NumberProcessors;
  34. if (NumberProcessors > 1)
  35. {
  36. NumberLookasideLists++;
  37. }
  38. PoolSize = sizeof(NPAGED_LOOKASIDE_LIST) * NumberLookasideLists;
  39. PoolHandle = ExAllocatePoolWithTag(NonPagedPool, PoolSize, Tag);
  40. if (PoolHandle)
  41. {
  42. for (i = 0, Lookaside = (PNPAGED_LOOKASIDE_LIST)PoolHandle;
  43. i < NumberLookasideLists;
  44. i++, Lookaside++)
  45. {
  46. ExInitializeNPagedLookasideList(
  47. Lookaside,
  48. Allocate,
  49. Free,
  50. Flags,
  51. Size,
  52. Tag,
  53. Depth);
  54. // ExInitializeNPagedLookasideList doesn't really set the
  55. // maximum depth to Depth, so we'll do it here.
  56. //
  57. if (Depth != 0) {
  58. Lookaside->L.MaximumDepth = Depth;
  59. }
  60. }
  61. }
  62. return PoolHandle;
  63. }
  64. VOID
  65. PplDestroyPool(
  66. IN HANDLE PoolHandle
  67. )
  68. {
  69. CCHAR NumberProcessors;
  70. CCHAR NumberLookasideLists;
  71. CCHAR i;
  72. PNPAGED_LOOKASIDE_LIST Lookaside;
  73. if (!PoolHandle)
  74. {
  75. return;
  76. }
  77. NumberProcessors = KeNumberProcessors;
  78. NumberLookasideLists = NumberProcessors;
  79. if (NumberProcessors > 1)
  80. {
  81. NumberLookasideLists++;
  82. }
  83. for (i = 0, Lookaside = (PNPAGED_LOOKASIDE_LIST)PoolHandle;
  84. i < NumberLookasideLists;
  85. i++, Lookaside++)
  86. {
  87. ExDeleteNPagedLookasideList(Lookaside);
  88. }
  89. ExFreePool(PoolHandle);
  90. }