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 11 #ifndef BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP 12 #define BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP 13 14 #ifndef BOOST_CONFIG_HPP 15 # include <boost/config.hpp> 16 #endif 17 # 18 #if defined(BOOST_HAS_PRAGMA_ONCE) 19 # pragma once 20 #endif 21 22 #include <boost/interprocess/detail/config_begin.hpp> 23 #include <boost/interprocess/detail/workaround.hpp> 24 #include <boost/interprocess/detail/posix_time_types_wrk.hpp> 25 26 #include <boost/interprocess/sync/interprocess_mutex.hpp> 27 #include <boost/interprocess/sync/scoped_lock.hpp> 28 #include <boost/interprocess/exceptions.hpp> 29 #include <boost/interprocess/sync/windows/semaphore.hpp> 30 #include <boost/interprocess/sync/windows/mutex.hpp> 31 #include <boost/interprocess/sync/detail/condition_algorithm_8a.hpp> 32 33 34 namespace boost { 35 namespace interprocess { 36 namespace ipcdetail { 37 38 class windows_condition 39 { 40 windows_condition(const windows_condition &); 41 windows_condition &operator=(const windows_condition &); 42 43 public: windows_condition()44 windows_condition() 45 : m_condition_data() 46 {} 47 ~windows_condition()48 ~windows_condition() 49 { 50 //Notify all waiting threads 51 //to allow POSIX semantics on condition destruction 52 this->notify_all(); 53 } 54 notify_one()55 void notify_one() 56 { m_condition_data.notify_one(); } 57 notify_all()58 void notify_all() 59 { m_condition_data.notify_all(); } 60 61 template <typename L> timed_wait(L & lock,const boost::posix_time::ptime & abs_time)62 bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time) 63 { return m_condition_data.timed_wait(lock, abs_time); } 64 65 template <typename L, typename Pr> timed_wait(L & lock,const boost::posix_time::ptime & abs_time,Pr pred)66 bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred) 67 { return m_condition_data.timed_wait(lock, abs_time, pred); } 68 69 template <typename L> wait(L & lock)70 void wait(L& lock) 71 { m_condition_data.wait(lock); } 72 73 template <typename L, typename Pr> wait(L & lock,Pr pred)74 void wait(L& lock, Pr pred) 75 { m_condition_data.wait(lock, pred); } 76 77 private: 78 79 struct condition_data 80 { 81 typedef boost::int32_t integer_type; 82 typedef windows_semaphore semaphore_type; 83 typedef windows_mutex mutex_type; 84 condition_databoost::interprocess::ipcdetail::windows_condition::condition_data85 condition_data() 86 : m_nwaiters_blocked(0) 87 , m_nwaiters_gone(0) 88 , m_nwaiters_to_unblock(0) 89 , m_sem_block_queue(0) 90 , m_sem_block_lock(1) 91 , m_mtx_unblock_lock() 92 {} 93 get_nwaiters_blockedboost::interprocess::ipcdetail::windows_condition::condition_data94 integer_type &get_nwaiters_blocked() 95 { return m_nwaiters_blocked; } 96 get_nwaiters_goneboost::interprocess::ipcdetail::windows_condition::condition_data97 integer_type &get_nwaiters_gone() 98 { return m_nwaiters_gone; } 99 get_nwaiters_to_unblockboost::interprocess::ipcdetail::windows_condition::condition_data100 integer_type &get_nwaiters_to_unblock() 101 { return m_nwaiters_to_unblock; } 102 get_sem_block_queueboost::interprocess::ipcdetail::windows_condition::condition_data103 semaphore_type &get_sem_block_queue() 104 { return m_sem_block_queue; } 105 get_sem_block_lockboost::interprocess::ipcdetail::windows_condition::condition_data106 semaphore_type &get_sem_block_lock() 107 { return m_sem_block_lock; } 108 get_mtx_unblock_lockboost::interprocess::ipcdetail::windows_condition::condition_data109 mutex_type &get_mtx_unblock_lock() 110 { return m_mtx_unblock_lock; } 111 112 boost::int32_t m_nwaiters_blocked; 113 boost::int32_t m_nwaiters_gone; 114 boost::int32_t m_nwaiters_to_unblock; 115 windows_semaphore m_sem_block_queue; 116 windows_semaphore m_sem_block_lock; 117 windows_mutex m_mtx_unblock_lock; 118 }; 119 120 ipcdetail::condition_8a_wrapper<condition_data> m_condition_data; 121 }; 122 123 } //namespace ipcdetail 124 } //namespace interprocess 125 } //namespace boost 126 127 #include <boost/interprocess/detail/config_end.hpp> 128 129 #endif //BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP 130