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.

199 lines
3.7 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. pSend->NACKMask=0;
  90. pSend->bCleaningUp=FALSE;
  91. exit:
  92. return pSend;
  93. }
  94. VOID ReleaseSendDesc(PSEND pSend)
  95. {
  96. PSENDSTAT pStat;
  97. BILINK *pBilink;
  98. // Dump extra statistics.
  99. while(!EMPTY_BILINK(&pSend->StatList)){
  100. //BUGBUG: move stats to end.
  101. pBilink=pSend->StatList.next;
  102. pStat=CONTAINING_RECORD(pBilink, SENDSTAT, StatList);
  103. Delete(pBilink);
  104. ReleaseSendStat(pStat);
  105. }
  106. Lock(&SendDescLock);
  107. nSendDescsInUse--;
  108. ASSERT(!(nSendDescsInUse&0x80000000));
  109. pSend->pNext=pSendDescPool;
  110. pSendDescPool=pSend;
  111. Unlock(&SendDescLock);
  112. }
  113. #if 0
  114. // let virtual memory handle this. - switched out.
  115. LONG fInSendDescTick=0;
  116. VOID SendDescTick(VOID)
  117. {
  118. PSEND pSend;
  119. #ifdef DEBUG
  120. LONG fLast;
  121. #endif
  122. // Adjusts Number of allocated buffers to
  123. // highwater mark over the last ticks.
  124. // Call once per delta t (around a minute).
  125. DEBUG_BREAK(); //TRACE all paths.
  126. if(!InterlockedExchange(&fInSendDescTick, 1)){
  127. Lock(&SendDescLock);
  128. while((nSendDescsAllocated > nMaxSendDescsInUse) && pSendDescPool){
  129. pSend=pSendDescPool;
  130. ASSERT_SIGN(pSend,SEND_SIGN);
  131. pSendDescPool=pSendDescPool->pNext;
  132. Unlock(&SendDescLock);
  133. CloseHandle(pSend->hEvent);
  134. DeleteCriticalSection(&pSend->SendLock);
  135. My_GlobalFree(pSend);
  136. Lock(&SendDescLock);
  137. nSendDescsAllocated--;
  138. }
  139. nMaxSendDescsInUse=nSendDescsInUse;
  140. ASSERT(nMaxSendDescsInUse <= nSendDescsAllocated);
  141. Unlock(&SendDescLock);
  142. #ifdef DEBUG
  143. fLast=
  144. #endif
  145. InterlockedExchange(&fInSendDescTick, 0);
  146. #ifdef DEBUG
  147. ASSERT(fLast==1);
  148. #endif
  149. }
  150. }
  151. #endif