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.

123 lines
2.1 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. //BUGBUG: out of interest track allocated/free buffers.
  52. if(pBufferPoolList){
  53. Lock(&BufferPoolLock);
  54. if(pBufferFreeList){
  55. pBuffer=pBufferFreeList;
  56. pBufferFreeList=pBuffer->pNext;
  57. }
  58. Unlock(&BufferPoolLock);
  59. if(pBuffer){
  60. return pBuffer;
  61. }
  62. }
  63. pBufferPool=(PBUFFER_POOL)My_GlobalAlloc(GMEM_FIXED, sizeof(BUFFER_POOL));
  64. if(pBufferPool){
  65. // link the buffers into a chain.
  66. for(i=0;i<BUFFER_POOL_SIZE-1;i++){
  67. pBufferPool->Buffers[i].pNext=&pBufferPool->Buffers[i+1];
  68. }
  69. Lock(&BufferPoolLock);
  70. // link the pool on the pool list.
  71. pBufferPool->pNext=pBufferPoolList;
  72. pBufferPoolList=pBufferPool;
  73. // link the buffers on the buffer list.
  74. pBufferPool->Buffers[BUFFER_POOL_SIZE-1].pNext=pBufferFreeList;
  75. pBufferFreeList=&pBufferPool->Buffers[0];
  76. Unlock(&BufferPoolLock);
  77. goto Top;
  78. } else {
  79. ASSERT(0); //TRACE ALL PATHS
  80. return NULL;
  81. }
  82. }
  83. VOID FreeBuffer(PBUFFER pBuffer)
  84. {
  85. Lock(&BufferPoolLock);
  86. pBuffer->pNext=pBufferFreeList;
  87. pBufferFreeList=pBuffer;
  88. Unlock(&BufferPoolLock);
  89. }