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.

86 lines
2.0 KiB

  1. /*****************************************************************************
  2. * Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  3. *
  4. * All Rights Reserved
  5. *
  6. * This software is furnished under a license and may be used and copied
  7. * only in accordance with the terms of such license and with the inclusion
  8. * of the above copyright notice. This software or any other copies thereof
  9. * may not be provided or otherwise made available to any other person. No
  10. * title to and ownership of the software is hereby transferred.
  11. *****************************************************************************/
  12. //============================================================================
  13. //
  14. // CMutex.cpp -- Mutex Wrapper
  15. //
  16. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  17. //
  18. // Revisions: 6/26/98 a-kevhu Created
  19. //
  20. //============================================================================
  21. #include "precomp.h"
  22. #include "CMutex.h"
  23. // constructor creates a mutex allowing creation parameters to be specified...
  24. CMutex::CMutex(BOOL bInitialOwner, LPCTSTR lpName, LPSECURITY_ATTRIBUTES lpMutexAttributes)
  25. {
  26. m_hHandle = ::CreateMutex(lpMutexAttributes, bInitialOwner, lpName);
  27. if (CIsValidHandle(m_hHandle))
  28. {
  29. if (lpName)
  30. {
  31. m_dwStatus = GetLastError();
  32. }
  33. else
  34. {
  35. m_dwStatus = NO_ERROR;
  36. }
  37. }
  38. else
  39. {
  40. m_dwStatus = GetLastError();
  41. ThrowError(m_dwStatus);
  42. }
  43. }
  44. // constructor opens an existing named mutex...
  45. CMutex::CMutex(LPCTSTR lpName, BOOL bInheritHandle, DWORD dwDesiredAccess)
  46. {
  47. m_hHandle = ::OpenMutex(dwDesiredAccess, bInheritHandle, lpName);
  48. if (CIsValidHandle(m_hHandle))
  49. {
  50. m_dwStatus = NO_ERROR;
  51. }
  52. else
  53. {
  54. m_dwStatus = GetLastError();
  55. }
  56. }
  57. // release a lock on a mutex...
  58. BOOL CMutex::Release(void)
  59. {
  60. return ::ReleaseMutex(m_hHandle);
  61. }