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.

76 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. wanarp2\ref.h
  5. Abstract:
  6. Generic structure referencing routines
  7. All these routines assume that the structure has the following field:
  8. LONG lRefCount
  9. setting REF_DEBUG to 1 results in noisy output about when a structure
  10. is referenced and derefenced
  11. Revision History:
  12. Amritansh Raghav
  13. --*/
  14. #if REF_DEBUG
  15. #define InitStructureRefCount(s, p, r) \
  16. { \
  17. DbgPrint("\n<>%s refcount set to %d for %x (%s, %d)\n\n", \
  18. s, (r), (p), __FILE__, __LINE__); \
  19. (p)->lRefCount = r; \
  20. }
  21. #define ReferenceStructure(s, p) \
  22. { \
  23. DbgPrint("\n++Ref %s %x to %d (%s, %d)\n\n", \
  24. s, p, InterlockedIncrement(&((p)->lRefCount)), \
  25. __FILE__, __LINE__); \
  26. }
  27. #define DereferenceStructure(s, p, f) \
  28. { \
  29. LONG __lTemp; \
  30. __lTemp = InterlockedDecrement(&((p)->lRefCount)); \
  31. DbgPrint("\n--Deref %s %x to %d (%s, %d)\n\n", \
  32. s, (p), __lTemp, __FILE__, __LINE__); \
  33. if(__lTemp == 0) \
  34. { \
  35. DbgPrint("\n>< Deleting %s at %x\n\n", \
  36. s, (p)); \
  37. (f)((p)); \
  38. } \
  39. }
  40. #else // REF_DEBUG
  41. #define InitStructureRefCount(s, p, r) \
  42. (p)->lRefCount = (r)
  43. #define ReferenceStructure(s, p) \
  44. InterlockedIncrement(&((p)->lRefCount))
  45. #define DereferenceStructure(s, p, f) \
  46. { \
  47. if(InterlockedDecrement(&((p)->lRefCount)) == 0) \
  48. { \
  49. (f)((p)); \
  50. } \
  51. }
  52. #endif // REF_DEBUG