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.

104 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: freelist.cxx
  7. //
  8. // Contents: CFreeList implementation
  9. //
  10. // History: 05-Nov-92 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <dfhead.cxx>
  14. #pragma hdrstop
  15. #include <freelist.hxx>
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Member: CFreeList::Reserve, public
  19. //
  20. // Synopsis: Allocates memory for a given number of blocks
  21. //
  22. // Arguments: [pMalloc] - Allocator to use to allocate blocks
  23. // [cBlocks] - Number of blocks to allocate
  24. // [cbBlock] - Block size
  25. //
  26. // Returns: Appropriate status code
  27. //
  28. // History: 05-Nov-92 DrewB Created
  29. // 21-May-93 AlexT Add allocator
  30. //
  31. //----------------------------------------------------------------------------
  32. #ifdef CODESEGMENTS
  33. #pragma code_seg(SEG_CFreeList_Reserve)
  34. #endif
  35. SCODE CFreeList::Reserve(IMalloc *pMalloc, UINT cBlocks, size_t cbBlock)
  36. {
  37. SFreeBlock *pfb;
  38. UINT i;
  39. SCODE sc;
  40. olDebugOut((DEB_ITRACE, "In CFreeList::Reserve:%p(%lu, %u)\n",
  41. this, cBlocks, cbBlock));
  42. olAssert(cbBlock >= sizeof(SFreeBlock));
  43. for (i = 0; i<cBlocks; i++)
  44. {
  45. olMem(pfb = (SFreeBlock *)
  46. CMallocBased::operator new (cbBlock, pMalloc));
  47. pfb->pfbNext = _pfbHead;
  48. _pfbHead = P_TO_BP(CBasedFreeBlockPtr, pfb);
  49. }
  50. olDebugOut((DEB_ITRACE, "Out CFreeList::Reserve\n"));
  51. return S_OK;
  52. EH_Err:
  53. SFreeBlock *pfbT;
  54. for (; i>0; i--)
  55. {
  56. olAssert(_pfbHead != NULL);
  57. pfbT = BP_TO_P(SFreeBlock *, _pfbHead->pfbNext);
  58. delete (CMallocBased *) BP_TO_P(SFreeBlock *, _pfbHead);
  59. _pfbHead = P_TO_BP(CBasedFreeBlockPtr, pfbT);
  60. }
  61. return sc;
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Member: CFreeList::Unreserve, public
  66. //
  67. // Synopsis: Removes N blocks from the list
  68. //
  69. // Arguments: [cBlocks] - Number of blocks to free
  70. //
  71. // History: 05-Nov-92 DrewB Created
  72. // 21-May-93 AlexT Switch to CMallocBased
  73. //
  74. //----------------------------------------------------------------------------
  75. #ifdef CODESEGMENTS
  76. #pragma code_seg(SEG_CFreeList_Unreserve)
  77. #endif
  78. void CFreeList::Unreserve(UINT cBlocks)
  79. {
  80. SFreeBlock *pfbT;
  81. olDebugOut((DEB_ITRACE, "In CFreeList::Unreserve:%p(%lu)\n",
  82. this, cBlocks));
  83. for (; cBlocks>0; cBlocks--)
  84. {
  85. olAssert(_pfbHead != NULL);
  86. pfbT = BP_TO_P(SFreeBlock *, _pfbHead->pfbNext);
  87. delete (CMallocBased *) BP_TO_P(SFreeBlock *, _pfbHead);
  88. _pfbHead = P_TO_BP(CBasedFreeBlockPtr, pfbT);
  89. }
  90. olDebugOut((DEB_ITRACE, "Out CFreeList::Unreserve\n"));
  91. }