NamedMutex_VMS.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // NamedMutex_VMS.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/NamedMutex_VMS.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Processes
  8. // Module: NamedMutex
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/NamedMutex_VMS.h"
  16. #include <starlet.h>
  17. #include <iodef.h>
  18. namespace Poco {
  19. NamedMutexImpl::NamedMutexImpl(const std::string& name):
  20. _name(name)
  21. {
  22. _nameDesc.dsc$w_length = _name.length();
  23. _nameDesc.dsc$b_dtype = DSC$K_DTYPE_T;
  24. _nameDesc.dsc$b_class = DSC$K_CLASS_S;
  25. _nameDesc.dsc$a_pointer = _name.data();
  26. int status = sys$enqw(0, LCK$K_NLMODE, (struct _lksb*) &_lksb, 0, &_nameDesc, 0, 0, 0, 0, 0, 0);
  27. if (status != 1)
  28. throw SystemException("cannot create named mutex", _name);
  29. }
  30. NamedMutexImpl::~NamedMutexImpl()
  31. {
  32. sys$deq(m_lksb[1], 0, 0, 0);
  33. }
  34. void NamedMutexImpl::lockImpl()
  35. {
  36. int status = sys$enqw(0, LCK$K_EXMODE, (struct _lksb*) &_lksb, LCK$M_CONVERT, &_nameDesc, 0, 0, 0, 0, 0, 0);
  37. if (status != 1)
  38. throw SystemException("cannot lock named mutex", _name);
  39. }
  40. bool NamedMutexImpl::tryLockImpl()
  41. {
  42. int status = sys$enqw(0, LCK$K_EXMODE, (struct _lksb*) &_lksb, LCK$M_CONVERT | LCK$M_NOQUEUE, &_nameDesc, 0, 0, 0, 0, 0, 0);
  43. return status == 1;
  44. }
  45. void NamedMutexImpl::unlockImpl()
  46. {
  47. int status = sys$enqw(0, LCK$K_NLMODE, (struct _lksb*) &_lksb, LCK$M_CONVERT, &_nameDesc, 0, 0, 0, 0, 0, 0);
  48. if (status != 1)
  49. throw SystemException("cannot unlock named mutex", _name);
  50. }
  51. } // namespace Poco