Semaphore_WIN32.h 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Semaphore_WIN32.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/Semaphore_WIN32.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Threading
  8. // Module: Semaphore
  9. //
  10. // Definition of the SemaphoreImpl class for WIN32.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_Semaphore_WIN32_INCLUDED
  18. #define Foundation_Semaphore_WIN32_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/Exception.h"
  21. #include "Poco/UnWindows.h"
  22. namespace Poco {
  23. class Foundation_API SemaphoreImpl
  24. {
  25. protected:
  26. SemaphoreImpl(int n, int max);
  27. ~SemaphoreImpl();
  28. void setImpl();
  29. void waitImpl();
  30. bool waitImpl(long milliseconds);
  31. private:
  32. HANDLE _sema;
  33. };
  34. //
  35. // inlines
  36. //
  37. inline void SemaphoreImpl::setImpl()
  38. {
  39. if (!ReleaseSemaphore(_sema, 1, NULL))
  40. {
  41. throw SystemException("cannot signal semaphore");
  42. }
  43. }
  44. } // namespace Poco
  45. #endif // Foundation_Semaphore_WIN32_INCLUDED