STABLIZE.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:3k
源码类别:

Windows编程

开发平台:

Visual C++

  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. #ifndef __STABLIZE__
  18. #define __STABLIZE__
  19. //+-------------------------------------------------------------------------
  20. //
  21. //  Class:      CSafeRefCount
  22. //
  23. //  Purpose:    A concrete class for objects to inherit from.
  24. //              CSafeRefCount will keep track of reference counts,
  25. //              nesting counts, and zombie states, allowing objects
  26. //              to easily manage the liveness of their memory images.
  27. //
  28. //  Interface:
  29. //
  30. //  History:    dd-mmm-yy Author    Comment
  31. //              01-Aug-94 alexgo    author
  32. //
  33. //  Notes:      inherits CPrivAlloc
  34. //
  35. //--------------------------------------------------------------------------
  36. class CSafeRefCount
  37. {
  38. public:
  39.         ULONG   SafeAddRef();
  40.         ULONG   SafeRelease();
  41.         ULONG   IncrementNestCount();
  42.         ULONG   DecrementNestCount();
  43.                 CSafeRefCount();
  44.         virtual ~CSafeRefCount();
  45. private:
  46.         ULONG   m_cRefs;
  47.         ULONG   m_cNest;
  48.         BOOL    m_fInDelete;
  49. };
  50. //+-------------------------------------------------------------------------
  51. //
  52. //  Class:      CStabilize
  53. //
  54. //  Purpose:    An instance of this class should be allocated on the
  55. //              stack of every object method that makes an outgoing call.
  56. //              The contstructor takes a pointer to the object's base
  57. //              CSafeRefCount class.
  58. //
  59. //  Interface:
  60. //
  61. //  History:    dd-mmm-yy Author    Comment
  62. //              01-Aug-94 alexgo    author
  63. //
  64. //  Notes:      The constructor will increment the nest count of the
  65. //              object while the destructor will decrement it.
  66. //
  67. //--------------------------------------------------------------------------
  68. class CStabilize
  69. {
  70. public:
  71.         inline CStabilize( CSafeRefCount *pObjSafeRefCount );
  72.         inline ~CStabilize();
  73. private:
  74.         CSafeRefCount * m_pObjSafeRefCount;
  75. };
  76. inline CStabilize::CStabilize( CSafeRefCount *pObjSafeRefCount )
  77. {
  78.         pObjSafeRefCount->IncrementNestCount();
  79.         m_pObjSafeRefCount = pObjSafeRefCount;
  80. }
  81. inline CStabilize::~CStabilize()
  82. {
  83.         m_pObjSafeRefCount->DecrementNestCount();
  84. }
  85. #endif  // __STABLIZE__