semaphore.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_POSIX_SEMAPHORE_HPP
  11. #define BOOST_INTERPROCESS_POSIX_SEMAPHORE_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #include <boost/interprocess/detail/config_begin.hpp>
  20. #include <boost/interprocess/detail/workaround.hpp>
  21. #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
  22. #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp>
  23. namespace boost {
  24. namespace interprocess {
  25. namespace ipcdetail {
  26. class posix_semaphore
  27. {
  28. posix_semaphore();
  29. posix_semaphore(const posix_semaphore&);
  30. posix_semaphore &operator= (const posix_semaphore &);
  31. public:
  32. posix_semaphore(unsigned int initialCount)
  33. { semaphore_init(&m_sem, initialCount); }
  34. ~posix_semaphore()
  35. { semaphore_destroy(&m_sem); }
  36. void post()
  37. { semaphore_post(&m_sem); }
  38. void wait()
  39. { semaphore_wait(&m_sem); }
  40. bool try_wait()
  41. { return semaphore_try_wait(&m_sem); }
  42. bool timed_wait(const boost::posix_time::ptime &abs_time)
  43. { return semaphore_timed_wait(&m_sem, abs_time); }
  44. private:
  45. sem_t m_sem;
  46. };
  47. } //namespace ipcdetail {
  48. } //namespace interprocess {
  49. } //namespace boost {
  50. #include <boost/interprocess/detail/config_end.hpp>
  51. #endif //#ifndef BOOST_INTERPROCESS_POSIX_SEMAPHORE_HPP