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.

169 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1996,1997 Microsoft Corporation
  3. Module Name:
  4. RCVPOOL.CPP
  5. Abstract:
  6. Manages pool of send descriptors.
  7. Author:
  8. Aaron Ogus (aarono)
  9. Environment:
  10. Win32/COM
  11. Revision History:
  12. Date Author Description
  13. ====== ====== ============================================================
  14. 12/10/96 aarono Original
  15. --*/
  16. #include <windows.h>
  17. #include <mmsystem.h>
  18. #include <dplay.h>
  19. #include <dplaysp.h>
  20. #include <dplaypr.h>
  21. #include "mydebug.h"
  22. #include "arpd.h"
  23. #include "arpdint.h"
  24. #include "macros.h"
  25. //
  26. // Receive Descriptor Management.
  27. //
  28. VOID InitRcvDescs(PPROTOCOL this)
  29. {
  30. this->pRcvDescPool=NULL;
  31. this->nRcvDescsAllocated=0;
  32. this->nRcvDescsInUse=0;
  33. this->nMaxRcvDescsInUse=0;
  34. this->fInRcvDescTick=FALSE;
  35. InitializeCriticalSection(&this->RcvDescLock);
  36. }
  37. VOID FiniRcvDescs(PPROTOCOL this)
  38. {
  39. PRECEIVE pReceive;
  40. ASSERT(this->nRcvDescsInUse==0);
  41. while(this->pRcvDescPool){
  42. pReceive=this->pRcvDescPool;
  43. ASSERT_SIGN(pReceive, RECEIVE_SIGN);
  44. this->pRcvDescPool=this->pRcvDescPool->pNext;
  45. DeleteCriticalSection(&pReceive->ReceiveLock);
  46. My_GlobalFree(pReceive);
  47. this->nRcvDescsAllocated--;
  48. }
  49. ASSERT(this->nRcvDescsAllocated==0);
  50. DeleteCriticalSection(&this->RcvDescLock);
  51. }
  52. PRECEIVE GetRcvDesc(PPROTOCOL this)
  53. {
  54. PRECEIVE pReceive;
  55. Lock(&this->RcvDescLock);
  56. if(!this->pRcvDescPool){
  57. Unlock(&this->RcvDescLock);
  58. pReceive=(PRECEIVE)My_GlobalAlloc(GMEM_FIXED, sizeof(RECEIVE)+this->m_dwSPHeaderSize);
  59. if(pReceive){
  60. SET_SIGN(pReceive,RECEIVE_SIGN);
  61. InitializeCriticalSection(&pReceive->ReceiveLock);
  62. InitBilink(&pReceive->RcvBuffList);
  63. }
  64. Lock(&this->RcvDescLock);
  65. if(pReceive){
  66. this->nRcvDescsAllocated++;
  67. }
  68. } else {
  69. pReceive=this->pRcvDescPool;
  70. ASSERT_SIGN(pReceive, RECEIVE_SIGN);
  71. this->pRcvDescPool=this->pRcvDescPool->pNext;
  72. }
  73. if(pReceive){
  74. this->nRcvDescsInUse++;
  75. if( this->nRcvDescsInUse > this->nMaxRcvDescsInUse ){
  76. this->nMaxRcvDescsInUse = this->nRcvDescsInUse;
  77. }
  78. }
  79. ASSERT(this->nRcvDescsAllocated >= this->nRcvDescsInUse);
  80. Unlock(&this->RcvDescLock);
  81. return pReceive;
  82. }
  83. VOID ReleaseRcvDesc(PPROTOCOL this, PRECEIVE pReceive)
  84. {
  85. Lock(&this->RcvDescLock);
  86. this->nRcvDescsInUse--;
  87. ASSERT(!(this->nRcvDescsInUse&0x80000000));
  88. pReceive->pNext=this->pRcvDescPool;
  89. this->pRcvDescPool=pReceive;
  90. Unlock(&this->RcvDescLock);
  91. }
  92. #if 0
  93. // few enough of these, that we can just let virtual memory handle it. - switched off
  94. VOID RcvDescTick(PPROTOCOL this)
  95. {
  96. PRECEIVE pReceive;
  97. #ifdef DEBUG
  98. LONG fLast;
  99. #endif
  100. // Adjusts Number of allocated buffers to
  101. // highwater mark over the last ticks.
  102. // Call once per delta t (around a minute).
  103. DEBUG_BREAK(); //TRACE all paths.
  104. if(!InterlockedExchange(&this->fInRcvDescTick, 1)){
  105. Lock(&this->RcvDescLock);
  106. while((this->nRcvDescsAllocated > this->nMaxRcvDescsInUse) && this->pRcvDescPool){
  107. pReceive=this->pRcvDescPool;
  108. ASSERT_SIGN(pReceive,RECEIVE_SIGN);
  109. this->pRcvDescPool=this->pRcvDescPool->pNext;
  110. Unlock(&this->RcvDescLock);
  111. DeleteCriticalSection(&pReceive->ReceiveLock);
  112. My_GlobalFree(pReceive);
  113. Lock(&this->RcvDescLock);
  114. this->nRcvDescsAllocated--;
  115. }
  116. this->nMaxRcvDescsInUse=this->nRcvDescsInUse;
  117. ASSERT(this->nMaxRcvDescsInUse <= this->nRcvDescsAllocated);
  118. Unlock(&this->RcvDescLock);
  119. #ifdef DEBUG
  120. fLast=
  121. #endif
  122. InterlockedExchange(&this->fInRcvDescTick, 0);
  123. #ifdef DEBUG
  124. ASSERT(fLast==1);
  125. #endif
  126. }
  127. }
  128. #endif