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.

152 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. pplasl.c
  5. Abstract:
  6. This file contains definitions and function prototypes of a per-processor
  7. lookaside list manager.
  8. Author:
  9. Shaun Cox (shaunco) 25-Oct-1999
  10. --*/
  11. #ifndef _PPLASL_H_
  12. #define _PPLASL_H_
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. HANDLE
  17. PplCreatePool(
  18. IN PALLOCATE_FUNCTION Allocate,
  19. IN PFREE_FUNCTION Free,
  20. IN ULONG Flags,
  21. IN SIZE_T Size,
  22. IN ULONG Tag,
  23. IN USHORT Depth
  24. );
  25. VOID
  26. PplDestroyPool(
  27. IN HANDLE PoolHandle
  28. );
  29. __inline
  30. PVOID
  31. FASTCALL
  32. PplAllocate(
  33. IN HANDLE PoolHandle
  34. )
  35. {
  36. PNPAGED_LOOKASIDE_LIST Lookaside;
  37. CCHAR NumberProcessors;
  38. PVOID Entry;
  39. NumberProcessors = KeNumberProcessors;
  40. if (1 == NumberProcessors)
  41. {
  42. goto SingleProcessorCaseOrMissedPerProcessor;
  43. }
  44. // Try first for the per-processor lookaside list.
  45. //
  46. Lookaside = (PNPAGED_LOOKASIDE_LIST)PoolHandle +
  47. KeGetCurrentProcessorNumber() + 1;
  48. Lookaside->L.TotalAllocates += 1;
  49. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  50. if (!Entry)
  51. {
  52. Lookaside->L.AllocateMisses += 1;
  53. SingleProcessorCaseOrMissedPerProcessor:
  54. // We missed on the per-processor lookaside list, (or we're
  55. // running on a single processor machine) so try for
  56. // the overflow lookaside list.
  57. //
  58. Lookaside = (PNPAGED_LOOKASIDE_LIST)PoolHandle;
  59. Lookaside->L.TotalAllocates += 1;
  60. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  61. if (!Entry)
  62. {
  63. Lookaside->L.AllocateMisses += 1;
  64. Entry = (Lookaside->L.Allocate)(
  65. Lookaside->L.Type,
  66. Lookaside->L.Size,
  67. Lookaside->L.Tag);
  68. }
  69. }
  70. return Entry;
  71. }
  72. __inline
  73. VOID
  74. FASTCALL
  75. PplFree(
  76. IN HANDLE PoolHandle,
  77. IN PVOID Entry
  78. )
  79. {
  80. PNPAGED_LOOKASIDE_LIST Lookaside;
  81. CCHAR NumberProcessors;
  82. NumberProcessors = KeNumberProcessors;
  83. if (1 == NumberProcessors)
  84. {
  85. goto SingleProcessorCaseOrMissedPerProcessor;
  86. }
  87. // Try first for the per-processor lookaside list.
  88. //
  89. Lookaside = (PNPAGED_LOOKASIDE_LIST)PoolHandle +
  90. KeGetCurrentProcessorNumber() + 1;
  91. Lookaside->L.TotalFrees += 1;
  92. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth)
  93. {
  94. Lookaside->L.FreeMisses += 1;
  95. SingleProcessorCaseOrMissedPerProcessor:
  96. // We missed on the per-processor lookaside list, (or we're
  97. // running on a single processor machine) so try for
  98. // the overflow lookaside list.
  99. //
  100. Lookaside = (PNPAGED_LOOKASIDE_LIST)PoolHandle;
  101. Lookaside->L.TotalFrees += 1;
  102. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth)
  103. {
  104. Lookaside->L.FreeMisses += 1;
  105. (Lookaside->L.Free)(Entry);
  106. }
  107. else
  108. {
  109. InterlockedPushEntrySList(
  110. &Lookaside->L.ListHead,
  111. (PSINGLE_LIST_ENTRY)Entry);
  112. }
  113. }
  114. else
  115. {
  116. InterlockedPushEntrySList(
  117. &Lookaside->L.ListHead,
  118. (PSINGLE_LIST_ENTRY)Entry);
  119. }
  120. }
  121. #ifdef __cplusplus
  122. }; // extern "C"
  123. #endif
  124. #endif // _PPLASL_H_