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.

93 lines
1.8 KiB

  1. //=================================================================
  2. //
  3. // TimedDllResource.cpp
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include "ResourceManager.h"
  10. #include "TimerQueue.h"
  11. #include "TimedDllResource.h"
  12. #include "TimeOutRule.h"
  13. #include "ProvExce.h"
  14. #define CACHED_DLL_TIMEOUT 300000
  15. CTimedDllResource::~CTimedDllResource ()
  16. {
  17. LogMessage ( L"Entering ~CTimedDllResource" ) ;
  18. if ( m_pRules )
  19. {
  20. m_pRules->Detach () ;
  21. m_pRules->Release () ;
  22. m_pRules = NULL ;
  23. }
  24. LogMessage ( L"Leaving ~CTimedDllResource" ) ;
  25. }
  26. BOOL CTimedDllResource :: OnFinalRelease()
  27. {
  28. if ( m_pRules )
  29. {
  30. m_pRules->Detach () ;
  31. m_pRules->Release () ;
  32. m_pRules = NULL ;
  33. return TRUE ;
  34. }
  35. else
  36. {
  37. /*
  38. * Add an unload rule
  39. */
  40. m_pRules = new CTimeOutRule ( CACHED_DLL_TIMEOUT, this, m_pResources ) ;
  41. if( !m_pRules )
  42. {
  43. throw CHeap_Exception( CHeap_Exception::E_ALLOCATION_ERROR ) ;
  44. }
  45. m_pRules->AddRef () ;
  46. /*
  47. * Up the reference count to wait for the callback to come
  48. */
  49. ++m_lRef ;
  50. return FALSE ;
  51. }
  52. }
  53. BOOL CTimedDllResource :: OnAcquire ()
  54. {
  55. /*
  56. * somebody tried to acquire us, so we don't want the unload rule hanging around
  57. */
  58. if ( m_pRules )
  59. {
  60. m_pRules->Detach () ;
  61. m_pRules->Release () ;
  62. m_pRules = NULL ;
  63. /*
  64. * decrement the ref count which we'd added to wait for the callback
  65. */
  66. --m_lRef ;
  67. }
  68. return TRUE ;
  69. }
  70. void CTimedDllResource :: RuleEvaluated ( const CRule *a_Rule )
  71. {
  72. if ( m_pRules->CheckRule () )
  73. {
  74. /*
  75. * Decrement the Refcount which we'd added to wait for the callback & check if we've to delete ourselves
  76. */
  77. Release () ;
  78. }
  79. }