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.

120 lines
2.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: freelist.hxx
  7. //
  8. // Contents: CFreeList header
  9. //
  10. // Classes: CFreeList
  11. //
  12. // History: 05-Nov-92 DrewB Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #ifndef __FREELIST_HXX__
  16. #define __FREELIST_HXX__
  17. struct SFreeBlock;
  18. SAFE_DFBASED_PTR(CBasedFreeBlockPtr, SFreeBlock);
  19. struct SFreeBlock
  20. {
  21. CBasedFreeBlockPtr pfbNext;
  22. };
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Class: CFreeList (frl)
  26. //
  27. // Purpose: Maintains a list of free blocks
  28. //
  29. // Interface: See below
  30. //
  31. // History: 05-Nov-92 DrewB Created
  32. //
  33. //----------------------------------------------------------------------------
  34. class CFreeList
  35. {
  36. public:
  37. inline CFreeList(void);
  38. inline ~CFreeList(void);
  39. SCODE Reserve(IMalloc *pMalloc, UINT cBlocks, size_t cbBlock);
  40. inline void *GetReserved(void);
  41. inline void ReturnToReserve(void *pv);
  42. void Unreserve(UINT cBlocks);
  43. private:
  44. CBasedFreeBlockPtr _pfbHead;
  45. };
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Member: CFreeList::CFreeList, public
  49. //
  50. // Synopsis: Constructor
  51. //
  52. // History: 05-Nov-92 DrewB Created
  53. //
  54. //----------------------------------------------------------------------------
  55. inline CFreeList::CFreeList(void)
  56. {
  57. _pfbHead = NULL;
  58. }
  59. //+---------------------------------------------------------------------------
  60. //
  61. // Member: CFreeList::~CFreeList, public
  62. //
  63. // Synopsis: Destructor
  64. //
  65. // History: 05-Nov-92 DrewB Created
  66. //
  67. //----------------------------------------------------------------------------
  68. inline CFreeList::~CFreeList(void)
  69. {
  70. olAssert(_pfbHead == NULL);
  71. }
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Member: CFreeList::GetReserved, public
  75. //
  76. // Synopsis: Returns a reserved block
  77. //
  78. // History: 05-Nov-92 DrewB Created
  79. //
  80. //----------------------------------------------------------------------------
  81. inline void *CFreeList::GetReserved(void)
  82. {
  83. olAssert(_pfbHead != NULL);
  84. void *pv = (void *)BP_TO_P(SFreeBlock *, _pfbHead);
  85. _pfbHead = _pfbHead->pfbNext;
  86. return pv;
  87. }
  88. //+---------------------------------------------------------------------------
  89. //
  90. // Member: CFreeList::ReturnToReserve, public
  91. //
  92. // Synopsis: Puts a block back on the list
  93. //
  94. // History: 09-Nov-92 DrewB Created
  95. //
  96. //----------------------------------------------------------------------------
  97. inline void CFreeList::ReturnToReserve(void *pv)
  98. {
  99. olAssert(pv != NULL);
  100. SFreeBlock *pfb = (SFreeBlock *)pv;
  101. pfb->pfbNext = _pfbHead;
  102. _pfbHead = P_TO_BP(CBasedFreeBlockPtr, pfb);
  103. }
  104. #endif // #ifndef __FREELIST_HXX__