condition.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_DETAIL_WINDOWS_CONDITION_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP
  12. #include <boost/interprocess/detail/config_begin.hpp>
  13. #include <boost/interprocess/detail/workaround.hpp>
  14. #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
  15. #include <boost/interprocess/sync/interprocess_mutex.hpp>
  16. #include <boost/interprocess/sync/scoped_lock.hpp>
  17. #include <boost/interprocess/exceptions.hpp>
  18. #include <boost/interprocess/sync/windows/semaphore.hpp>
  19. #include <boost/interprocess/sync/windows/mutex.hpp>
  20. #include <boost/interprocess/sync/detail/condition_algorithm_8a.hpp>
  21. namespace boost {
  22. namespace interprocess {
  23. namespace ipcdetail {
  24. class windows_condition
  25. {
  26. windows_condition(const windows_condition &);
  27. windows_condition &operator=(const windows_condition &);
  28. public:
  29. windows_condition()
  30. : m_condition_data()
  31. {}
  32. ~windows_condition()
  33. {}
  34. void notify_one()
  35. { m_condition_data.notify_one(); }
  36. void notify_all()
  37. { m_condition_data.notify_all(); }
  38. template <typename L>
  39. bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time)
  40. { return m_condition_data.timed_wait(lock, abs_time); }
  41. template <typename L, typename Pr>
  42. bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred)
  43. { return m_condition_data.timed_wait(lock, abs_time, pred); }
  44. template <typename L>
  45. void wait(L& lock)
  46. { m_condition_data.wait(lock); }
  47. template <typename L, typename Pr>
  48. void wait(L& lock, Pr pred)
  49. { m_condition_data.wait(lock, pred); }
  50. private:
  51. struct condition_data
  52. {
  53. typedef boost::int32_t integer_type;
  54. typedef windows_semaphore semaphore_type;
  55. typedef windows_mutex mutex_type;
  56. condition_data()
  57. : m_nwaiters_blocked(0)
  58. , m_nwaiters_gone(0)
  59. , m_nwaiters_to_unblock(0)
  60. , m_sem_block_queue(0)
  61. , m_sem_block_lock(1)
  62. , m_mtx_unblock_lock()
  63. {}
  64. integer_type &get_nwaiters_blocked()
  65. { return m_nwaiters_blocked; }
  66. integer_type &get_nwaiters_gone()
  67. { return m_nwaiters_gone; }
  68. integer_type &get_nwaiters_to_unblock()
  69. { return m_nwaiters_to_unblock; }
  70. semaphore_type &get_sem_block_queue()
  71. { return m_sem_block_queue; }
  72. semaphore_type &get_sem_block_lock()
  73. { return m_sem_block_lock; }
  74. mutex_type &get_mtx_unblock_lock()
  75. { return m_mtx_unblock_lock; }
  76. boost::int32_t m_nwaiters_blocked;
  77. boost::int32_t m_nwaiters_gone;
  78. boost::int32_t m_nwaiters_to_unblock;
  79. windows_semaphore m_sem_block_queue;
  80. windows_semaphore m_sem_block_lock;
  81. windows_mutex m_mtx_unblock_lock;
  82. };
  83. ipcdetail::condition_8a_wrapper<condition_data> m_condition_data;
  84. };
  85. } //namespace ipcdetail
  86. } //namespace interprocess
  87. } //namespace boost
  88. #include <boost/interprocess/detail/config_end.hpp>
  89. #endif //BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP