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.

166 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. STATPOOL.CPP
  5. Abstract:
  6. Maintains pool of Stat structures.
  7. Author:
  8. Aaron Ogus (aarono)
  9. Environment:
  10. Win32/COM
  11. Revision History:
  12. Date Author Description
  13. ======= ====== ============================================================
  14. 1/30/97 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. PSENDSTAT pSendStatPool=NULL;
  26. UINT nSendStatsAllocated=0; // Number Allocated
  27. UINT nSendStatsInUse=0; // Number currently in use
  28. UINT nMaxSendStatsInUse=0; // Maximum number in use since last TICK.
  29. CRITICAL_SECTION SendStatLock;
  30. VOID InitSendStats(VOID)
  31. {
  32. InitializeCriticalSection(&SendStatLock);
  33. }
  34. VOID FiniSendStats(VOID)
  35. {
  36. PSENDSTAT pSendStat;
  37. ASSERT(nSendStatsInUse==0);
  38. while(pSendStatPool){
  39. pSendStat=pSendStatPool;
  40. ASSERT_SIGN(pSendStat, SENDSTAT_SIGN);
  41. pSendStatPool=pSendStatPool->pNext;
  42. My_GlobalFree(pSendStat);
  43. nSendStatsAllocated--;
  44. }
  45. ASSERT(nSendStatsAllocated==0);
  46. DeleteCriticalSection(&SendStatLock);
  47. }
  48. PSENDSTAT GetSendStat(VOID)
  49. {
  50. PSENDSTAT pSendStat;
  51. Lock(&SendStatLock);
  52. if(!pSendStatPool){
  53. Unlock(&SendStatLock);
  54. pSendStat=(PSENDSTAT)My_GlobalAlloc(GMEM_FIXED, sizeof(SENDSTAT));
  55. Lock(&SendStatLock);
  56. if(pSendStat){
  57. SET_SIGN(pSendStat,SENDSTAT_SIGN);
  58. nSendStatsAllocated++;
  59. }
  60. } else {
  61. pSendStat=pSendStatPool;
  62. ASSERT_SIGN(pSendStat, SENDSTAT_SIGN);
  63. pSendStatPool=pSendStatPool->pNext;
  64. }
  65. if(pSendStat){
  66. nSendStatsInUse++;
  67. if( nSendStatsInUse > nMaxSendStatsInUse ){
  68. nMaxSendStatsInUse = nSendStatsInUse;
  69. }
  70. }
  71. ASSERT(nSendStatsAllocated >= nSendStatsInUse);
  72. Unlock(&SendStatLock);
  73. return pSendStat;
  74. }
  75. VOID ReleaseSendStat(PSENDSTAT pSendStat)
  76. {
  77. Lock(&SendStatLock);
  78. nSendStatsInUse--;
  79. ASSERT(!(nSendStatsInUse&0x80000000));
  80. pSendStat->pNext=pSendStatPool;
  81. pSendStatPool=pSendStat;
  82. Unlock(&SendStatLock);
  83. }
  84. #if 0
  85. // let virtual memory handle this.
  86. LONG fInSendStatTick=0;
  87. VOID SendStatTick(VOID)
  88. {
  89. PSENDSTAT pSendStat;
  90. #ifdef DEBUG
  91. LONG fLast;
  92. #endif
  93. // Adjusts Number of allocated buffers to
  94. // highwater mark over the last ticks.
  95. // Call once per delta t (around a minute).
  96. DEBUG_BREAK(); //TRACE all paths.
  97. if(!InterlockedExchange(&fInSendStatTick, 1)){
  98. Lock(&SendStatLock);
  99. while((nSendStatsAllocated > nMaxSendStatsInUse) && pSendStatPool){
  100. pSendStat=pSendStatPool;
  101. ASSERT_SIGN(pSendStat,SENDSTAT_SIGN);
  102. pSendStatPool=pSendStatPool->pNext;
  103. Unlock(&SendStatLock);
  104. My_GlobalFree(pSendStat);
  105. Lock(&SendStatLock);
  106. nSendStatsAllocated--;
  107. }
  108. nMaxSendStatsInUse=nSendStatsInUse;
  109. ASSERT(nMaxSendStatsInUse <= nSendStatsAllocated);
  110. Unlock(&SendStatLock);
  111. #ifdef DEBUG
  112. fLast=
  113. #endif
  114. InterlockedExchange(&fInSendStatTick, 0);
  115. #ifdef DEBUG
  116. ASSERT(fLast==1);
  117. #endif
  118. }
  119. }
  120. #endif