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.

122 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. BUFPOOL.C
  5. Abstract:
  6. Manages a pool of BUFFER descriptors (BUFFERS)
  7. 16 at a time are allocated. They are not freed until
  8. shutdown.
  9. Author:
  10. Aaron Ogus (aarono)
  11. Environment:
  12. Win32/COM
  13. Revision History:
  14. Date Author Description
  15. ======= ====== ============================================================
  16. 1/27/97 aarono Original
  17. --*/
  18. #include <windows.h>
  19. #include "newdpf.h"
  20. #include <dplay.h>
  21. #include <dplaysp.h>
  22. #include <dplaypr.h>
  23. #include "bufpool.h"
  24. #include "macros.h"
  25. #include "mydebug.h"
  26. CRITICAL_SECTION BufferPoolLock;
  27. PBUFFER_POOL pBufferPoolList;
  28. PBUFFER pBufferFreeList;
  29. VOID InitBufferPool(VOID)
  30. {
  31. pBufferPoolList=NULL;
  32. pBufferFreeList=NULL;
  33. InitializeCriticalSection(&BufferPoolLock);
  34. }
  35. VOID FiniBufferPool(VOID)
  36. {
  37. PBUFFER_POOL pNextBufPool;
  38. while(pBufferPoolList){
  39. pNextBufPool=pBufferPoolList->pNext;
  40. My_GlobalFree(pBufferPoolList);
  41. pBufferPoolList=pNextBufPool;
  42. }
  43. DeleteCriticalSection(&BufferPoolLock);
  44. }
  45. PBUFFER GetBuffer(VOID)
  46. {
  47. PBUFFER pBuffer=NULL;
  48. PBUFFER_POOL pBufferPool;
  49. UINT i;
  50. Top:
  51. if(pBufferPoolList){
  52. Lock(&BufferPoolLock);
  53. if(pBufferFreeList){
  54. pBuffer=pBufferFreeList;
  55. pBufferFreeList=pBuffer->pNext;
  56. }
  57. Unlock(&BufferPoolLock);
  58. if(pBuffer){
  59. return pBuffer;
  60. }
  61. }
  62. pBufferPool=(PBUFFER_POOL)My_GlobalAlloc(GMEM_FIXED, sizeof(BUFFER_POOL));
  63. if(pBufferPool){
  64. // link the buffers into a chain.
  65. for(i=0;i<BUFFER_POOL_SIZE-1;i++){
  66. pBufferPool->Buffers[i].pNext=&pBufferPool->Buffers[i+1];
  67. }
  68. Lock(&BufferPoolLock);
  69. // link the pool on the pool list.
  70. pBufferPool->pNext=pBufferPoolList;
  71. pBufferPoolList=pBufferPool;
  72. // link the buffers on the buffer list.
  73. pBufferPool->Buffers[BUFFER_POOL_SIZE-1].pNext=pBufferFreeList;
  74. pBufferFreeList=&pBufferPool->Buffers[0];
  75. Unlock(&BufferPoolLock);
  76. goto Top;
  77. } else {
  78. ASSERT(0); //TRACE ALL PATHS
  79. return NULL;
  80. }
  81. }
  82. VOID FreeBuffer(PBUFFER pBuffer)
  83. {
  84. Lock(&BufferPoolLock);
  85. pBuffer->pNext=pBufferFreeList;
  86. pBufferFreeList=pBuffer;
  87. Unlock(&BufferPoolLock);
  88. }