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.

124 lines
2.9 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. #include <windows.h>
  14. #include <cpool.h>
  15. #include "traceint.h"
  16. //
  17. // global pointer to CPool to avoid pulling in the C runtime
  18. // to call the con/destrustors
  19. //
  20. CPool* g_pFreePool = NULL;
  21. //+---------------------------------------------------------------
  22. //
  23. // Function: InitTraceBuffers
  24. //
  25. // Synopsis: external "C" function to init the CPool
  26. //
  27. // Arguments: DWORD: Maximum number of pending traces
  28. // DWORD: Increment size for the CPool
  29. //
  30. // Returns: BOOL: successful or not
  31. //
  32. //----------------------------------------------------------------
  33. BOOL WINAPI InitTraceBuffers( DWORD dwThresholdCount, DWORD dwIncrement )
  34. {
  35. g_pFreePool = new CPool( TRACE_SIGNATURE );
  36. return g_pFreePool != NULL &&
  37. g_pFreePool->ReserveMemory( dwThresholdCount,
  38. sizeof(TRACEBUF),
  39. dwIncrement );
  40. }
  41. //+---------------------------------------------------------------
  42. //
  43. // Function: TermTraceBuffers
  44. //
  45. // Synopsis: cleanup
  46. //
  47. // Arguments: void
  48. //
  49. // Returns: void
  50. //
  51. //----------------------------------------------------------------
  52. void WINAPI TermTraceBuffers( void )
  53. {
  54. CPool* pPool = (CPool*)InterlockedExchangePointer((LPVOID *)&g_pFreePool, NULL);
  55. if ( pPool != NULL )
  56. {
  57. pPool->ReleaseMemory();
  58. delete pPool;
  59. }
  60. }
  61. //+---------------------------------------------------------------
  62. //
  63. // Function: GetTraceBuffer
  64. //
  65. // Synopsis: external "C" function to get a CPool buffer
  66. //
  67. // Arguments: void
  68. //
  69. // Returns: LPTRACEBUF: allocated buffer
  70. //
  71. //----------------------------------------------------------------
  72. LPTRACEBUF WINAPI GetTraceBuffer( void )
  73. {
  74. LPTRACEBUF lpBuf;
  75. //
  76. // don't let the number of traces exceed the size
  77. // of the file
  78. //
  79. if ( PendQ.dwCount >= PendQ.dwThresholdCount )
  80. {
  81. INT_TRACE( "Alloc flush: %u\n", PendQ.dwCount );
  82. INTERNAL__FlushAsyncTrace();
  83. }
  84. lpBuf = (LPTRACEBUF)g_pFreePool->Alloc();
  85. if ( lpBuf != NULL )
  86. {
  87. lpBuf->pNext = NULL;
  88. lpBuf->dwSignature = TRACE_SIGNATURE;
  89. }
  90. return lpBuf;
  91. }
  92. //+---------------------------------------------------------------
  93. //
  94. // Function: FreeTraceBuffer
  95. //
  96. // Synopsis: external "C" function to free a CPool buffer
  97. //
  98. // Arguments: LPTRACEBUF: the buffer to free
  99. //
  100. // Returns: void
  101. //
  102. //----------------------------------------------------------------
  103. void WINAPI FreeTraceBuffer( LPTRACEBUF lpBuf )
  104. {
  105. ASSERT( lpBuf != NULL );
  106. ASSERT( lpBuf->dwSignature == TRACE_SIGNATURE );
  107. g_pFreePool->Free( (void*)lpBuf );
  108. }