Mutex_WINCE.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Mutex_WINCE.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Mutex_WINCE.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Threading
  8. // Module: Mutex
  9. //
  10. // Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/Mutex_WINCE.h"
  16. namespace Poco {
  17. MutexImpl::MutexImpl()
  18. {
  19. _mutex = CreateMutexW(NULL, FALSE, NULL);
  20. if (!_mutex) throw SystemException("cannot create mutex");
  21. }
  22. MutexImpl::~MutexImpl()
  23. {
  24. CloseHandle(_mutex);
  25. }
  26. void MutexImpl::lockImpl()
  27. {
  28. switch (WaitForSingleObject(_mutex, INFINITE))
  29. {
  30. case WAIT_OBJECT_0:
  31. return;
  32. default:
  33. throw SystemException("cannot lock mutex");
  34. }
  35. }
  36. bool MutexImpl::tryLockImpl()
  37. {
  38. switch (WaitForSingleObject(_mutex, 0))
  39. {
  40. case WAIT_TIMEOUT:
  41. return false;
  42. case WAIT_OBJECT_0:
  43. return true;
  44. default:
  45. throw SystemException("cannot lock mutex");
  46. }
  47. }
  48. bool MutexImpl::tryLockImpl(long milliseconds)
  49. {
  50. switch (WaitForSingleObject(_mutex, milliseconds + 1))
  51. {
  52. case WAIT_TIMEOUT:
  53. return false;
  54. case WAIT_OBJECT_0:
  55. return true;
  56. default:
  57. throw SystemException("cannot lock mutex");
  58. }
  59. }
  60. void MutexImpl::unlockImpl()
  61. {
  62. ReleaseMutex(_mutex);
  63. }
  64. } // namespace Poco