Source code of Windows XP (NT5)
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.

68 lines
1.2 KiB

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