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.

196 lines
4.2 KiB

  1. #ifndef _SYNC_HEADER_
  2. #define _SYNC_HEADER_
  3. #if COMPREF_DEBUG_TRACKING
  4. #define _COMPREF_DEBUG_RECORD_COUNT (1024)
  5. enum TypeOfRefOp
  6. {
  7. eReferencing,
  8. eDereferencing
  9. } ;
  10. typedef struct _COMPREF_DEBUG_RECORD_
  11. {
  12. BOOLEAN bInUse;
  13. ULONG OpCode;
  14. PCHAR File;
  15. ULONG Line;
  16. TypeOfRefOp Type;
  17. } COMPREF_DEBUG_RECORD_, *PCOMPREF_DEBUG_RECORD_;
  18. #endif
  19. class COMPONENT_SYNC
  20. {
  21. public:
  22. COMPONENT_SYNC();
  23. virtual ~COMPONENT_SYNC();
  24. virtual void ComponentCleanUpRoutine(void);
  25. //virtual void shouldBeDeleted();
  26. virtual BOOLEAN ReferenceSync(void);
  27. virtual BOOLEAN DereferenceSync(void);
  28. virtual void DeleteSync(void);
  29. virtual void StopSync(void) {};
  30. virtual ULONG InitializeSync(void);
  31. virtual BOOLEAN RecordRef(
  32. ULONG RefId,
  33. PCHAR File,
  34. ULONG Line
  35. );
  36. virtual BOOLEAN RecordDeref(
  37. ULONG RefId,
  38. PCHAR File,
  39. ULONG Line
  40. );
  41. virtual BOOLEAN ReportRefRecord();
  42. // virtual BOOLEAN RecordDeref(PCHAR File, ULONG Line, UCHAR Type);
  43. // virtual void ResetSync(void);
  44. virtual PCHAR GetObjectName() { return ObjectNamep;}
  45. inline virtual void AcquireLock();
  46. inline virtual void ReleaseLock();
  47. protected:
  48. static const PCHAR ObjectNamep;
  49. CRITICAL_SECTION m_Lock;
  50. ULONG m_ReferenceCount;
  51. BOOLEAN Deleted;
  52. BOOLEAN bCleanupCalled;
  53. #if COMPREF_DEBUG_TRACKING
  54. struct _COMPREF_DEBUG_RECORD_ * m_RecordArray;
  55. ULONG m_RecordIndex;
  56. #endif
  57. };
  58. typedef COMPONENT_SYNC * PCOMPONENT_SYNC;
  59. // +-*****************
  60. // Macro - Enum Definitions
  61. // +-*****************
  62. enum REFERENCE_OPCODE
  63. {
  64. eRefInitialization = 0x00000001,
  65. eRefSecondLevel = 0x00000002,
  66. eRefIoRead = 0x00000004,
  67. eRefIoWrite = 0x00000008,
  68. eRefIoAccept = 0x00000010,
  69. eRefIoConnect = 0x00000020,
  70. eRefIoSharing = 0x00000040,
  71. eRefIoClose = 0x00000080,
  72. eRefList = 0x00000100
  73. };
  74. //
  75. //
  76. //
  77. #define REFERENCE_COMPONENT_OR_RETURN(c, retcode) \
  78. ICQ_TRC(TM_SYNC, TL_TRACE, ("%s %ld", __FILE__, __LINE__));\
  79. if (!(c)->ReferenceSync()) { return (retcode); }
  80. //
  81. //
  82. //
  83. #define DEREF_COMPONENT(_X_, _Y_) \
  84. ICQ_TRC(TM_SYNC, TL_TRACE, ("%s %ld", __FILE__, __LINE__));\
  85. (_X_)->RecordDeref( (_Y_), __FILE__, __LINE__); \
  86. if((_X_)->DereferenceSync()) \
  87. { \
  88. delete (_X_); \
  89. (_X_) = NULL; \
  90. }
  91. //
  92. //
  93. //
  94. #define REF_COMPONENT(_X_, _Y_ ) \
  95. ICQ_TRC(TM_SYNC, TL_TRACE, ("REF %s %ld", __FILE__, __LINE__));\
  96. (_X_)->RecordRef( (_Y_), __FILE__, __LINE__ ); \
  97. (_X_)->ReferenceSync()
  98. //
  99. // This Macro is used to Stop or delete Asynchronous elements like
  100. // - Sockets which are waiting on Reads or Writes and/or Accepts
  101. // - Stops Timers or Waiting Objects if any.
  102. //
  103. #define STOP_COMPONENT(_X_) \
  104. ICQ_TRC(TM_SYNC, TL_TRACE, ("%s %ld", __FILE__, __LINE__)); \
  105. (_X_)->StopSync()
  106. #define DELETE_COMPONENT(_X_) \
  107. ICQ_TRC(TM_SYNC, TL_TRACE, ("%s %ld", __FILE__, __LINE__)); \
  108. (_X_)->StopSync(); \
  109. (_X_)->RecordRef( eRefInitialization, __FILE__, __LINE__ ); \
  110. if( (_X_)->DereferenceSync() ) \
  111. { \
  112. delete (_X_); \
  113. (_X_) = NULL; \
  114. }
  115. #if COMPREF_DEBUG_TRACKING
  116. //
  117. //
  118. //
  119. //#define REF_COMPONENT_OR_RETURN(c,retcode) \
  120. // if (!c->RecordSync( __FILE__, __LINE__, ComprefAcquireRecord)) { return retcode; }
  121. //
  122. //
  123. //
  124. // #define DEREF_COMPONENT(c) \
  125. // c->RecordSync( __FILE__, __LINE__, ComprefReleaseRecord)
  126. #else
  127. #endif //if COMPREF
  128. #endif // _SYNC_HEADER_