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.

85 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. refcnt.h
  5. Abstract:
  6. Author:
  7. Edward Buchwalter (v-edbuc) 15-Aug-1996
  8. Revision History:
  9. Shreedhar Madhavapeddi (ShreeM) 16-April-1999 Adapted for GPC.
  10. Rajesh Sundaram (rajeshsu) 05-Aug-1999 Adapted for psched.
  11. --*/
  12. #ifndef REFCNT_H
  13. #define REFCNT_H
  14. //
  15. // Reference Count Control Block
  16. //
  17. // Elements:
  18. //
  19. // - Count: number of outstanding references
  20. // - Instance: user supplied context
  21. // - UserDeleteFunc: user supplied delete function
  22. //
  23. #define TAG_CNT 10
  24. #define REF_SIG 0x7841eeee
  25. typedef struct
  26. {
  27. ULONG Tag;
  28. LONG Count;
  29. } REF_TAG;
  30. typedef struct reference_count_control
  31. {
  32. LONG Count;
  33. PVOID Instance;
  34. VOID (*DeleteHandler)( PVOID, BOOLEAN );
  35. #if DBG
  36. int Sig;
  37. REF_TAG Tags[TAG_CNT];
  38. CTELock Lock;
  39. #endif
  40. } REF_CNT, *PREF_CNT;
  41. VOID
  42. ReferenceInit
  43. (
  44. IN PREF_CNT pRefCnt,
  45. PVOID InstanceHandle,
  46. VOID (*DeleteHandler)( PVOID , BOOLEAN)
  47. );
  48. #define REFINIT(Rc, I, h) ReferenceInit(Rc, I, h)
  49. #if DBG
  50. VOID ReferenceAddDbg(PREF_CNT pRefCnt, ULONG Tag);
  51. VOID ReferenceRemoveDbg(PREF_CNT pRefCnt, BOOLEAN Locked, ULONG Tag);
  52. #define REFADD(Rc, Tag) ReferenceAddDbg(Rc, Tag);
  53. #define REFDEL(Rc, LockHeld, Tag) ReferenceRemoveDbg(Rc, LockHeld, Tag)
  54. #else
  55. #define REFADD(Rc, Tag) InterlockedIncrement(&(Rc)->Count);
  56. #define REFDEL(Rc, LockHeld, Tag) \
  57. if (InterlockedDecrement(&(Rc)->Count) == 0 ) \
  58. ((Rc)->DeleteHandler)( (Rc)->Instance , (LockHeld));
  59. #endif
  60. #endif