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.

200 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1996,1997 Microsoft Corporation
  3. Module Name:
  4. SENDPOOL.C
  5. Abstract:
  6. Manages pool of send descriptors.
  7. Author:
  8. Aaron Ogus (aarono)
  9. Environment:
  10. Win32
  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. // Send Descriptor Management.
  27. //
  28. PSEND pSendDescPool=NULL;
  29. UINT nSendDescsAllocated=0; // Number Allocated
  30. UINT nSendDescsInUse=0; // Number currently in use
  31. UINT nMaxSendDescsInUse=0; // Maximum number in use since last TICK.
  32. CRITICAL_SECTION SendDescLock;
  33. VOID InitSendDescs(VOID)
  34. {
  35. InitializeCriticalSection(&SendDescLock);
  36. }
  37. VOID FiniSendDescs(VOID)
  38. {
  39. PSEND pSend;
  40. ASSERT(nSendDescsInUse==0);
  41. while(pSendDescPool){
  42. pSend=pSendDescPool;
  43. ASSERT_SIGN(pSend, SEND_SIGN);
  44. pSendDescPool=pSendDescPool->pNext;
  45. CloseHandle(pSend->hEvent);
  46. DeleteCriticalSection(&pSend->SendLock);
  47. My_GlobalFree(pSend);
  48. nSendDescsAllocated--;
  49. }
  50. ASSERT(nSendDescsAllocated==0);
  51. DeleteCriticalSection(&SendDescLock);
  52. }
  53. PSEND GetSendDesc(VOID)
  54. {
  55. PSEND pSend;
  56. Lock(&SendDescLock);
  57. if(!pSendDescPool){
  58. Unlock(&SendDescLock);
  59. pSend=(PSEND)My_GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, sizeof(SEND));
  60. if(pSend){
  61. if(!(pSend->hEvent=CreateEventA(NULL, FALSE, FALSE, NULL))){
  62. My_GlobalFree(pSend);
  63. goto exit;
  64. }
  65. InitBilink(&pSend->StatList);
  66. InitializeCriticalSection(&pSend->SendLock);
  67. }
  68. Lock(&SendDescLock);
  69. if(pSend){
  70. SET_SIGN(pSend,SEND_SIGN);
  71. nSendDescsAllocated++;
  72. }
  73. } else {
  74. pSend=pSendDescPool;
  75. ASSERT_SIGN(pSend, SEND_SIGN);
  76. pSendDescPool=pSendDescPool->pNext;
  77. }
  78. if(pSend){
  79. InitBilink(&pSend->TimeoutList);
  80. InitBilink(&pSend->m_GSendQ);
  81. InitBilink(&pSend->SendQ);
  82. nSendDescsInUse++;
  83. if( nSendDescsInUse > nMaxSendDescsInUse ){
  84. nMaxSendDescsInUse = nSendDescsInUse;
  85. }
  86. }
  87. ASSERT(nSendDescsAllocated >= nSendDescsInUse);
  88. Unlock(&SendDescLock);
  89. if(pSend){
  90. pSend->NACKMask=0;
  91. pSend->bCleaningUp=FALSE;
  92. }
  93. exit:
  94. return pSend;
  95. }
  96. VOID ReleaseSendDesc(PSEND pSend)
  97. {
  98. PSENDSTAT pStat;
  99. BILINK *pBilink;
  100. // Dump extra statistics.
  101. while(!EMPTY_BILINK(&pSend->StatList)){
  102. pBilink=pSend->StatList.next;
  103. pStat=CONTAINING_RECORD(pBilink, SENDSTAT, StatList);
  104. Delete(pBilink);
  105. ReleaseSendStat(pStat);
  106. }
  107. Lock(&SendDescLock);
  108. nSendDescsInUse--;
  109. ASSERT(!(nSendDescsInUse&0x80000000));
  110. pSend->pNext=pSendDescPool;
  111. pSendDescPool=pSend;
  112. Unlock(&SendDescLock);
  113. }
  114. #if 0
  115. // let virtual memory handle this. - switched out.
  116. LONG fInSendDescTick=0;
  117. VOID SendDescTick(VOID)
  118. {
  119. PSEND pSend;
  120. #ifdef DEBUG
  121. LONG fLast;
  122. #endif
  123. // Adjusts Number of allocated buffers to
  124. // highwater mark over the last ticks.
  125. // Call once per delta t (around a minute).
  126. DEBUG_BREAK(); //TRACE all paths.
  127. if(!InterlockedExchange(&fInSendDescTick, 1)){
  128. Lock(&SendDescLock);
  129. while((nSendDescsAllocated > nMaxSendDescsInUse) && pSendDescPool){
  130. pSend=pSendDescPool;
  131. ASSERT_SIGN(pSend,SEND_SIGN);
  132. pSendDescPool=pSendDescPool->pNext;
  133. Unlock(&SendDescLock);
  134. CloseHandle(pSend->hEvent);
  135. DeleteCriticalSection(&pSend->SendLock);
  136. My_GlobalFree(pSend);
  137. Lock(&SendDescLock);
  138. nSendDescsAllocated--;
  139. }
  140. nMaxSendDescsInUse=nSendDescsInUse;
  141. ASSERT(nMaxSendDescsInUse <= nSendDescsAllocated);
  142. Unlock(&SendDescLock);
  143. #ifdef DEBUG
  144. fLast=
  145. #endif
  146. InterlockedExchange(&fInSendDescTick, 0);
  147. #ifdef DEBUG
  148. ASSERT(fLast==1);
  149. #endif
  150. }
  151. }
  152. #endif