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.

102 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. memlog.c
  5. Abstract:
  6. DNS Resolver Service
  7. In memory logging.
  8. Author:
  9. Glenn Curtis (glennc) Feb 1998
  10. Revision History:
  11. Jim Gilroy (jamesg) March 2000 cleanup
  12. Jim Gilroy (jamesg) Nov 2000 create this module
  13. --*/
  14. #include "local.h"
  15. //
  16. // Memory event array
  17. //
  18. typedef struct _InMemoryEvent
  19. {
  20. DWORD Thread;
  21. DWORD Ticks;
  22. DWORD Checkpoint;
  23. DWORD Data;
  24. }
  25. MEM_EVENT, *PMEM_EVENT;
  26. #define MEM_EVENT_ARRAY_SIZE 200
  27. PMEM_EVENT g_pEventArray = NULL;
  28. LONG g_EventArrayLength = MEM_EVENT_ARRAY_SIZE;
  29. LONG g_EventIndex = 0;
  30. VOID
  31. LogEventInMemory(
  32. IN DWORD Checkpoint,
  33. IN DWORD Data
  34. )
  35. {
  36. DWORD index;
  37. //
  38. // allocate event table
  39. // - use interlock to insure only done once
  40. //
  41. if ( !g_pEventArray )
  42. {
  43. PMEM_EVENT ptemp = (PMEM_EVENT)
  44. HeapAlloc(
  45. GetProcessHeap(),
  46. HEAP_ZERO_MEMORY,
  47. g_EventArrayLength * sizeof(MEM_EVENT) );
  48. if ( !ptemp )
  49. {
  50. return;
  51. }
  52. if ( InterlockedCompareExchangePointer(
  53. (PVOID *) &g_pEventArray,
  54. ptemp,
  55. 0) != 0 )
  56. {
  57. HeapFree(GetProcessHeap(), 0, ptemp);
  58. }
  59. }
  60. //
  61. // write event to memory
  62. //
  63. index = InterlockedIncrement( &g_EventIndex );
  64. index %= g_EventArrayLength;
  65. g_pEventArray[index].Ticks = GetTickCount();
  66. g_pEventArray[index].Checkpoint = Checkpoint;
  67. g_pEventArray[index].Thread = (short) GetCurrentThreadId();
  68. g_pEventArray[index].Data = Data;
  69. }
  70. //
  71. // memlog.c
  72. //