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.

132 lines
3.1 KiB

  1. //#---------------------------------------------------------------
  2. //
  3. // File: FreeQ.cpp
  4. //
  5. // Synopsis: interface between CPool object and asynctrc.c
  6. //
  7. // Copyright (C) 1995 Microsoft Corporation
  8. // All rights reserved.
  9. //
  10. // Authors: gordm
  11. //
  12. //----------------------------------------------------------------
  13. #define _DBGTRACE_DLL_IMPLEMENTATION
  14. #include <windows.h>
  15. #include <cpool.h>
  16. #include "randfail.h"
  17. #include "traceint.h"
  18. //
  19. // global pointer to CPool to avoid pulling in the C runtime
  20. // to call the con/destrustors
  21. //
  22. CPool* g_pFreePool = NULL;
  23. //+---------------------------------------------------------------
  24. //
  25. // Function: InitTraceBuffers
  26. //
  27. // Synopsis: external "C" function to init the CPool
  28. //
  29. // Arguments: DWORD: Maximum number of pending traces
  30. // DWORD: Increment size for the CPool
  31. //
  32. // Returns: BOOL: successful or not
  33. //
  34. //----------------------------------------------------------------
  35. BOOL WINAPI InitTraceBuffers( DWORD dwThresholdCount, DWORD dwIncrement )
  36. {
  37. g_pFreePool = new CPool( TRACE_SIGNATURE );
  38. return g_pFreePool != NULL &&
  39. g_pFreePool->ReserveMemory( dwThresholdCount,
  40. sizeof(TRACEBUF),
  41. dwIncrement );
  42. }
  43. //+---------------------------------------------------------------
  44. //
  45. // Function: TermTraceBuffers
  46. //
  47. // Synopsis: cleanup
  48. //
  49. // Arguments: void
  50. //
  51. // Returns: void
  52. //
  53. //----------------------------------------------------------------
  54. void WINAPI TermTraceBuffers( void )
  55. {
  56. CPool* pPool = (CPool*)InterlockedExchangePointer((void**)&g_pFreePool, NULL );
  57. if ( pPool != NULL )
  58. {
  59. pPool->ReleaseMemory();
  60. delete pPool;
  61. }
  62. }
  63. //+---------------------------------------------------------------
  64. //
  65. // Function: GetTraceBuffer
  66. //
  67. // Synopsis: external "C" function to get a CPool buffer
  68. //
  69. // Arguments: void
  70. //
  71. // Returns: LPTRACEBUF: allocated buffer
  72. //
  73. //----------------------------------------------------------------
  74. LPTRACEBUF WINAPI GetTraceBuffer( void )
  75. {
  76. LPTRACEBUF lpBuf;
  77. //
  78. // don't let the number of traces exceed the size
  79. // of the file
  80. //
  81. if ( PendQ.dwCount >= PendQ.dwThresholdCount )
  82. {
  83. INT_TRACE( "Alloc flush: %u\n", PendQ.dwCount );
  84. FlushAsyncTrace();
  85. }
  86. //
  87. // Turn off randfail for this allocation
  88. //
  89. RandFailDisable();
  90. lpBuf = (LPTRACEBUF)g_pFreePool->Alloc();
  91. RandFailEnable();
  92. if ( lpBuf != NULL )
  93. {
  94. lpBuf->pNext = NULL;
  95. lpBuf->dwSignature = TRACE_SIGNATURE;
  96. }
  97. return lpBuf;
  98. }
  99. //+---------------------------------------------------------------
  100. //
  101. // Function: FreeTraceBuffer
  102. //
  103. // Synopsis: external "C" function to free a CPool buffer
  104. //
  105. // Arguments: LPTRACEBUF: the buffer to free
  106. //
  107. // Returns: void
  108. //
  109. //----------------------------------------------------------------
  110. void WINAPI FreeTraceBuffer( LPTRACEBUF lpBuf )
  111. {
  112. ASSERT( lpBuf != NULL );
  113. ASSERT( lpBuf->dwSignature == TRACE_SIGNATURE );
  114. g_pFreePool->Free( (void*)lpBuf );
  115. }