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.

69 lines
1.3 KiB

  1. #pragma once
  2. #define ADMT_MUTEX _T("Global\\{9DC80865-6CC7-4988-8CC0-2AC5CA01879C}")
  3. #define AGENT_MUTEX _T("Global\\{E2624042-8C80-4A83-B3DF-2B840DE366E5}")
  4. #define AGENT_MUTEX_NT4 _T("{E2624042-8C80-4A83-B3DF-2B840DE366E5}")
  5. #define DISPATCHER_MUTEX _T("Global\\{7C84F7DB-CF48-4B59-99D8-6B5A95276DBD}")
  6. //---------------------------------------------------------------------------
  7. // MigrationMutex Class
  8. //
  9. // This class may be used to prevent more than one instance of a migration
  10. // task to run at the same time.
  11. //
  12. //
  13. // Revision
  14. // Initial 01/26/01 Mark Oluper
  15. //---------------------------------------------------------------------------
  16. class CMigrationMutex
  17. {
  18. public:
  19. CMigrationMutex(LPCTSTR pszMutexName, bool bObtainOwnership = false) :
  20. m_hMutex(CreateMutex(NULL, FALSE, pszMutexName))
  21. {
  22. if (bObtainOwnership)
  23. {
  24. ObtainOwnership();
  25. }
  26. }
  27. ~CMigrationMutex()
  28. {
  29. if (m_hMutex)
  30. {
  31. ReleaseOwnership();
  32. CloseHandle(m_hMutex);
  33. }
  34. }
  35. bool ObtainOwnership(DWORD dwTimeOut = INFINITE)
  36. {
  37. bool bObtain = false;
  38. if (m_hMutex)
  39. {
  40. if (WaitForSingleObject(m_hMutex, dwTimeOut) == WAIT_OBJECT_0)
  41. {
  42. bObtain = true;
  43. }
  44. }
  45. return bObtain;
  46. }
  47. void ReleaseOwnership()
  48. {
  49. if (m_hMutex)
  50. {
  51. ReleaseMutex(m_hMutex);
  52. }
  53. }
  54. protected:
  55. HANDLE m_hMutex;
  56. };