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.

81 lines
2.7 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: shutdown.h
  5. //
  6. // Description: An inheritable class that uses SharedLock to synchronize
  7. // shutdown.
  8. //
  9. // Author: mikeswa
  10. //
  11. // History:
  12. // 9/4/98 - MikeSwa Modified to have a non-blocking fTryShutdownLock.
  13. //
  14. // Copyright (C) 1998 Microsoft Corporation
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef __SHUTDOWN_H__
  18. #define __SHUTDOWN_H__
  19. class CSyncShutdown;
  20. #include <aqincs.h>
  21. #include <rwnew.h>
  22. #define CSyncShutdown_Sig 'tuhS'
  23. #define CSyncShutdown_SigFree 'thS!'
  24. //Bit in m_cReadLocks used to signal that shudown is in progress
  25. const DWORD SYNC_SHUTDOWN_SIGNALED = 0x80000000;
  26. //---[ CSyncShutdown ]---------------------------------------------------------
  27. //
  28. //
  29. // Synchronization object that is a base class for AQ objects. This is
  30. // designed to allow objects to know when it is OK to access member variables,
  31. // and is really only needed in components that have external threads calling
  32. // in (current CAQSvrInst and CConnMgr).
  33. //
  34. // The basic usage is to call fTryShutdownLock() before access member data. If
  35. // it fails, return AQUEUE_E_SHUTDOWN... otherwise you can access member data
  36. // until you call ShutdownUnlock(). Neither of these calls will block:
  37. //
  38. // if (!fTryShutdownLock())
  39. // {
  40. // hr = AQUEUE_E_SHUTDOWN;
  41. // goto Exit;
  42. // }
  43. // ...
  44. // ShutdownUnlock();
  45. //
  46. // SignalShutdown should be called during the inheriting function's
  47. // HrDeInitialize(). This will cause all further calls to fTryShutdownLock()
  48. // to fail. This call will block until all threads that have had a successful
  49. // fTryShutdownLock() call ShutdownUnlock().
  50. //
  51. //-----------------------------------------------------------------------------
  52. class CSyncShutdown
  53. {
  54. private:
  55. DWORD m_dwSignature;
  56. DWORD m_cReadLocks; //Keep track of the number of read locks
  57. CShareLockNH m_slShutdownLock;
  58. public:
  59. CSyncShutdown()
  60. {
  61. m_dwSignature = CSyncShutdown_Sig;
  62. m_cReadLocks = 0;
  63. };
  64. ~CSyncShutdown();
  65. BOOL fTryShutdownLock();
  66. void ShutdownUnlock();
  67. void SignalShutdown();
  68. BOOL fShutdownSignaled() {return (m_cReadLocks & SYNC_SHUTDOWN_SIGNALED);};
  69. //Assert that can be used to verify that the lock is held by somethread
  70. void AssertShutdownLockAquired() {_ASSERT(m_cReadLocks & ~SYNC_SHUTDOWN_SIGNALED);};
  71. void SetShutdownHint(); //causes future calls to fTryShutdownLock to fail
  72. };
  73. #endif //__SHUTDOWN_H__