home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / stablize.h < prev    next >
C/C++ Source or Header  |  1998-04-24  |  3KB  |  97 lines

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright 1992 - 1997 Microsoft Corporation.
  5. //
  6. //  File:       stablize.h
  7. //
  8. //  Contents:   Stabilization Classes used to stabilize objects during
  9. //              re-entrant calls.
  10. //
  11. //  Classes:    CSafeRefCount
  12. //              CStabilize
  13. //
  14. //  History:    8-26-94   stevebl   Modified from code written by AlexGo
  15. //
  16. //----------------------------------------------------------------------------
  17.  
  18. #ifndef __STABLIZE__
  19. #define __STABLIZE__
  20.  
  21. //+-------------------------------------------------------------------------
  22. //
  23. //  Class:      CSafeRefCount
  24. //
  25. //  Purpose:    A concrete class for objects to inherit from.
  26. //              CSafeRefCount will keep track of reference counts,
  27. //              nesting counts, and zombie states, allowing objects
  28. //              to easily manage the liveness of their memory images.
  29. //
  30. //  Interface:
  31. //
  32. //  History:    dd-mmm-yy Author    Comment
  33. //              01-Aug-94 alexgo    author
  34. //
  35. //  Notes:      inherits CPrivAlloc
  36. //
  37. //--------------------------------------------------------------------------
  38.  
  39. class CSafeRefCount
  40. {
  41. public:
  42.         ULONG   SafeAddRef();
  43.         ULONG   SafeRelease();
  44.         ULONG   IncrementNestCount();
  45.         ULONG   DecrementNestCount();
  46.                 CSafeRefCount();
  47.         virtual ~CSafeRefCount();
  48.  
  49. private:
  50.  
  51.         ULONG   m_cRefs;
  52.         ULONG   m_cNest;
  53.         BOOL    m_fInDelete;
  54. };
  55.  
  56. //+-------------------------------------------------------------------------
  57. //
  58. //  Class:      CStabilize
  59. //
  60. //  Purpose:    An instance of this class should be allocated on the
  61. //              stack of every object method that makes an outgoing call.
  62. //              The contstructor takes a pointer to the object's base
  63. //              CSafeRefCount class.
  64. //
  65. //  Interface:
  66. //
  67. //  History:    dd-mmm-yy Author    Comment
  68. //              01-Aug-94 alexgo    author
  69. //
  70. //  Notes:      The constructor will increment the nest count of the
  71. //              object while the destructor will decrement it.
  72. //
  73. //--------------------------------------------------------------------------
  74.  
  75. class CStabilize
  76. {
  77. public:
  78.         inline CStabilize( CSafeRefCount *pObjSafeRefCount );
  79.         inline ~CStabilize();
  80.  
  81. private:
  82.         CSafeRefCount * m_pObjSafeRefCount;
  83. };
  84.  
  85. inline CStabilize::CStabilize( CSafeRefCount *pObjSafeRefCount )
  86. {
  87.         pObjSafeRefCount->IncrementNestCount();
  88.         m_pObjSafeRefCount = pObjSafeRefCount;
  89. }
  90.  
  91. inline CStabilize::~CStabilize()
  92. {
  93.         m_pObjSafeRefCount->DecrementNestCount();
  94. }
  95.  
  96. #endif  // __STABLIZE__
  97.