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.

79 lines
1.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // slock.hxx
  7. //
  8. //--------------------------------------------------------------------------
  9. #ifndef __LOCKS_HXX__
  10. #define __LOCKS_HXX__
  11. class CSharedLock
  12. {
  13. public:
  14. CSharedLock(
  15. IN char * pszName,
  16. OUT HRESULT & hr
  17. );
  18. ~CSharedLock();
  19. void LockShared(void);
  20. void UnlockShared(void);
  21. void LockExclusive(void);
  22. void UnlockExclusive(void);
  23. private:
  24. HANDLE _hMutex;
  25. };
  26. inline
  27. CSharedLock::CSharedLock(
  28. IN char * pszName,
  29. OUT HRESULT & hr
  30. )
  31. {
  32. hr = S_OK;
  33. _hMutex = CreateMutex( NULL, FALSE, pszName );
  34. if ( ! _hMutex )
  35. hr = HRESULT_FROM_WIN32( GetLastError() );
  36. }
  37. inline
  38. CSharedLock::~CSharedLock()
  39. {
  40. if ( _hMutex )
  41. CloseHandle( _hMutex );
  42. }
  43. inline void
  44. CSharedLock::LockShared()
  45. {
  46. // No shared locking on win9x.
  47. LockExclusive();
  48. }
  49. inline void
  50. CSharedLock::UnlockShared()
  51. {
  52. // No shared locking on win9x.
  53. UnlockExclusive();
  54. }
  55. inline void
  56. CSharedLock::LockExclusive()
  57. {
  58. WaitForSingleObject( _hMutex, INFINITE );
  59. }
  60. inline void
  61. CSharedLock::UnlockExclusive()
  62. {
  63. ReleaseMutex( _hMutex );
  64. }
  65. #endif // __LOCKS_HXX__